akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll x,k,d;
  cin >> x >> k >> d;
  x = abs(x);
  ll ans;

if(x/d > k){
// x までたどり着かない
  ans = x- d*k;
}else{
  ll time = x/d;
  k -= time;
  x -= time*d;
  if(k%2 == 1) x = abs(x-d);
  ans = x;
  
}

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


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll cntl[200000],cntr[200000];

int main() {
  ll n,x,ans=0;
  cin >> n;
  for(ll i=1;i<=n;i++){
    cin >> x;
    if(i+x<n) cntl[i+x]++;
    if(i-x>1) cntr[i-x]++;
  }
  for(int i=2;i<n;i++) ans += cntl[i]*cntr[i];
  cout << ans << endl;
}


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

int main() {
  	vector<int> s(3);
    for(int i=0;i<3;i++){
      cin >> s.at(i);
    }
    sort(s.begin(),s.end());
    cout << (s.at(1)-s.at(0))+(s.at(2)-s.at(1)) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int64_t sum = 0;
  map<int64_t,int64_t> mp;
  vector<int64_t> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
    mp[vec[i]]++;
    sum += vec[i];
  }
  
  int Q;
  cin >> Q;
  for(int i=0; i<Q; i++){
    int64_t b, c;
    cin >> b >> c;
    if(mp.count(b)){
      sum -= b*mp[b];
      sum += c*mp[b];
      mp[c] += mp[b];
      mp[b] = 0;
    }
    cout << sum << endl;
  }
}
  

Measured memory_bytes: 8972
def solve(a): #長さaにするのに何回いるか
  ret = 0
  for x in A:
    if x%a == 0:
      temp = x//a-1
    else:
      temp = x//a
    ret += temp
  return ret

N,K = map(int,input().split())
A = list(map(int,input().split()))
total = N+K
Sum = sum(A)
MAX = pow(10,9)+10
ng = 0
ok = MAX
while abs(ok-ng) > 1:
  mid = (ok+ng)//2
  if solve(mid) <= K:
    ok = mid
  else:
    ng = mid
print(ok)
#print(solve(3))

Measured memory_bytes: 30984
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
void solve(int a){cout<<( a?"YES":"NO")<<endl;}
int main(){
	int n;
	cin >>n;
	int bef;
	map<int,int>a;
	for(int i=0;i<n;i++){
		cin >>bef;
		a[bef]+=0;
		a[bef]++;
	}
	int ans=0;
	for(auto i=a.begin();i!=a.end();i++){
		if(i->second >=i->first){
			ans+=(i->second)-i->first;
		}else{
			ans+=i->second;
		}
	}

	cout <<ans<<endl;
	
}

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

#define f first
#define s second

#define pb push_back
#define mp make_pair

#define ll long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())

using namespace std;

const int MAXN = (int) 3e5 + 10;
const int mod = (int)998244353;

int n;
pii a[MAXN];
int p[MAXN];

int sum(int x, int y) {
    x += y;
    if ( x < 0) x += mod;
    if (x >= mod) x -= mod;
    return x;
}
void add(int &x, int y) {
    x =sum(x,y);
}

int t[MAXN];

int get(int i) {
    i=a[i].s;
    int cnt=0;
    while(i>=0){
        cnt+=t[i];
        i=(i&(i+1))-1;
    }
    return cnt;
}

void upd(int i){
    i=a[i].s;
    while(i<n){
        t[i]++;
        i|=i+1;
    }
}

