akhauriyash/Code-Regression huggingface dataset:
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll dp[102][2][102];
ll k;
vi num;
ll fun(ll pos,ll f,ll cnt)
{
	if(pos==sz(num))
	{
		if(cnt==k) return 1;
		else return 0;
	}

	if(dp[pos][f][cnt]!=-1) return dp[pos][f][cnt];
	ll lim=9;
	if(f) lim=num[pos];
	ll ans=0;
	rep(i,0,lim+1)
	{
		ll nf = 0;
		if(f==1 && i==lim) nf=1;
		ans+=fun(pos+1,nf,cnt+(i!=0));
	}

	return dp[pos][f][cnt]=ans;
}

int solve()
{
	memset(dp,-1,sizeof dp);
	string n;cin>>n>>k;
	rep(i,0,sz(n)) num.pb(n[i]-'0');
	cout<<fun(0,1,0)<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

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

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 384
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
 
const int INF = 100000000;
typedef pair<int ,int> P;
 
char maze[55][55];
int n,m;
int sx,sy;
int gx,gy;
 
int d[55][55];
 
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
 
int bfs()
{
    queue<P> que;
    for(int i = 0;i<n;i++)
    {
        for(int j = 0;j<m;j++)
        {
            d[i][j] = INF;
        }
    }
    que.push(P(sx,sy));
    d[sx][sy] = 0;
 
    while(que.size())
    {
        P p = que.front();
        que.pop();
        if(p.first == gx && p.second == gy)
            break;
        for(int i = 0;i<4;i++)
        {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if(nx>=0 && nx<=n && ny>=0 && ny<=m && maze[nx][ny] != '#' &&d [nx][ny] == INF)
            {
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    return d[gx][gy];
}
int main()
{
    cin>>n>>m;
    int sum1 = 0;
    for(int i = 0;i<n;i++)
    {
        for(int j = 0;j<m;j++)
        {
            cin>>maze[i][j];
            if(maze[i][j]=='.')sum1++;
        }
    }
    sx=0;
    sy=0;
    gx=n-1;
    gy=m-1;
    int resourt = bfs();
    if(resourt==INF)cout<<"-1"<<endl;
    else cout<<sum1-resourt-1<<endl;
    return 0;
}

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

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

    //mapのソートは宣言時に
    map<ll,ll,greater<ll>> A;
    rep(i,n){
        ll a;
        cin>>a;
        A[a]++;
    }

    vector<ll> tateyoko(1);
    //0で初期化されているのでpush_backはダメか？
    for(auto p:A){
        if(p.second>=4){
            tateyoko.push_back(p.first);
            tateyoko.push_back(p.first);
        }
        if(p.second>=2) tateyoko.push_back(p.first);
    }

    if(tateyoko.size()>=3)cout<<tateyoko[1]*tateyoko[2]<<endl;
    else cout<<0<<endl;

}

//pushbackの使い方(0に上書き不可)

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
int inf = 1000000000; //10e9
 
int main(){
 
    ll n, t, x;
    cin >> n >> x >> t;

    int tako = 0;
    int ans = 0;
    
    while(tako < n){
        tako += x;
        ans += t;
    }

    cout << ans << endl;

    return 0;
 
}

Measured memory_bytes: 3588
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

def f(x):
  if(x > 1):
    return (2 * f(x // 2) + 1)
  else:
    return 1

print(f(int(input())))


Measured memory_bytes: 13640
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int r, c, k;
    cin >> r >> c >> k;
    vector<vector<vector<ll>>> dp(r + 1,
                                  vector<vector<ll>>(c + 1, vector<ll>(4, 0)));
    vector<vector<ll>> grid(r + 1, vector<ll>(c + 1, 0));
    for(int i = 0; i < k; i++) {
        int a, b;
        cin >> a >> b;
        cin >> grid[a][b];
    }
    for(int i = 1; i <= r; i++) {
        for(int j = 1; j <= c; j++) {
            for(int l = 0; l < 4; l++) {
                ll tmp = max({dp[i - 1][j][3], dp[i][j - 1][l]});
                dp[i][j][l] = max(dp[i][j][l], tmp);
            }
            for(int l = 3; l > 0; l--) {
                dp[i][j][l] = max(dp[i][j][l], dp[i][j][l - 1] + grid[i][j]);
            }
        }
    }
    cout << dp[r][c][3] << endl;
}

Measured memory_bytes: 706992
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	map <int,int> m;
	map <int,vector<int> > l;
	int n;
	while(~scanf("%d\n", &n)) m[n]++;
	for(map<int, int>::iterator it = m.begin(); it != m.end(); it++)
		l[(*it).second].push_back((*it).first);
	sort((*l.rbegin()).second.begin(), (*l.rbegin()).second.end());
	for(int i = 0; i < (*l.rbegin()).second.size(); i++)
		printf("%d\n", (*l.rbegin()).second[i]);
	return 0;
}

Measured memory_bytes: 0
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

int main(){
	string s ; 
	cin >> s ; 
	int nax = -1e9 ; 
	for(int i=0;i<(int)s.size();i++){
		int cnt = 0 ; 
		while(s[i] == 'A' || s[i] == 'C' || s[i] == 'T' || s[i] == 'G' ){
			i++;
			cnt++ ;
		}
		nax = max(nax,cnt) ; 
	}
	cout << nax << endl;
    return 0 ;
}


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

using namespace std;

typedef long long ll;

int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, x, m;
  cin >> n >> x >> m;
  vector <ll> a(1, x);
  if (n < 1e6) {
    ll ans = x;
    while (--n) {
      x = x * x % m;
      ans += x;
    }
    cout << ans;
    return 0;
  }
  vector <int> last(m, -1);
  for (int i = 0; i < 2 * m; i++)
    a.push_back(a.back() * a.back() % m);
  for (int i = 0; i < a.size(); i++) {
    if (last[a[i]] == -1)
      last[a[i]] = i;
    else {
      ll ans = 0;
      int left = last[a[i]];
      int right = i;
      for (int i = 0; i < left; i++)
        ans += a[i];
      n -= left;
      vector <ll> sumpre(right - left);
      for (int i = 0; i < right - left; i++)
        sumpre[i] = (i ? sumpre[i - 1] : 0) + a[i + left];
      ll cel = n / (right - left), r = n % (right - left);
      ans += cel * sumpre[right - left - 1] + (r ? sumpre[r - 1] : 0);
      cout << ans;
      return 0;
    }
  }
  return 0;
}


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

const int MAXN=1e5+10;
const long long inf=1e18+2137;

long long dp[MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,W,w,v,ans;
    cin>>n>>W;
    for(int i=1;i<=1e5;i++)
        dp[i]=inf;
    for(int i=0;i<n;i++)
    {
        cin>>w>>v;
        for(int j=1e5;j-v>=0;j--)
            dp[j]=min(dp[j],dp[j-v]+w);
    }
    for(int i=0;i<=1e5;i++)
        if(dp[i]<=W)
            ans=i;
    cout<<ans;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <stdio.h>

using namespace std;

int pat[3][3];
int len[3];
int chr[3];
int zure;
int size;
bool atteru[3];
char text[100];
char ptext[100];

int main() {
	//cin >> text;
	while (gets(text)) {
		bool flag = false;
		for (int i = 0; i < size; i++) {
			if (text[i] != ptext[i]) break;
			if (i == size-1) flag = true;
		}
		if (flag) break;
	//int size = text.size();
	int pt = 0;
	size = 100;

	pat[0][0] = 't' - 'h';
	pat[0][1] = 'h' - 'e';
	pat[1][0] = 't' - 'h';
	pat[1][1] = 'h' - 'i';
	pat[1][2] = 'i' - 's';
	pat[2][0] = 't' - 'h';
	pat[2][1] = 'h' - 'a';
	pat[2][2] = 'a' - 't';
	chr[0] = 'e';
	chr[1] = 's';
	chr[2] = 't';
	len[0] = 3;
	len[1] = 4;
	len[2] = 4;

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (pat[i][j] < 0) pat[i][j] += 26;
		}
	}

	zure = -1;

	int cnt = 0;
	atteru[0] = true;
	atteru[1] = true;
	atteru[2] = true;
	for (int i = 0; i < size-1 && zure == -1; i++) {
		if (text[i] == ' ') {
			cnt = 0;
			atteru[0] = true;
			atteru[1] = true;
			atteru[2] = true;
			//cout << "yarinaoshi!" << endl;
			continue;
		}
		if (text[i+1] == ' ' || cnt > 3) continue;
		int dist = text[i] - text[i+1];
		if (dist < 0) dist += 26;
		for (int j = 0; j <= 2; j++) {
			if (!atteru[j]) continue;
			if (cnt >= len[j]-1) continue;
			if (dist != pat[j][cnt]) {
				atteru[j] = false;
				//cout << j << " ha tigau!" << endl;
				continue;
			} else if (cnt == len[j]-2) {
				if (text[i+2] == ' ') {
					//cout << j << " ha atteta!" << endl;
					zure = text[i+1] - chr[j];
					if (zure < 0) zure += 26;
					//cout << "zure = " << zure << endl;
				} else {
					atteru[j] = false;
					continue;
				}
			}
		}
		cnt++;
	}

	for (int i = 0; i < size; i++) {
		if (text[i] == EOF) break;
		if (text[i] < 'a' || text[i] > 'z') continue;
		text[i] = text[i] - zure;
		if (text[i] < 'a') text[i] += 26;
	}

	cout << text << endl;
	}

	return 0;
}

/*@@@@@@@@@@@@@@@@@@@@@@@@@*/
/*@                       @*/
/*@ debug output erased ? @*/
/*@                       @*/
/*@@@@@@@@@@@@@@@@@@@@@@@@@*/

Measured memory_bytes: 1120
#include <iostream>
#include <map>
#include <string>

using namespace std;

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

  map<char, int> m;
  for (char c : s) {
    m[c]++;
  }

  if (m['a'] > 0 && m['b'] > 0 && m['c'] > 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

template<typename T = char>
vector<pair<T, int>> run_length_encode(string &a) {
    vector<pair<T, int>> res;
    for (T &ai: a) {
        if (res.empty() || res.back().first != ai) res.emplace_back(ai, 1);
        else res.back().second++;
    }
    return res;
}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    auto res = run_length_encode(s);
    int sz = res.size();
    cout << sz << endl;
    return 0;
}

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

int main(){
  	int n, T;
  	cin >> n >> T;
  	
  	int ans = INT_MAX;
  	for(int i=0; i < n; i++){
    	int c, t;
      	cin >> c >> t;
      	if(ans > c && t <= T){
        	ans = c;
        }
    }
  
  	if(ans == INT_MAX){
    	cout << "TLE" << endl;
    }else{
		 cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class ABC164
{
    static void Main()
    {
        int[] n = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
        if(n[1] < n[0])
        {
            Console.WriteLine("safe");
        }
        else
        {
            Console.WriteLine("unsafe");
        }
    }
}

Measured memory_bytes: 19128
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    getline(cin, s);
    for(int i = 0; i < s.size(); i++) {
        char ch = s.at(i);
        if(isalpha(ch)) {
            if(islower(ch)) ch = toupper(ch);
            else if(isupper(ch)) ch = tolower(ch);
            s.at(i) = ch;
        }
    }
    cout << s << "\n";
}


Measured memory_bytes: 3228
#include <stdio.h>

int main(void)
{
	int n, k, i;
	int count = 0;
	int h[100000];

	scanf("%d %d", &n, &k);

	for (i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}

	for (i = 0; i < n; i++) {
		if (h[i] >= k) {
			count++;
		}
	}

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

	return 0;
}

Measured memory_bytes: 512
import std.stdio;

void main()
{
    int n, k;
    readf("%s\n", &n);
    readf("%s\n", &k);

    int v = 1;
    foreach(i; 0 .. n){
        if(v < k)
            v *= 2;
        else
            v += k;
    }

    writeln(v);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;



int main() {	
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	int total = 1;
	int sugar = 0;

	for (int i = 0; 0 <= f - 100 * a*i; i++) {
		for (int j = 0; 0 <= f - 100 * a - 100 * b*j; j++) {
			for (int k = 0; 0 <= f - 100 * a*i - 100 * b*j - c * k; k++) {
				for (int l = 0; 0 <= f - 100 * a*i - 100 * b*j - c * k - d * l; l++) {
					if (c*k + d * l <= e * (a*i + b * j)) {
						if (total * (c*k + d * l)>=sugar * (100 * a*i + 100 * b*j + c * k + d * l)) {
							total = (100 * a*i + 100 * b*j + c * k + d * l);
							sugar = (c * k + d * l);
						}
					}
				}
			}
		}
	}

	cout << total << " " << sugar << endl;


	return 0;

}

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

int main(){
    string S, T;
    cin >> S >> T;

  	//cout << T.substr(0, T.size() - 1) << endl;
    if (T.substr(0, T.size() - 1) == S){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main() {
  char S[4];
  scanf("%s", S);

  int A = 0;

  for(int i = 0; i < 4; i++) {
     if(S[i] == '+'){
       A++;
     }else
       A--;
  }
  printf("%d\n", A);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

int main() {
  int n,q;
  while( cin >> n >> q, n|q) {
    map<int,int> mp;
    int maxi = -1;
    for(int i=0;i<n;++i) {
      int m;
      cin >> m;
      for(int j=0;j<m;++j) {
	int data;
	cin >> data ;
	++mp[data];
	maxi = max(mp[data],maxi);
      }
    }
    vector<int> vec;
    for(auto v : mp) {
      if( v.second >= q ) {
	if( maxi == v.second ) {
	  vec.push_back(v.first);
	}
      }
    }
    if( vec.size() ) {
      sort(vec.begin(),vec.end());
      cout<< vec[0] << endl;
    }else {
      cout << 0 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3024
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    LL N;
    cin >> N;
    LL sum[N];
    REP(i, N) sum[i] = 0;
    LL a;
    REP(i, N)
    {
        cin >> a;
        sum[i] = (i == 0 ? 0 : sum[i - 1]) + a;
    }
    LL ans = 1000000000000000LL;
    REP(i, N - 1)
    {
        ans = min(ans, abs(sum[i] - (sum[N - 1] - sum[i])));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,a) FOR(i,0,(int)(a)-1)
#define reset(a,b) memset(a,b,sizeof(a))
#define BUG(x) cout << #x << " = " << x << endl
#define PR(x,a,b) {cout << #x << " = "; FOR (_,a,b) cout << x[_] << ' '; cout << endl;}
#define CON(x) {cout << #x << " = "; for(auto i:x) cout << i << ' '; cout << endl;}
#define mod 1000000007
#define pi acos(-1)
#define eps 0.00000001
#define pb push_back
#define sqr(x) (x) * (x)
#define _1 first
#define _2 second

long long n, ans;

long long f(long long x) {
	long long ret = 0;
	while (x) {
		ret++;
		x /= 10;
	}
	return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  ans = 1000;
  for (long long i = 1; i * i <= n; i++) if (n % i == 0) ans = min(ans, f(n / i));
  cout << ans;
}

Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main extends App {
  val Array(n, k) = readLine.split(" ").map(_.toInt)
  val seq = Iterator.continually(readLine)
    .take(n)
    .map(_.toInt)
    .toArray
    .sorted
  val l = k-1
  val ans = (l until n).map(i => seq(i) - seq(i-l))
  // println(ans.mkString(" "))
  println(ans.min)
}

Measured memory_bytes: 43432
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	int result = 0;
	int a, b, c;
	Scanner sc = new Scanner(System.in);
	try {
	    a = sc.nextInt();
	    b = sc.nextInt();
	    c = sc.nextInt();
	    for (int i = a; i <= b; i++) {
		if (canMod(i, c)) {
		    result++;
		}
	    }
	} catch (Exception e) {
	    System.out.println(e.getMessage());
	} finally {
	    sc.close();
	}
	System.out.println(result);
    }

    private static boolean canMod(int a, int c) {
	return c % a == 0 ? true : false;
    }
}

Measured memory_bytes: 26352
import sys
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()

    ans = 0
    for i in range(1, N): ans += i

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40708
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define int long long
using namespace std;

typedef pair<int, int> Pii;

void readint(int N, vector<int> &a);
void readdouble(int N, vector<double> &a);
void readindex(int N, vector<int> &a);



signed main(){

    int N, K;
    cin >> N >> K;

    int ans = 0;

    if(K == 0){
        ans = N * N;
    }
    if(K > 0){
        FOR(b, K + 1, N + 1){
            int x = N / b;
            //a=1,2,...,xbまで
            ans += x * (b - K);
            //残り
            int m = N % b;
            if(m >= K) ans += m - K + 1;
        }
    }

    cout << ans;

    return 0;
}








void readint(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readdouble(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}
void readindex(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str()) - 1;
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str()) - 1;
}

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

int main()
{
    long long n,k,sum=0 ;
    cin>>n>>k;
    int arr[n] ;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i] ;
    }

    if(k>=n)
    {
        cout<<0<<endl;
    }else{
        sort(arr,arr+n) ;
        for(int i=0;i<n-k;i++)
    {
        sum+=arr[i] ;
    }
    cout<<sum<<endl ;
    }
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<set>
#include<algorithm>
using namespace std;
int p[110000];
long long b[110000];
long long c[110000];
int bit[110000];
void add(int a,int b){
	for(;a<110000;a|=a+1)bit[a]+=b;
}
int sum(int a,int b){
	if(a)return sum(0,b)-sum(0,a-1);
	int ret=0;
	for(;b>=0;b=(b&(b+1))-1)ret+=bit[b];
	return ret;
}
pair<long long,int>ev[110000];
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	b[0]=p[0];
	for(int i=1;i<a;i++)b[i]=b[i-1]+p[i];
	for(int i=0;i<a;i++)scanf("%d",c+i);
	for(int i=0;i<a-1;i++)add(i,1);
	for(int i=0;i<a-1;i++)ev[i]=make_pair(b[i],i);
	std::sort(ev,ev+a-1);
	long long ret=0;
	for(int i=0;i<a-1;i++){
		add(ev[i].second,-1);
		ret+=sum(0,ev[i].second);
	}
	std::sort(b,b+a);
	bool dame=false;
	if(b[0]<c[0])dame=true;
	for(int i=1;i<a;i++){
		if(b[i]-b[i-1]<c[i])dame=true;
	}
	if(dame)printf("-1\n");
	else printf("%lld\n",ret);
}

Measured memory_bytes: 5304
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int A, B;
  cin >> A >> B;
  if (1 <= A && A <= 9 && 1 <= B && B <= 9) {
    cout << A * B << endl;
  } else {
    cout << -1 << endl;
  }
}

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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, h, w;
string s;

int main() {
    cin >> h >> w;

    VVi c(10, Vi(10));
    REP(i, 10) REP(j, 10) cin >> c[i][j];

    REP(k, 10) REP(i, 10) REP(j, 10) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    }

    ll res = 0;
    REP(i, h) REP(j, w) {
        int x; cin >> x;
        if (x == -1) continue;
        res += c[x][1];
    }
    std::cout << res << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ENDL '\n'
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FOR_EACH(i, v) for (auto&& i : v)

const int HP_MAX = 10001;
const int MAGIC_NUM = 1000;
int H;
int N;
pair<int, int> ans[MAGIC_NUM][HP_MAX];

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	cin >> H >> N;
	FOR(i, N) {
		ans[i][0] = make_pair(0, 0);
	}

	FOR(i, N) {
		int damage;
		int mp;
		cin >> damage >> mp;

		for (int j = 1; j <= H; j++) {
			if (j <= ans[i][j - 1].second) {
				ans[i][j] = ans[i][j - 1];
			}
			else {
				int t = j - damage >= 0 ? j - damage : 0;
				pair<int, int> p1;
				if (i) {
					 p1 = make_pair(ans[i - 1][j].first, ans[i - 1][j].second);
				}
				else {
					p1 = make_pair(-1, -1);
				}
				pair<int, int> p2 = make_pair(ans[i][t].first + mp, ans[i][t].second + damage);

				if (p1.first > p2.first || p1.first == -1) {
					ans[i][j] = p2;
				}
				else if (p1.first < p2.first) {
					ans[i][j] = p1;
				}
				else {
					if (p1.second > p2.second) {
						ans[i][j] = p1;
					}
					else {
						ans[i][j] = p2;
					}
				}
			}
		}
	}

	cout << ans[N - 1][H].first << ENDL;

	return 0;
}

Measured memory_bytes: 81676
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() { ;
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int X = sc.nextInt();
		int L[] = new int[N+2] ;
		for(int i = 1 ; i <= N ; i ++) {
			L[i] = sc.nextInt();
		}

		int D[] = new int[N+2] ;
		D[1] = 0 ;
		int ans = 2 ;
		for(int i = 2 ; i <= N + 1 ; i ++) {
			D[i] = D[i - 1] + L[i - 1];
			if(D[i] > X) {
				break;
			}
			ans = i ;
		}

		System.out.println(ans);
	}

}


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

    int main() {
        int N,M;
        int road[51]={0};
        int c1,c2;
        cin >> N >> M;

        for(int i=0;i<M;i++){
            cin >> c1 >> c2;
            road[c1]++;
            road[c2]++; 
        }
        for(int i=0;i<N;i++){
            cout << road[i+1] << endl;
        }
    }

Measured memory_bytes: 256
#ifdef ConanYu
#include "E:\yuzining\code\local.hpp"
#else
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(...) do { } while(false)
void Main();
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie();
  Main();
  return 0;
}
#endif