int main() {
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        cin >> a[i].f >> a[i].s;
        v.pb(a[i].s);
    }
    sort(all(v));
    for (int i = 0; i < n; i++) {
        a[i].s=lower_bound(all(v), a[i].s)-v.begin();
    }
    p[0]=1;
    for (int i = 1; i <= n; i++) p[i]=sum(p[i-1],p[i-1]);
    sort(a, a + n);
    int ans = 0;
    for (int i = 0; i < n; i++){
        add(ans, sum(p[n],-1));
    }
    for (int i = 0; i < n; i++){
        add(ans, -sum(p[i],-1));
        add(ans, -sum(p[n-i-1],-1));
    }
    for (int i = 0; i < n; i++){
        add(ans, -sum(p[i],-1));
        add(ans, -sum(p[n-i-1],-1));
    }
    for (int i = 0; i < n; i++){
        add(ans, sum(p[get(i)],-1));
        add(ans, sum(p[i-get(i)],-1));
        upd(i);
    }
    memset(t,0,sizeof(t));
    reverse(a,a+n);
    for (int i = 0; i < n; i++){
        add(ans, sum(p[get(i)],-1));
        add(ans, sum(p[i-get(i)],-1));
        upd(i);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5108
S, T = readlines.map(&:chomp)

def fail
  puts 'No'
  exit
end

h1, h2 = {}, {}
S.chars.zip(T.chars).each do |s, t|
  fail if h1.key?(s) && h1[s] != t
  fail if h2.key?(t) && h2[t] != s
  h1[s] = t unless h1.key?(s)
  h2[t] = s unless h2.key?(t)
end
puts 'Yes'

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

int main(){
    int N;
    cin >> N;
    int A,B;


    if (N==1){
        cout << "Hello World" << endl;
    }

    else{
        cin >> A;
        cin >> B;
        cout << A+B << endl;
    }
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	string s,t;
	cin >> s >>t;
	int ans = s.size() + t.size();
	int i = n;
	int j = 0;
	int leng = 1;
	int counts = 0;
	int kouho = 0;
	int kotae = s.size() + t.size();
	while(n--){
		if(s.substr(i-1,leng) == t.substr(j,leng)){
			kouho = ans - leng;
			kotae = min(kotae,kouho);
		}
		i--;
		leng++;
	}
	cout << kotae << endl;
}

// cout << fixed << setprecision(15) <<  << endl;


Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};

int main() {
	ll N, M, K;
	cin >> N >> M >> K;
	vector<ll>a(N), b(M);
	int A=0, B=0;
	ll time=0;
	ll ans=0;
	rep(i, N)cin >> a[i];
	rep(i, M)cin >> b[i];
	rep(i, N)if (i > 0)a[i] += a[i - 1]; 
	
	rep(i, M)if(i>0) b[i]+=b[i-1];
	rep(i, N) {
		if (a[i] > K) {
			ans = i;
			if(i!=0)time = a[i - 1];
			break;
		}
		if (i == N-1) {
			ans = N;
			if (i != 0)time = a[i - 1];
		}
	}
	
	ll tmp=ans;//Aのほんの数
	ll tmptime;//残り時間
	for (ll i = tmp-1; i >=0; i--) {
		tmptime = K - a[i];//i+1冊Aを読む
		auto iter_upper = upper_bound(b.begin(), b.end(), tmptime);//tmptime以下のBの本の数
		ll idx_upper = distance(b.begin(), iter_upper);//先頭からの距離
		ans = max(ans, i+1+idx_upper);
	}
	auto iter_upper = upper_bound(b.begin(), b.end(), K);//K以下のBの本の数
	ll idx_upper = distance(b.begin(), iter_upper);//先頭からの距離
	ans = max(ans,idx_upper);
	cout << ans;
	//cout << fixed << setprecision(10) << ans;
}


Measured memory_bytes: 6416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 200;
int a[N], n;
ll ans = 0, l = 0, r = 0;
int cnt[50];

int main(int argc, char** argv) {
	//freopen("in.txt", "r", stdin);
	
	memset(cnt, 0, sizeof(cnt));
	
	cin>>n;
	for(int i=0;i<n;i++) {
		scanf("%d", &a[i]);
	}
	
	int p, flag = 1, t;
	while(r < n) {
		t = a[r], p = 0;
		while(t) {
			if(t & 1)cnt[p] ++;
			if(cnt[p] > 1)flag = 0;
			p ++;
			t = t >> 1;
		}
		
		if(!flag){
			while(!flag) {
				t = a[l], p = 0;
				while(t) {
					if(t & 1)cnt[p] --;
					p ++;
					t = t >> 1;
				}
				
				int tf = 1;
				for(int i=0;i<=25;i++) {
					if(cnt[i] > 1)tf = 0;
				}
				
				l ++;
				if(tf) {
					flag = 1;
					break;
				}
			}
		}
		ans += (r - l + 1);
		//cout<<ans<<" "<<l<<" "<<r<<endl;
		r ++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    int n; cin >> n;
    vll(a, n);
    sort(ALL(a));

    vll c(n);
    c = a;
    rep(i, n-1) c[i+1] += c[i];
    // prvec(a);
    // prvec(c);

    int ans = 0;
    rep(i, n-1){
        if(2*c[i]>=a[i+1]){
            ans++;
        }else{
            ans=0;
        }
    }
    pr(ans+1);
    return 0;}

Measured memory_bytes: 4844
#青:N, s_i earn
#赤:M, t_i lose
N = int(input())
bl = [input() for i in range(N)]
M = int(input())
rl = [input() for i in range(M)]

yenResult = 0
for i in set(bl):
    yen = 0
    yen += bl.count(i)
    yen -= rl.count(i)
    if yen > yenResult:
        yenResult = yen
print(yenResult)


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

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

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut seqs = vec![(0, 0); n];
    for i in 0..n {
        seqs[i].0 = read::<i64>();
        seqs[i].1 = read::<usize>();
    }
    seqs.sort();
    let mut ans = 0;
    let mut cnt = 0;
    for i in 0..n {
        let c = std::cmp::min(m - cnt, seqs[i].1);
        cnt += c;
        ans += c as i64 * seqs[i].0;
        if cnt == m {
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n;
    if(n == 1)cout << "Hello World";
    else{
        intl a,b;
        cin >> a >> b;
        cout << a + b;
    }
    return 0;
}

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

void fnInput(int& rnTrgSu, int& rnTrgKin)
{
  cin >> rnTrgSu >> rnTrgKin;
}

int fnRcsSch(int nPos, int nTrgSu, int nTrgKin, vector<int>& rvnNumMoney)
{
  vector<int> cnvnMoney{10000, 5000, 1000};

  if (nTrgKin < 0)  return -1;
  if (nPos == rvnNumMoney.size() - 1)
  {
    rvnNumMoney[nPos] = nTrgSu;
    if (nTrgKin - cnvnMoney[nPos] * nTrgSu == 0)
      return 1;
    else
      return 0;
  }

  for (int i = 0; i <= nTrgSu; i++)
  {
    rvnNumMoney[nPos] = i;
    int nRtn = fnRcsSch(nPos + 1, nTrgSu - i, nTrgKin - cnvnMoney[nPos] * i, rvnNumMoney);
    if      (nRtn == -1)  return 0;
    else if (nRtn)        return 1;
  }

  return 0;
}

int fnExhSch(int nTrgSu, int nTrgKin)
{
  vector<int> vnNumMoney(3);

  if (fnRcsSch(0, nTrgSu, nTrgKin, vnNumMoney))
  {
    for (int i = 0; i < vnNumMoney.size(); i++)
    {
      if ( i )  cout << " ";
      cout << vnNumMoney[i];
    }
    cout << endl;
  }
  else
    cout << -1 << " " << -1 << " " << -1 << endl;
}

int main()
{
  int nTrgSu, nTrgKin;
  
  fnInput(nTrgSu, nTrgKin);
  fnExhSch(nTrgSu, nTrgKin);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// posted by a friend of mine

int main(){
	int a;
	int n;
	cin>>a;
	n=0;
	for(int x=1;x<=a;x+=2){
		for(int y=2;y<=a;y+=2){
			n=n+1;
		}
	}
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = ""
i = 1
j = 1
while n >= j
  x = n-j
  a += ((x/(26**(i-1))) % 26 +97).chr
  j += 26**i
  i += 1
end
if n == 1
  puts "a"
else
  puts a.reverse
end

Measured memory_bytes: 14340
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
          if(n/i==i)
            c++;
          else
            c+=2;
        }

    }

    
    return  c;
}
int func(int n)
{
    return (n*(n+1))/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   
    string s,s1;
    cin>>s>>s1;
    s=s+s1;
    int n=0;
    for(int i=0;i<s.size();i++)
    {
        n=n*10 + s[i] -48;
    }
    int p=sqrt(n);
    if(p*p==n)
    {
        cout<<"Yes";
    }
    else
        cout<<"No";


 return 0;
}








Measured memory_bytes: 3640
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    n = str(input())

    #output
    l = len(n)

    mod = 0
    for i in range(l):
        mod += int(n[i])
        mod %= 9 

    #  %%
    if mod == 0:
        print("Yes")
    else:
        print("No")

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Measured memory_bytes: 9292
#include <stdio.h>
#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
typedef long long ll;

using namespace std;

const int N = 3e5 + 111, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1.0), eps = 1e-9;