const int MOD = 1e9 + 7;

void add(int &x, int y) {
  x += y;
  if(x >= MOD) x -= MOD;
}

void sub(int &x, int y) {
  x -= y;
  if(x < 0) x += MOD;
}

int c1(int x) {
  return 1ll * x * (x + 1) / 2 % MOD;
}

struct Seive {
  int n;
  vector<bool> isp;
  vector<int> p, mu;
  Seive(int nn) : n(nn), isp(nn, true), mu(nn, 0) { solve(); }
  void solve() {
    isp[0] = isp[1] = false; mu[1] = 1;
    for (int i = 2; i < n; i++) {
      if (isp[i]) {
        p.push_back(i);
        mu[i] = -1;
      }
      for (int j = 0; j < (int)p.size() && i * p[j] < n; j++) {
        const int cur = i * p[j];
        isp[cur] = false;
        if (i % p[j]) {
          mu[cur] = -mu[i];
        }
        else {
          mu[cur] = 0;
          break;
        }
      }
    }
    for(int i = 1; i < n; i++) {
      if(mu[i] < 0) mu[i] += MOD;
      add(mu[i], mu[i - 1]);
    }
  }
};

Seive o(100005);

int fpow(int a, int b) {
  int ans = 1;
  for(; b > 0; b >>= 1, a = 1ll * a * a % MOD) {
    if(b & 1) {
      ans = 1ll * ans * a % MOD;
    }
  }
  return ans;
}