int n, a[N], l[N], r[N];
ll ans;
stack <int> st;

ll sum(ll L, ll R){
	if(L > R)
		return 0;
	ll len = R - L + 1;
	return (len * (len + 1)) / 2;
}

int main(){
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	cout << setprecision(10) << fixed;

	cin >> n;
	
	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	for(int i = 1; i <= n; ++i){
		while((int)st.size() > 0 && a[st.top()] > a[i])
			st.pop();
		if((int)st.size() == 0)
			l[i] = 1;
		else l[i] = st.top() + 1;
		st.push(i);
	}

	while((int)st.size() > 0)
		st.pop();

	for(int i = n; i >= 1; --i){
		while((int)st.size() > 0 && a[st.top()] > a[i])
			st.pop();
		if((int)st.size() == 0)
			r[i] = n;
		else r[i] = st.top() - 1;	
		st.push(i);
	}

	for(int i = 1; i <= n; ++i){	
		ans += 1LL * a[i] * (sum(l[i], r[i]) - sum(l[i], i - 1) - sum(i + 1, r[i]));
	}

	cout << ans;
	
	return 0;
	//cout << (clock() + 0.0) / CLOCKS_PER_SEC;
}

Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int d = 0;
		int ans = 1;
		for(ans = 1; ans < n + 1; ans++) {
			d += sc.nextInt();
			if(d > x) {
				break;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 22356
#include<iostream>

using namespace std;

int main(){
    int a, b;
    cin >>a >> b;
    if(a<b){
        for(int i=0;i<b;i++)cout << a;
    }
    else{
        for(int i=0;i<a;i++)cout << b;
    }
    cout << endl;
}

Measured memory_bytes: 256
import itertools

n,m,q=map(int,input().split()) #0-indexed

LR=[[0]*(n+1) for i in range(n+1)]

for i in range(m):
  l,r=map(int,input().split())
  LR[l][r]+=1

for i in range(n):
  LR[i]=list(itertools.accumulate(LR[i]))


for i in range(q):
  l,r=map(int,input().split())
  ans=0
  for j in range(l,r+1):
    ans+=LR[j][r]-LR[j][l-1]

  print(ans)

Measured memory_bytes: 79076
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
using lint = long long;

bool match_str(std::string a, std::string b)
{
    bool out = true;
    for (int i = 0; i < a.size(); ++i)
    {
        if (a[i] == '?')
            continue;
        if (a[i] != b[i])
        {
            out = false;
            break;
        }
    }
    return out;
}

std::string restore(std::string s)
{
    std::string out = "";
    for (int i = 0; i < s.size(); ++i)
    {
        if (s[i] == '?')
            out += 'a';
        else
            out += s[i];
    }
    return out;
}

int main()
{
    std::string s;
    std::cin >> s;
    std::string t;
    std::cin >> t;

    bool match = false;

    std::vector<std::string> cand;

    for (int i = s.size() - t.size(); i >= 0; i--)
    {
        if (match_str(s.substr(i, t.size()), t))
        {
            match = true;
            std::string tmp = s;
            tmp.replace(i, t.size(), t);
            cand.push_back(tmp);
        }
    }

    if (!match)
    {
        printf("UNRESTORABLE");
        return 0;
    }
    else
    {
        std::vector<std::string> ans;
        for (auto cur_s : cand)
        {
            ans.push_back(restore(cur_s));
        }
        std::sort(ans.begin(), ans.end());
        std::cout << ans[0] << "\n";
    }

    return 0;
}


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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<pair<char, char>> p;
  rep(i, q) {
    char t, d;
    cin >> t >> d;
    p.emplace_back(t, d);
  }
  reverse(all(p));
  int lc = 0, rc = 0;
  rep(i, q) {
    if (lc < n && p[i].first == s[lc] && p[i].second == 'L') {
      lc++;
    } else if (lc > 0 && p[i].first == s[lc - 1] && p[i].second == 'R') {
      lc--;
    }
  }
  rep(i, q) {
    if (rc < n && p[i].first == s[n - rc - 1] && p[i].second == 'R') {
      rc++;
    } else if (rc > 0 && p[i].first == s[n - rc] && p[i].second == 'L') {
      rc--;
    }
  }
  cout << min(n, n - lc - rc) << endl;
  return 0;
}


Measured memory_bytes: 1100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

template<class T> inline bool cmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool cmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll MAXN=2e5+5;
const ll MAXLG=__lg(MAXN)+2;
#define SQ(i) (i)*(i)
ll n,c,h[MAXN],dp[MAXN];
deque<pii> dq;

ll trans(pii t,ll hei) {
    return t.Y + c + SQ(hei) - 2 * hei * t.X;
}
bool solve(pii t1,pii t2,pii nw) {
    pii i1 = {t1.Y - t2.Y,t2.X - t1.X};
    pii i2 = {t2.Y - nw.Y,nw.X - t2.X};
    //return i1 > i2
    return i1.X*i2.Y > i1.Y*i2.X;
}
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> n >> c;
    REP (i,n) {
        cin >> h[i];
    }

    dp[0] = 0;
    dq.emplace_back(h[0],dp[0]+SQ(h[0]));
    REP1 (i,n-1) {
        while (dq.size()>1&&trans(dq[0],h[i])>=trans(dq[1],h[i]))dq.pop_front();
        dp[i] = trans(dq.front(),h[i]);
        pii cur = {h[i],dp[i]+SQ(h[i])};
        while (dq.size()>1&&solve(dq.back(),dq[SZ(dq)-2],cur))dq.pop_back();
        dq.emplace_back(cur);
    }

    cout << dp[n-1] << endl;
    return 0;
}
//DP

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

using ll=long long;

using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;

int main() {
  int MAX=pow(10,5)+1;
  vi is_prime(MAX,1);
  is_prime[0]=0,is_prime[1]=0;
  rep(i,2,MAX) {
    if (is_prime[i]==0) {
      continue;
    }
    for (int j=i*2;j<MAX;j+=i) {
      is_prime[j]=0;
    }
  }
  vi a(MAX,0);
  rep(i,0,MAX) {
    if (i%2==0) {
      continue;
    } else if (is_prime[i] && is_prime[(i+1)/2]) {
      a[i]=1;
    }
  }
  vi s(MAX+1,0);
  rep(i,0,MAX) {
    s[i+1]=s[i]+a[i];
  }
  int Q; cin >>Q;
  rep(q,0,Q) {
    int l,r; cin >>l >>r;
    r++;
    cout <<s[r]-s[l] <<endl;
  }
  return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int X; cin >> X;
    if(X == 7 || X == 5 || X == 3) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

int main(){
    long long a;
    string b,c;
    cin>>a>>b;
    for(int i=0;i<4;i++){
        if(i==1) continue;
        c+=b[i];
    }
    cout<<a*stoll(c)/100<<endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double time=h*60+m;
	double ang=time*(5.5);
	double ans=a*a+b*b-2*a*b*cos(ang/180*3.1415926535897932);
	printf("%.9f",sqrt(ans));
	return 0; 
}

Measured memory_bytes: 4228
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) {
    cin >> v[i];
  } 
  sort(v.begin(), v.end());
  double ans = v[0];
  for(int i = 1; i < n; i++) ans = (ans+v[i])/2;
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())

ans = 10 ** 9
for c in range(max(X, Y) + 1):
    tmp = 2 * C * c
    tmp += A * max(0, X - c)
    tmp += B * max(0, Y - c)
    ans = min(ans, tmp)

print (ans)

Measured memory_bytes: 3060
# FizzBuzzの整数部分の総和を求めよ

# FizzBuzz試し
# N = input()
# for i in range(1,int(N)+1):
#     if (i % 3 == 0) and (i % 5 == 0):
#         answer = 'FizzBuzz'
#     elif i % 3 == 0:
#         answer = 'Fizz'
#     elif i % 5 == 0:
#         answer = 'Buzz'
#     else:
#         answer = int(i)
#     print(answer)

N = input()
I = []
for i in range(1,int(N)+1):
    if (i % 3 != 0) and (i % 5 != 0):
        I.append(i)
# print(I)
Sum = sum(I)
print(Sum)

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