int c2(int m, int k) {
  int ret = 0;
  for(int i = 1, j; i <= m; i = j + 1) {
    j = m / (m / i);
    int c = o.mu[j];
    sub(c, o.mu[i - 1]);
    int cur = fpow(m / i, k);
    cur = 1ll * cur * c % MOD;
    add(ret, cur);
  }
  return ret;
}

void Main() {
  int n, k; cin >> k >> n;
  int ans = 0;
  for(int i = 1, j; i <= n; i = j + 1) {
    j = n / (n / i);
    int cur = c1(j);
    sub(cur, c1(i - 1));
    cur = 1ll * cur * c2(n / i, k) % MOD;
    add(ans, cur);
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

vector<vector<P>> G;
vector<int> loc;
vector<bool> seen;
bool dfs(int v) {
    if (loc[v]==INF) loc[v] = 0;
    seen[v] = true;
    for(const auto& p: G[v]) {
        int nv = p.fi, tmp = loc[v]+p.se;
        debug(seen[nv], v, nv, tmp);
        if (seen[nv] && loc[nv]!=tmp) return false;
        if (!seen[nv]) {
            loc[nv] = tmp;
            dfs(nv);
        }
    }
    return true;
}

int main() {
    int n, m; cin >> n >> m;
    G.resize(n);
    rep(i, m) {
        int u, v, cost; cin >> u >> v >> cost;
        u--; v--;
        G[u].emplace_back(v, cost);
        G[v].emplace_back(u, -cost);
    }
    loc.assign(n, INF);
    seen.assign(n, false);
    rep(i, n) {
        if (seen[i]) continue;
        if (!dfs(i)) {
            cout << "No" << endl;
            return 0;
        }
        debug(seen);
        debug(loc);
    }
    rep(i, n) {
        for(const auto& p: G[i]) {
            if (loc[p.fi]!=loc[i]+p.se) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 12032
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

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

static ll b[200010];
static ll w[200010];


int main() {
	int n;
	string s;

	cin >> n >> s;

	for (int i = 0; i < n ; i++) {
		w[i + 1] = w[i];
		if (s[i] == '#') {
			w[i + 1]++;
		}
	}


	for (int i = n - 1; i >= 0; i--) {
		b[i] = b[i + 1];
		if (s[i] == '.') {
			b[i] ++;
		}
	}

	ll min = 1LL << 62;

	rep(i , n + 1) {
		//cout << "i:" << " b:" << b[i] << " w:" << w[i] << endl;
		ll cur = b[i] + w[i];
		if (cur < min) {
			min = cur;
		}
	}

	cout << min << endl;
	

	
	return 0;
}

Measured memory_bytes: 3708
H, W, D = map(int, input().split())
dic = {}
memo = [0]*(H*W+1)

for i in range(H):
  s = input().split()
  for j in range(W):
    dic[int(s[j])] = (i,j)
    
for i in range(1,H*W+1):
  if i - D >= 1:
    memo[i] = memo[i-D] + abs(dic[i][0]-dic[i-D][0]) + abs(dic[i][1]-dic[i-D][1])
    
Q = int(input())
for _ in range(Q):
  l, r = map(int, input().split())
  print(memo[r]-memo[l])

Measured memory_bytes: 86820
#include<iostream>
#include<vector>
#include<map>

using namespace std;

int N;

int main(void) {
    cin>>N;
    int Max = -1e8,Min = 1e8;
    int Maxindex = -1,Minindex = -1;
    for(int i = 1;i <= N;i++) {
        int temp;
        cin>>temp;
        if(temp > Max) {
            Max = temp;
            Maxindex = i;
        }
        if(temp < Min) {
            Min = temp;
            Minindex = i;
        }
    }

    cout<<2*N-2<<endl;

    if(Max+Min > 0) {
        for(int x = 1;x <= N;x++) {
            if(Maxindex == x)
                continue;
            cout<<Maxindex<<" "<<x<<endl;
        }
        for(int x = 1;x <= N-1;x++) {
            int y = x+1;
            cout<<x<<" "<<y<<endl;
        }
    } else {
        for(int x = 1;x <= N;x++ ) {
            if(Minindex == x)
                continue;
            cout<<Minindex<<" "<<x<<endl;
        }
        for(int x = N;x >= 2;x--) {
            int y = x-1;
            cout<<x<<" "<<y<<endl;
        }
    }

    return 0;
}


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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF ((1LL<<62)-1)
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME ((1ll<<61)-1)

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

inline void out() {
	cout<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

bool isout(int h, int w, int H, int W) {
	return ( h<0 || h>=H || w<0 || w>=W );
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


string S;

void input() {
	cin>>S;
}

void solve() {
	cout<<S[0]<<S.len-2<<S[S.len-1]<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3620
N, M = map(int, input().split())
d = (N-1)//2
ans = []
ans.append((1, 1+d))

while True:
    a = ans[-1][0]+1
    b = ans[-1][1]-1
    
    if a>=b:
        break
    
    ans.append((a, b))

d2 = d-1
ans.append((2+d, 2+d+d2))

while True:
    a = ans[-1][0]+1
    b = ans[-1][1]-1
    
    if a>=b:
        break
    
    ans.append((a, b))

for a, b in ans[:M]:
    print(a, b)

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

using namespace std;

const int P = 998244353;
int fac[4005], ifac[4005];

int power(int a, int x) {
  int ans = 1;
  for (; x; x >>= 1, a = 1LL * a * a % P)
    if (x & 1) ans = 1LL * ans * a % P;
  return ans;
}
int calc(int N, int M) {
  return !M ? !N : 1LL * fac[N + M - 1] * ifac[M - 1] % P * ifac[N] % P;
}

int main() {
  int K, N;
  scanf("%d%d", &K, &N);
  for (int i = fac[0] = 1; i <= N + K - 2; ++i)
    fac[i] = 1LL * fac[i - 1] * i % P;
  ifac[N + K - 2] = power(fac[N + K - 2], P - 2);
  for (int i = N + K - 2; i; --i)
    ifac[i - 1] = 1LL * ifac[i] * i % P;
  vector<int> v(N + 1), res(K + 2);
  v[0] = 1;
  for (int S = 2; S <= 2 * K; ++S) {
    if (S <= K + 1 && S % 2) {
      for (int i = 1; i <= N; ++i)
        v[i] = (v[i] + v[i - 1]) % P;
      for (int i = N; i; --i)
        v[i] = (v[i] + v[i - 1]) % P;
    }
    int ans = 0;
    if (S <= K + 1) {
      for (int i = 0; i <= N; ++i) {
        int sum = ((S % 2 || !i ? 0 : v[i - 1]) + v[i]) % P;
        ans = (ans + 1LL * sum * calc(N - i, K + 1 - S)) % P;
      }
      res[S] = ans;
    } else
      ans = res[2 * K + 2 - S];
    printf("%d\n", ans);
  }
  return 0;
}


Measured memory_bytes: 384
a, b = map(int, input().split())

a_b = []
b_a = []

for i in range(b):
  a_b.append(str(a))
for i in range(a):
  b_a.append(str(b))

a_b = ''.join(a_b)
b_a = ''.join(b_a)

if a_b < b_a:
  print(a_b)
else:
  print(b_a)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
int main() {
	string a, b("CODEFESTIVAL2016");
	int i, count=0;
	cin >> a;
	for (i = 0;i < 16;i++) {
		if (a[i] != b[i]) {
			count++;
		}
	}
	cout << count << endl;
		return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int noto_mamiko, hayami_saori;
	for (noto_mamiko = 1; scanf("%d", &hayami_saori) == 1 && hayami_saori != 0; noto_mamiko++) {
		printf("Case %d: %d\n", noto_mamiko, hayami_saori);
	}
	return 0;
}



Measured memory_bytes: 2140
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main()
{
    string s;
    cin >> s;
    if (s == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 50;
int n, d;
int sz[maxn + 10], fa[maxn + 10];
int mn[maxn + 10];
ll m[maxn + 10];
ll f[maxn * maxn * maxn + 10], x, now, ans;
int nsz;


struct data {
	int val;
	ll w;
	int lim;

	bool operator < (const data &t) const {
		return val * t.w > w * t.val;
	}

}a[maxn + 10];

void addin(int j) {
	for (int k = 1; k <= mn[j]; ++k) {
		nsz += a[j].val;
		for (int l = nsz; l >= a[j].val; --l)
			f[l] = min(f[l], f[l - a[j].val] + a[j].w);
	}
}

void solve(int p) {
	ll now = 0, lstx = x;
	for (int i = 1; i < p; ++i) {
		if (a[i].lim - mn[i] > x / a[i].w) {
			x = lstx; return;
		}
		now += 1ll * (a[i].lim - mn[i]) * a[i].val;
		x -= 1ll * (a[i].lim - mn[i]) * a[i].w;
	}
	int i = p;
	for (int j = 0; j <= maxn * maxn * maxn; ++j)
		if (f[j] <= x)
			ans = max(ans, now + j + min<ll>((x - f[j]) / a[i].w, a[i].lim) * a[i].val);
	x = lstx;
}

void solve(int l, int r) {
	if (l == r) {
		solve(l); return;
	}
	ll tmp[maxn * maxn * maxn + 10];
	int lsz = nsz;
	memcpy(tmp, f, sizeof f);
	int mid = (l + r) >> 1;
	for (int i = l; i <= mid; ++i)
		addin(i);
	solve(mid + 1, r);
	memcpy(f, tmp, sizeof f); nsz = lsz;
	for (int i = mid + 1; i <= r; ++i)
		addin(i);
	solve(l, mid);
	memcpy(f, tmp, sizeof f); nsz = lsz;
}

int main() {
	scanf("%d%lld%d", &n, &x, &d);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &m[i]);
		if (i > 1) scanf("%d", &fa[i]);
	}
	for (int i = n; i >= 1; --i) {
		++sz[i]; sz[fa[i]] += sz[i];
		m[fa[i]] += m[i];
		a[i] = (data){sz[i], m[i], i == 1 ? int(1e9) : d};
	}
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i) mn[i] = min(a[i].lim, maxn);
	memset(f, 0x3f, sizeof f);
	f[0] = 0;
	solve(1, n);
	/*
	for (int i = 1; i <= n; ++i) {
		memset(f, 0x3f, sizeof f);
		f[0] = 0;
		int nowsz = 0;
		for (int j = 1; j <= n; ++j)
			if (j != i)
				for (int k = 1; k <= mn[j]; ++k) {
					nowsz += a[j].val;
					for (int l = nowsz; l >= a[j].val; --l)
						f[l] = min(f[l], f[l - a[j].val] + a[j].w);
				}
		for (int j = 0; j <= nowsz; ++j)
			if (f[j] <= x)
				ans = max(ans, now + j + min<ll>((x - f[j]) / a[i].w, a[i].lim) * a[i].val);
		if (a[i].lim - mn[i] > x / a[i].w) break;
		now += 1ll * (a[i].lim - mn[i]) * a[i].val;
		x -= 1ll * (a[i].lim - mn[i]) * a[i].w;
	}
	*/
	printf("%lld", ans);
}


Measured memory_bytes: 9088
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    L = list(input())
    n = len(L)

    dp = [[0] * 2 for _ in range(n + 1)]
    dp[0][0] = 1
    for i in range(1, n + 1):
        if L[i - 1] == "0":
            dp[i][0] = dp[i - 1][0]
            dp[i][1] = (dp[i - 1][1] * 3) % mod
        else:
            dp[i][0] = (dp[i - 1][0] * 2) % mod
            dp[i][1] = (dp[i - 1][1] * 3 + dp[i - 1][0]) % mod

    print((dp[-1][0] + dp[-1][1]) % mod)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 24432
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		
		double x=0;
		String u="";
		double sum=0;
		double btc=380000.;
		
		int n=sc.nextInt();
		
		for(int i=0;i<n;i++){
			x=sc.nextDouble();
			u=sc.next();
			if(u.equals("BTC"))x=x*btc;
			sum=sum+x;
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 22992
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
	int R, G, B, N,M1,M2,M3,m1,m2,m3;
	cin >> R >> G >> B >> N;
	int r, g, b;
	int count = 0;
	int a[3] = { R, G, B};    // 配列を用意する。
	sort(a, a+3);
	M1 = a[2];
	M2 = a[1];
	M3 = a[0];
	
	int flag = -1, N1 = 0;;
	int fcount = 0;
	for (m1 =0; m1<=N/M1; m1++) {
		N1 = N - M1 * m1;
		for (m2 =0; m2 <=N1/M2; m2++)
			if ((N1 - m2 * M2) % M3 == 0)
				fcount++;
	}

	
	cout << fcount;

	
}

Measured memory_bytes: 256
N = int(input())
S = input()
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            nums = [str(x) for x in [i, j, k]]
            for s in S:
                if s == nums[0]:
                    nums = nums[1:]
                    if len(nums) == 0:
                        ans += 1
                        break
print(ans)


Measured memory_bytes: 74260
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    b();
  }
  public static void b() {
    try (Scanner sc = new Scanner(System.in)) {
      int n = Integer.parseInt(sc.next());
      int k = Integer.parseInt(sc.next());
      int[] p = new int[n];
      for (int xx = 0; xx < n; xx++) {
        p[xx] = Integer.parseInt(sc.next());
      }
      Arrays.parallelSort(p);

      int goukei = 0;
      for (int ans = 0; ans < k; ans++) {
        goukei += p[ans];
      }

      System.out.println(goukei);

    } catch (Exception E) {
      System.out.println("エラー");
    }
  }
}

Measured memory_bytes: 38372
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<list>
#include<queue>
#define mm(a,b) memset(a,b,sizeof(a))
#define ACCELERATE (ios::sync_with_stdio(false),cin.tie(0))
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define MAXN 0x3f3f3f3f3f3f3f3f
#define PI acos(-1.0)
#define E exp(1.0)
using namespace std;

//#define debug

struct Puzzle{
    int e[10];
    int space;
    int ans;
};

Puzzle tmp;

bool state[362880];

int kangtuo(int x[])  //康拓展开进行判重
{
    int fac[]={1,1,2,6,24,120,720,5040,40320};
    int i,j,t,sum;
    sum = 0;
    for(i=0;i<9;i++)
    {
        t = 0;
        for(j=i+1;j<9;j++)
        {
            if(x[j]<x[i])
                t++;
        }
        sum = sum+t*fac[8-i];
    }
    if(state[sum]==1)
        return 0;
    else
    {
        state[sum] = 1;
        return 1;
    }
}

bool judge(Puzzle t){
    for(int i=0;i<=8;i++){
        if(t.e[i]!=i+1) return false;
    }
    return true;
}

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

int bfs(){
    queue<Puzzle> q;
    q.push(tmp);
    while(!q.empty()){
        Puzzle t=q.front();
        q.pop();
        kangtuo(t.e);
        if(judge(t)) return t.ans;
        for(int i=0;i<4;i++){
            int sx=t.space/3+dx[i];
            int sy=t.space%3+dy[i];
            if(sx>=3||sy>=3||sx<0||sy<0){
                continue;
            }
            Puzzle f;
            f.ans=t.ans+1;
            f.space=sx*3+sy;
//            cout<<sx<<" "<<sy<<endl;
            memcpy(f.e,t.e,sizeof(t.e));
            swap(f.e[sx*3+sy],f.e[t.space]);
            if(!kangtuo(f.e)) continue;

            q.push(f);
        }
    }
}

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

    ACCELERATE;
    mm(state,0);
    for(int i=0;i<9;i++){
        cin>>tmp.e[i];
        if(tmp.e[i]==0){
            tmp.e[i]=9;
            tmp.space=i;
            tmp.ans=0;
        }
    }
    int ans=bfs();
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 4656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a % 2 == 0 || b % 2 == 0)System.out.println("No");
		else System.out.println("Yes");
	}
}

Measured memory_bytes: 25300
from collections import defaultdict
def main(n,a):
    for i in range(2**n):
        ans=0
        for j in range(n):

            if (i>>j)&1:
                ans+=a[j]
        cnt[ans]=1
cnt = defaultdict(lambda: 0)
n=int(input())
a=list(map(int,input().split()))
main(n,a)
q=int(input())

for i in list(map(int,input().split())):
    if cnt[i]==1:print('yes')
    else:print('no')


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

template<typename T>
struct BinaryIndexedTree{
    vector<T> dat;
    BinaryIndexedTree(int n):dat(n+1,0){}
    void add(int i,T x){
        if (i==0) return;
        for (;i<=dat.size();i+=(i&-i)) dat[i]+=x;
    }
    T sum(int i){
        T res=0;
        for (;i>0;i-=(i&-i)) res+=dat[i];
        return res;
    }
    T query(int l,int r){ //[l,r)
        return sum(r-1)-sum(l-1);
    }
    int lower_bound(T x){
        if (x<=0) return 0;
        int lb=0,r=1;
        while(r<dat.size()) r<<=1;
        for (;r>0;r>>=1){
            if (lb+r<dat.size()&&dat[lb+r]<x){
                x-=dat[lb+r]; lb+=r;
            }
        }
        return lb+1;
    }
    void add0(int i,T x){add(i+1,x);}
    T sum0(int i){return sum(i+1);}
    T query0(int l,int r){return sum(r)-sum(l);}
};

// https://onlinejudge.u-aizu.ac.jp/problems/DSL_2_B

void DSL_2_B(){
    int n,q; cin >> n >> q;
    BinaryIndexedTree<int> BIT(n+1);
    for (;q--;){
        int c,x,y; cin >> c >> x >> y;
        if (!c) BIT.add(x,y);
        else cout << BIT.query(x,y+1) << '\n';
    }
}

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


Measured memory_bytes: 3328
import java.util.Scanner;


public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(; scanner.hasNext();)
		{
			int[] a = new int[2];
			a[0] = scanner.nextInt();
			a[1] = scanner.nextInt();
			
			int b = scanner.nextInt();
			
			int cnt = 0;
			for(int i=0; i<10; i++)
			{
				int j = i+1;
				if(!(j==a[0] || j==a[1] || j==b))
				{
					if(a[0]+a[1]+j <= 20)
					{
						cnt++;
					}
				}
			}

			System.out.println(cnt<4 ? "NO" : "YES");
		}
	}
}

Measured memory_bytes: 26320