int main(){
  long x,ans,a,b;
  cin >> a;
  cin >> b;
  
  x= a*b;
  if(a<b){
    int tmp=a;
    a=b;
    b=tmp;
  }
  int r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  ans = x/b;
  cout << ans << endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<int>slimes(N);
	int cnt = 0, pre;
	for (int i = 0; i < N; i++) 
		cin >> slimes[i];
	pre = slimes[0];
	for (int i = 1; i < N; i++) {
		if (slimes[i] == pre) {
			cnt++;
			i++;
		}
		if (i < N) 
			pre = slimes[i];
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
//Created by Aigerim.
//© 2019 Aigerim.
                                                                               
/***************************************************************                                       ****       ****
**                                                                                                  *       *   *      *
**  *********   **          *********    **           **  ********     **        **                 *        * *       *
**      **      **          **     **     **         **   **           **        **                 *         *        *
**      **      **          **     **      **       **    **           **        **                  *                *    
**      **      **          **     **       **     **     ********     **        **                   *              *
**      **      **          **     **        **   **      **           **        **                    *            *        
**      **      *********   **     **         ** **       **            *        *                       *         *
**  *********   *********   *********          ***        ********       ********                          *      *
**                                                                                                           *  *
**                                                                                                             *
***************************************************************/  
#include <bits/stdc++.h>
 
using namespace std;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(a*n,b);
  return 0;
}

Measured memory_bytes: 256
n, m, k = gets.split.map(&:to_i)
a = [0] + gets.split.map(&:to_i)
b = [0] + gets.split.map(&:to_i)

n.times {|i| a[i+1] += a[i]}
m.times {|j| b[j+1] += b[j]}

ans = 0
j = m
(n+1).times do |i|
    break if a[i] > k
    j -= 1 while a[i] + b[j] > k && j > 0
    ans = [ans, i + j].max
end

p ans

Measured memory_bytes: 44192
// Shiritori

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>

using namespace std;

int n;
vector<string> words;

int main() {
    cin >> n;

    bool res = true;
    // if (n > 10) {
    //     n = 10;
    // }
    string w;
    for (int i = 0; i < n; i++) {
        cin >> w;

        if (find(words.begin(), words.end(), w) != words.end()) {
            res = false;
            //break;
        };

        if (i > 0) {
            char c_tail = words[i-1][words[i-1].size() - 1];
            char c_head = w[0];
            if (c_tail != c_head) {
                res = false;
                //break;
            }
        }
        words.push_back(w);
    }

    if (res) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
//
// Created by yamunaku on 2020/01/26.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    ll h;
    cin >> h;
    ll ans = 0, num = 1;
    while(h > 0){
        ans += num;
        num *= 2;
        h /= 2;
    }
    cout << ans << endl;
    return 0;
}

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

char getGrade(int m, int f, int r){
    int sum = m + f;
    char grade;
    if (m == -1 || f == -1 ) {
    grade = 'F';
    }else if (80 <= sum){
        grade = 'A';
    }else if (65 <= sum && sum < 80){
        grade ='B';
    }else if (50 <= sum && sum < 65){
        grade = 'C';
    }else if (30 <= sum && sum < 50){
        if (50 <= r) grade = 'C';
        else grade = 'D';
    }
    else if ( sum < 30) grade = 'F';
    
    return grade;
}

int main(){
    int m, f, r;
    while(1){
        cin >> m >> f >> r;
        if ( m == -1 && f == -1 && r == -1) break;
        cout << getGrade(m, f, r) << endl;
    }
    
    return 0;
    
}

Measured memory_bytes: 3084
#include<stdio.h>
int main(){
    int n,count=0,tri=0,sum=0;
    scanf("%d",&n);
    long a[n];
    for(int i=0; i<n; i++){
        tri=0;
        count=0;
        scanf("%d",&a[i]);
        while(tri==0){
            if(a[i]%2 == 0){
                count += 1;
                a[i] /= 2;
            }
            else tri+=1;
        }
        sum+=count;
    }
    printf("%d\n",sum);
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, x;
  cin >> N >> x;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll res = 0;
  for (int i = 0; i < N - 1; i++) {
    if (A[i] + A[i + 1] > x) {
      int d = min(A[i + 1], max(0, A[i] + A[i + 1] - x));
      A[i + 1] -= d;
      res += 1LL * d;
    }
    if (A[i] + A[i + 1] > x) {
      int d = min(A[i], max(0, A[i] + A[i + 1] - x));
      A[i] -= d;
      res += 1LL * d;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0102
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                int n = RInt();
                if (n == 0) break;

                int[] colSum = new int[n + 1];
                for (int i = 0 ; i < n ; i++)
                {
                    int[] items = RIntAr();
                    for (int j = 0 ; j <= n ; j++)
                    {
                        if (j < n)
                        {
                            Console.Write(items[j].ToString().PadLeft(5));
                            colSum[j] += items[j];
                        }
                        else
                        {
                            Console.Write(items.Sum().ToString().PadLeft(5));
                            Console.Write(Environment.NewLine);
                            colSum[j] += items.Sum();
                        }
                    }               
                }
                for (int i = 0 ; i <= n ; i++) Console.Write(colSum[i].ToString().PadLeft(5));
                Console.Write(Environment.NewLine);
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 16204
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int a,b,t;
    cin >> a >> b >> t;
    int ans = 0;
    for(int i = 1; i <= t; i++){
        if(i%a == 0) ans+=b;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
using namespace std;
// Problem https://atcoder.jp/contests/abc053/tasks/abc053_b
// Reference https://atcoder.jp/img/arc068/editorial.pdf

int solver(string iStr){
    int aPos,zPos,result;
    int iStrLeng=iStr.size();
    aPos = 0;
    zPos = iStrLeng;
    // Aは一番左にある物の位置
    for(int j=0;j<iStrLeng;j++){
        if(iStr.at(j)=='A'){
            aPos = j;
            break;
        }
    }
    for(int j=iStrLeng-1;-1 < j;j--){
        if(iStr.at(j) =='Z'){
            zPos = j;
            break;
        }
    }
    // cout << "A:" << aPos << ",Z:" << zPos << endl;
    result = zPos - aPos +1; // 文字自身も含む為
    return result;
}

int main(void){
    int answer;
    string s;
    cin >> s;
    answer = solver(s);
    cout << answer << endl;
}

Measured memory_bytes: 772
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100010;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,C;
    cin >> n >> C;
    int s[d5], t[d5], c[d5];
    int ss[2 * d5], tt[2 * d5];
    for (int i = 0; i < n; i++)
    {
        cin >> s[i] >> t[i] >> c[i];
    }
    for (int i = 1; i <= C;i++){
        fill(tt, tt + 2*d5, 0);
        for (int j = 0; j < n;j++){
            if(c[j]==i){
                tt[s[j] * 2 - 1]++;
                tt[t[j] * 2]--;
            }
        }
        for (int j = 1; j < 2 * d5;j++){
            tt[j] += tt[j - 1];
        }
        for (int j = 0; j < 2 * d5;j++){
            if(tt[j]>0){
                ss[j]++;
            }
        }
    }
    int res = -1;
    for (int j = 0; j < 2 * d5-10;j++)
        res = max(res, ss[j]);
    cout << res << endl;
}

Measured memory_bytes: 5760
N=int(input())
dp = [1000001] * (N+1)
dp[0] = 0
for i in range(1,N+1):
    dp[i]=dp[i-1]+1
    k=6
    while i-k >=0:
        dp[i] = min(dp[i],dp[i-k]+1)
        k*=6
    k=9
    while i-k >=0:
        dp[i] = min(dp[i],dp[i-k]+1)
        k*=9
print(dp[N])

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  ll n, x;
  cin >> n >> x;
  vec<ll> a(n);
  scan(a);

  ll ans = 0;
  rep(i, 1, n) {
    ll sum = a[i - 1] + a[i];
    if (x >= sum) continue;
    ll diff = min(sum - x, a[i]);
    ans += diff;
    a[i] -= diff;
  }

  ll sum = a[0] + a[1];
  if (x < sum) {
    ll diff = sum - x;
    ans += diff;
    a[0] -= diff;
  }

  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


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

typedef long long int int64;
int main()
{
    int64 n,d;
    int i;
    int64 x,y;
    int ans=0;
    scanf("%lld %lld",&n,&d);
    for(i=0;i<n;i++)
    {
        scanf("%lld %lld",&x,&y);
        if((x*x+y*y)<=d*d)ans++;
    }
	printf("%d",ans);
}


Measured memory_bytes: 1732
#include<iostream>
#include<bits/stdc++.h>
#include<climits>
#include<math.h>

#define forn(x,n,s) for(int i = x; i < n; i += s )
#define forr(x,n,s) for(int i = x; i>=n; i -= s)
#define PI 3.14159265358979323846264338327950L

using namespace std;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
} 
long long int mod = 1e9+7;

int main(){
    go(); 

    // code here
    int a,b,c,k;cin>>a>>b>>c>>k;
    int sum = 0;
    sum = min(a,k);
    k = max(0,k - a); 
    if(k!=0) k = max(0,k - b);
    if(k!=0) sum -= min(c,k);
    cout<<sum;
}





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

int main(){
    int64_t i,j,k,l;//preparation for
    int n;

    cin>>n;

    int a[n],d[n],e;

    a[0]=0;

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

    for(i=1;i<n;i++){
        cin>>a[i];
        e=a[i]-1;//i's boss name
        d[e]+=1;
    }

    for(i=0;i<n;i++){
        cout<<d[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 5208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = RSt();
            if (s.Length == 1)
            {
                Console.WriteLine(0);
            }
            else
            {
                int d1 = 0;
                int d2 = 0;
                for (int i = 0; i < s.Length; i++)
                {
                    if (int.Parse(s[i].ToString()) != i % 2) d1++;
                    else d2++;
                }
                Console.WriteLine(Math.Min(d1,d2));
            }

        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}


Measured memory_bytes: 13280
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

using namespace std;

template<typename T, typename V>
T bseach(T begin, T end, const V &v){
    int low = 0, high = end - begin - 1;
    while (low <= high) {
        int mid = (low + high) / 2;
        if(begin[mid] == v){
            return begin + mid;
        }
        if(v < begin[mid]){
            high = mid - 1;
        }else{
            low = mid + 1;
        }
    }
    return end;
}

const int maxn = 100000;
int arS[maxn];

int main(int argc, char const* argv[])
{
    int n,q,cnt = 0;
    scanf("%d ", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d ", &arS[i]);
    }

    scanf("%d ", &q);
    for (int i = 0; i < q; i++) {
        int t;
        scanf("%d ", &t);
        int *end = arS + n;
        if(bseach(arS, end, t) != end) cnt++;
    }

    printf("%d\n", cnt);
    
    return 0;
}

Measured memory_bytes: 3076
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d,num=0,i;
    cin>>a>>b>>c>>d;
    int p[105]={0};
    for(i=a;i<b;i++)
    {
        p[i]++;
    }
    for(i=c;i<d;i++)
    {
        p[i]++;
    }
    for(i=0;i<101;i++)
    {
        if(p[i]==2) num++;
    }


    printf("%d",num);
}


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

//直角三角形かどうかを判定する関数
int isRightTriangle(int a, int b, int c);
  
//main関数
int main(){
  int i;
  int N;
  int a,b,c;
  int *ans;

  //1行目にデータセット数Nが与えられる。
  scanf("%d",&N);
  //ansの配列の要素数Nを動的に確保
  ans = (int *)malloc(sizeof(int) * N);

  //三角形の3辺a,b,c
  for(i=0;i<N;i++){
    scanf("%d %d %d",&a, &b, &c);
    ans[i] = isRightTriangle(a, b, c); //ans[i] = 1 or 0
  }
  
  //output
  for(i=0; i<N; i++){
    if(ans[i] == 1){
      printf("YES\n");
    }
    else{
      printf("NO\n");
    }
  }

  free(ans);
  return 0;
}

int isRightTriangle(int n1, int n2, int n3){
  int a,b,c;

  //n1とn2とn3がどれが一番大きい辺か調べる
  if(n1 >= n2 && n1 >= n3){
    c=n1; a=n2; b=n3;
  }
  else if(n2 >= n1 && n2 >= n3){
    c=n2; a=n1; b=n3;
  }
  else{
    c=n3; a=n1; b=n2;
  }

  //直角三角形ならば、三平方の定理が成り立つ。
  if(c*c == a*a + b*b){ //成り立つならば1を返す
    return 1;
  }
  else{                 //成り立たないならば0を返す
    return 0;
  }
}

Measured memory_bytes: 584