akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	auto l = vector<int>(n);
	for(auto& m : l){
		cin >> m;
	}
	sort(l.begin(), l.end(), greater<int>());
	int ans = 0;
	for(auto i = 0; i < k; ++i){
		ans += l[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

const int MN = 100005;

int N, Q, b[MN], x;

int main() {
	scanf("%d%d", &N, &Q), Q *= 2;
	while (Q--) scanf("%d", &x), b[x] ^= 1;
	for (int i = 1; i <= N; ++i) if (b[i]) return puts("NO"), 0;
	puts("YES");
	return 0;
}

Measured memory_bytes: 1984
s=input()
n=len(s)

if n%2==0:
    odd=even=n//2
else:
    even=n//2
    odd=even+1
    
odd_black=0
even_black=0

for i in range(n):
    if i%2==0:
        if s[i]=="0":
            odd_black+=1
    else:
        if s[i]=="0":
            even_black+=1

odd_white=odd-odd_black
even_white=even-even_black

if odd_black<=even_black:
    count=odd_black+even_white
else:
    count=odd_white+even_black

print(count)

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
int n, m, x, y;
const int maxn = 1e5 + 100;
int in[maxn];
int main()
{
    cin>>n>>m;
    for(int i = 1; i <= m; i++){
        cin>>x>>y;
        in[x]++; in[y]++;
    }
    int f = 0;
    for(int i = 1; i <= n; i++) if(in[i]&1) f = 1;
    if(f) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;

}


Measured memory_bytes: 640
a=gets.to_i;b=gets.to_i;c=gets.to_i;x=gets.to_i
x/=50
sum=0
for k in 0..[x/10 ,a].min
for i in 0..[(x-10*k)/2,b].min
sum+=1 if x-10*k-2*i<=c
end
end
p sum

Measured memory_bytes: 1788
# 2019/08/04
# AtCoder Beginner Contest 136 - C

# Input
n = int(input())
h = list(map(int,input().split()))

# Check
hmax = h[0]
ans = "Yes"
for i in range(1, n):
    if hmax < h[i]:
        hmax = h[i]
    elif hmax - 1 > h[i]:
        ans = "No"
        break

print(ans)


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

int main() {
	int X;
	cin >> X;
	vector<int> Num(X+1,0);
	for (int i = 1; i <= X; i++) {
		int n = i;
		while (n <= X) {
			Num[n]++;
			n += i;
		}
	}
	long long ans = 0;
	for (long long i = 1; i <= X; i++) ans += i * Num[i];
	cout << ans << endl;
}

Measured memory_bytes: 42324
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define FL "a"
using namespace std;
typedef long long ll;
typedef long double dd;
const int N=2e5+10;
const int inf=2147483647;
const dd pi=acos(-1);
const ll INF=1ll<<60;
const int mod=998244353;
inline ll read(){
  ll data=0,w=1;char ch=getchar();
  while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
  if(ch=='-')w=-1,ch=getchar();
  while(ch<='9'&&ch>='0')data=data*10+ch-48,ch=getchar();
  return data*w;
}
inline void file(){
  freopen(FL".in","r",stdin);
  freopen(FL".out","w",stdout);
}

int n,k;
int main()
{
  n=read();k=read();
  puts(k<=(n+1)/2?"YES":"NO");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <queue>
using namespace std;


int main(){
    long long x;
    cin >> x;
    for(long long i = -200; i <= 200; ++i){
        for(long long j = -200; j <= 200; ++j){
            if(i * i * i * i * i - j * j * j * j * j == x){
                cout << i << " " << j;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define int int64_t
using namespace std;

const int M = 1e9+7;
int dp[(1 << 21)][22];
vector<vector<int>> v(22);

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

	int n;
	cin >> n;
	int a[n+1][n+1];
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) cin >> a[i][j];
	}
	memset(dp , 0 , sizeof(dp));
	dp[0][0] = 1;
	for(int i = 1; i < (1 << n); i++) v[__builtin_popcount(i)].push_back(i);
	for(int i = 1; i <= n; i++) {
		for(auto mask:v[i]) {
			for(int j = 0; j < n; j++) {
				if((mask & (1 << j)) != 0 && a[i][n-j] == 1) { 
					dp[mask][i] = (dp[mask][i] + dp[(mask ^ (1 << j))][i-1])%M;
				}
			}
		}
	}
	cout << dp[(1 << n)-1][n] << "\n";
	
    return 0;
}


Measured memory_bytes: 385828
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    i64 n;
    i64 L, T;
    std::cin >> n >> L >> T;

    vec<i64> ans(n);
    i64 cnt = 0;
    for (i64 i=0; i<n; i++) {
        i64 x, w;
        std::cin >> x >> w;

        i64 r = w==1 ? (x + T) % L : ((x - T) % L + L) % L;
        i64 q = w==1 ? (x + T) / L : -((T - x + L - 1) / L);
        ans.at(i) = r;
        cnt += q;
    }
    cnt = (cnt % n + n) % n;
    std::sort(ALL(ans));
    std::rotate(ans.begin(), ans.begin() + cnt, ans.end());

    for (i64 x: ans) {
        std::cout << x <<'\n';
    }
}


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

int main(){
  
  int N,K;
  cin>>N>>K;
  int sum=1;
  
  for(int i=0; i<N; i++){
    if(sum*2>sum+K){
      sum+=K;
    }
    else{
      sum*=2;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
/*
**    Your limitation it's only your imagination.
**
**    Author : Dhiraj Govindvira
**      Date : 01-Sep-2020 ~ Tuesday
**      Time : 03:19:14 PM
*/

#ifdef Dhiraj
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
    #define cerr if(0) cerr
#endif

// Macro --------------------------------------------------------------------

#define ll                  long long int
#define FOR(i, a, b, s)     for(ll i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define FOR1(b)             FOR(i, 0, b, 1)
#define FOR2(i, b)          FOR(i, 0, b, 1)
#define FOR3(i, a, b)       FOR(i, a, b, (a) <= (b) ? 1 :-1)
#define FOR4(i, a, b, s)    FOR(i, a, b, s)
#define GET5(a, b, c, d, e, ...) e
#define FORC(...)           GET5(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)
#define loop(...)           FORC(__VA_ARGS__)(__VA_ARGS__)
#define all(x)              x.begin(), x.end()
#define rall(x)             x.rbegin(), x.rend()
#define endl                '\n'

// Template -----------------------------------------------------------------

// multiple input
template <typename... T> 
inline void inp(T&... args) {
    ((cin>>args), ...);
}
// scan vector
template <typename T> 
inline istream& operator >>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream& operator >>(istream &in, pair<T, U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

void solve(int &T)
{
    ll n, m, d;
    cin >> n >> m >> d;

    vector<pair<ll, ll>> pos(n * m);
    loop(i, n) {
        loop(j, m) {
            ll x;
            cin >> x;
            pos[x - 1] = {i + 1, j + 1};
        }
    }

    map<ll, map<ll, ll>> db;
    loop(i, d)
    {
        ll ans = 0, s = i, e = i + d;
        while(e < n * m)
        {
            ans += abs(pos[s].first - pos[e].first);
            ans += abs(pos[s].second - pos[e].second);
            db[i][e] = ans;
            s = e, e += d;
        }
    }

    ll q;
    cin >> q;
    loop(q) {
        ll l, r;
        cin >> l >> r;
        l--, r--;
        cout << db[l % d][r] - db[l % d][l] << endl;
    }
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt", "r", stdin);
        freopen("D:/dhiraj/Programming/o1.txt", "w", stdout);
        // freopen("D:/dhiraj/Programming/e1.txt", "w", stderr);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    for(int i = 1; i <= t; i++) {
        cerr << "Case #" << i << "\n";
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 13996
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
using namespace std;

int main(){
	int a, b, h;
	cin >> a;
	cin >> b;
	cin >> h;
	int ans = (a+b)*h/2;
	
	printf("%d\n", ans);
	
	return 0;
}

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

int main() {
	long long N, ans;
	double M;
	cin >> N;
	M = sqrt((double)N);
	ans = N - 1;
	long long i;
	for (i = 1; i <= M; ++i) {
		if (N % i == 0) {
			long long val;
			val = N / i + i - 2;
			if (ans > val) ans = val;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0
for _ in range(N):
    A = list(map(int, input().split()))
    score = C
    for (ai, bi) in zip(A, B):
        score += ai * bi
    if score > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))

using namespace std;

int main()
{
    int n;
    int sum = 0;
    int maxv = -1;
    int a;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        sum = sum + a;

        maxv = max(maxv, a);
    }

    cout << (sum - maxv) + maxv / 2 << endl;
        
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;




int main() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i=3; i <10; ++i) {
        
        vi vec(i);
        
        rep(j, i-1) {
            rep(k, j) {
                string S;
                rep(h, i) {
                    if(h > j) {
                        S += '7';
                    } else if(h > k) {
                        S += '5';
                    } else {
                        S += '3';
                    }
                }

                do {
                    if(n >= stoi(S)) {
                        ans++;
                    }
                } while(next_permutation(S.begin(), S.end()));
            }
        }
        
    }

    cout << ans << endl;
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

long int combination(long int n, long int r);

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}

long int combination(long int n, long int r)
{
	if(r>n-r) r = n-r;
	if(r == 0) return 1;
	else if(r == 1) return n;
	return (combination(n-1, r) + combination(n-1, r-1));
	//大きくなるとき
	/*
	long int tmp1, tmp2, tmp3;
	tmp1 = combination(n-1, r);
	if(tmp1>=MOD) tmp1 = tmp1%MOD;
	tmp2 = combination(n-1, r-1);
	if(tmp2>=MOD) tmp2 = tmp2%MOD;
	tmp3 = tmp1+tmp2;
	if(tmp3>=MOD) tmp3 = tmp3%MOD;
	return (tmp3);
	*/
}


int main(){
	int n;
	scanf("%d", &n);
	int score[n], sum=0;
	for(int i=0; i<n; i++){
		scanf("%d", &score[i]);
		sum += score[i];
	}
	if(sum%10 != 0) printf("%d\n", sum);
	else{
		qsort(score, n, sizeof(int), compare_int);
		int i=0;
		while((i<n) && (score[i]%10 == 0)) i++;
		if(i==n) printf("0\n");
		else{
			sum = sum-score[i];
			printf("%d\n", sum);
		}
	}
	
	//printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<algorithm>
using namespace std;
int s[110];
pair<int,int> dat[110];
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a+b+c){
		int now=1;
		dat[0]=make_pair(b,c);
		for(int i=0;i<a;i++){
			int d,e;
			scanf("%d%d",&d,&e);
			int t=e%(dat[d-1].first+dat[d-1].second);
			if(t<dat[d-1].first){
				dat[now]=make_pair(min(t,dat[d-1].first-t),dat[d-1].second);
				dat[now+1]=make_pair(max(t,dat[d-1].first-t),dat[d-1].second);
			}else{
				t-=dat[d-1].first;
				dat[now]=make_pair(dat[d-1].first,min(t,dat[d-1].second-t));
				dat[now+1]=make_pair(dat[d-1].first,max(t,dat[d-1].second-t));
			}
			dat[d-1]=make_pair(-1,-1);
			now++;
			for(int j=0;j<now;j++){
				if(dat[j].first==-1){
					for(int k=j;k<now;k++)dat[k]=dat[k+1];
					break;
				}
			}
		}
		for(int i=0;i<now;i++)s[i]=dat[i].first*dat[i].second;
		std::sort(s,s+now);
		for(int i=0;i<now;i++){
			if(i)printf(" ");
			printf("%d",s[i]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define DEBUG true
#define $(x) {if (DEBUG) {cout << #x << " = " << (x) << endl;}}

const LL MOD = 1e9 + 7;
inline LL mod_add(LL a, LL b) { return (a + b) % MOD; }
inline LL mod_sub(LL a, LL b) { return (a + MOD - b) % MOD; }
inline LL mod_mul(LL a, LL b) { return ((a % MOD) * (b % MOD)) % MOD; }
LL mod_bipow(LL x, LL y) {   // x^y by bisection method
    if (y == 0) return 1;
    else if (y == 1) return x % MOD;
    else if (y % 2 == 0) {
        LL val = mod_bipow(x, (LL)(y / 2));
        return mod_mul(val, val);
    } else {
        LL val = mod_bipow(x, (LL)(y / 2));
        return mod_mul(mod_mul(val, val), x);
    }
}
LL mod_inv(LL x) { return mod_bipow(x, MOD - 2); }   // x^{-1} = x^{MOD-2} (MOD: prime number)
LL mod_div(LL a, LL b) { return mod_mul(a, mod_inv(b)); }   // a/b = a*b^{-1}

int main() {
    LL N, M;
    cin >> N >> M;
    unordered_set<LL> A;
    REP(i, M) {
        LL a;
        cin >> a;
        A.insert(a + 1);
    }

    VI dp(N + 2);
    dp[1] = 1;
    FOR(i, 2, N + 2) {
        if (A.count(i) == 0) {
            dp[i] = mod_add(dp[i - 1], dp[i - 2]);
        }
    }
    cout << dp.back() << endl;
	
    return 0;
}


Measured memory_bytes: 5156
#133 b
import itertools
n,d=map(int,input().split())
N=[i for i in range(n)]
k=[i*i for i in range(127)]
x=[]
for i in range(n):
    a=list(map(int,input().split()))
    x.append(a)
ans=0
kumi=itertools.combinations(N,2)

for a,b in kumi:
    s=0
    for j in range(d):
        s+=(x[a][j]-x[b][j])**2
    if s in k:
        ans+=1
print(ans)


Measured memory_bytes: 3064
def rythm_check(abc):
    sum = 0
    for i in abc.split():
        num = int(i)
        if num == 5 or num == 7:
            sum += num
        else:
            return 'NO'

    if sum == 17:
        return 'YES'
    else:
        return 'NO'

abc = input()
print (rythm_check(abc))

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

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

    int N, M;
    cin >> N >> M;

    map<int, long long> num;
    
    int A;
    for (int i=0; i<N; ++i) {
        cin >> A;
        num[A] ++;
    }

    int B, C;
    for (int i=0; i<M; ++i) {
        cin >> B >> C;
        num[C] += B;
    }

    long long sum = 0;
    for (auto it=num.rbegin(); it!=num.rend() && N > 0; ++it) {
        // B = it->second;
        // C = it->first; 
        sum += it->first * min((long long)N, it->second);
        N -= min((long long)N, it->second);
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 12800
s=input()
q=int(input())
trans=0
aft=""
bef=""
for i in range(q):
  que=input()
  if que[0]=="1":
    trans=1-trans
  else:
    if (que[2]=="1" and trans==0) or (que[2]=="2" and trans==1):
      bef=bef+que[4]
    else:
      aft=aft+que[4]
if trans==0:
  print("".join(bef[::-1])+s+"".join(aft))
else:
  print("".join(aft[::-1])+s[::-1]+"".join(bef))



Measured memory_bytes: 5108
#include<bits/stdc++.h>
using namespace std;
struct lis{
  int d;
  lis *pr;
  lis *ne;
};
lis he;
int n;
void ins();
void del();
void delf();
void dell();
int main(){
  cin >> n;
  string ord;
  lis bu={-1,&he,&he};
  he=bu;
  for(int i=0;i<n;i++){
    
    cin >> ord;

    if(ord=="insert")ins();
    else if(ord=="delete")del();
    else if(ord=="deleteFirst")delf();
    else if(ord=="deleteLast")dell();
  }
  for(lis *i=he.ne;i!=&he;i=i->ne){
    cout << i->d ;
    if(i->ne!=&he){
      cout << " ";
    }
  }
  cout << endl;
  return 0;
}
void ins(){
  int x;
  cin >> x;
  lis *p;
  p=new lis;
  p->d=x;
  p->ne=he.ne;
  p->pr=&he;
  he.ne->pr=p;
  he.ne=p;  
}
void del(){
  int x;
  cin >> x;
  for(lis *i=he.ne;i!=&he;i=i->ne){
    if(i->d==x){
      i->pr->ne=i->ne;
      i->ne->pr=i->pr;
      free(i);
      return;
    }    
  }
}
void dell(){
  lis *i=he.pr;
  i->pr->ne=i->ne;
  i->ne->pr=i->pr;
  free(i);
}
void delf(){
  lis *i=he.ne;
  i->pr->ne=i->ne;
  i->ne->pr=i->pr;
  free(i);
}

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


int main(){
    string s;
    string p;
    cin >> s >> p;
    s=s+s;
    if(s.find(p)!=-1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

}


Measured memory_bytes: 3180
class SegmentTree:
    def __init__(self, a):
        self.padding = -float('inf')    
        self.n = len(a)
        self.N = 2 ** (self.n-1).bit_length()
        self.seg_data = [self.padding]*(self.N-1) + a + [self.padding]*(self.N-self.n)
        for i in range(2*self.N-2, 0, -2):
            self.seg_data[(i-1)//2] = max(self.seg_data[i], self.seg_data[i-1])
    
    def __len__(self):
        return self.n
    
    def update(self, i, x):
        idx = self.N - 1 + i
        self.seg_data[idx] = x
        while idx:
            idx = (idx-1) // 2
            self.seg_data[idx] = max(self.seg_data[2*idx+1], self.seg_data[2*idx+2])
    
    def query(self, i, j):
        # [i, j)
        if i == j:
            return self.seg_data[self.N - 1 + i]
        else:
            idx1 = self.N - 1 + i
            idx2 = self.N - 2 + j # 閉区間にする
            result = self.padding
            while idx1 < idx2 + 1:
                if idx1&1 == 0: # idx1が偶数
                    result = max(result, self.seg_data[idx1])
                if idx2&1 == 1: # idx2が奇数
                    result = max(result, self.seg_data[idx2])
                    idx2 -= 1
                idx1 //= 2
                idx2 = (idx2 - 1)//2
            return result


N, K = map(int, input().split())
A = 300001
st = SegmentTree([0]*A)

for i in range(N):
    a = int(input())
    l = max(0, a-K)
    r = min(A-1, a+K)
    max_len = st.query(l, r+1)
    st.update(a, max_len+1)

print(st.query(1, A))

Measured memory_bytes: 108856
/*
@author: @sancodemonster
*/
 
#include <bits/stdc++.h>
 
#define flash ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define ll long long int
#define ld long double
#define pb push_back 
#define mp make_pair
#define MOD 1000000007
#define f(i,a,b)  for(long long i=a;i<b;i++)
#define all(c) (c).begin(),(c).end() 
using namespace std;

 
int main()
{
 /* #ifndef ONLINE_JUDGE
    freopen("C:\\desktopp\\new coding problems\\in.txt" , "r" , stdin);
    freopen("C:\\desktopp\\new coding problems\\out.txt" , "w" , stdout);
  #endif
*/
     flash;
     /////////////////////////////////////////////////////////////////////////////////////////////////////
      ll a,b,c;
      cin>>a>>b>>c;

      ll x = a - b;
      if(x>c)
      	cout<<"0";
      else
      cout<<c-x;
     /////////////////////////////////////////////////////////////////////////////////////////////////////

     return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

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

long long int INF = 1e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define line cout << "----------" << endl;


ll mod = 1000000007;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
void Yay(bool condition){

    if(condition){
        p("Yay!");
    }else{
        p(":(");
    }
    return;
}

//ll fact[800005],rfact[800005];
/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,ans,a,b,c,d,e,g,h,w,i,j,k,q;
ll x[300005],y[300005],z[100005];
bool used[1000000];
bool dame;


void dfs(ll v){
	used[v] = true;
	if(v >= 200000){
		a++;
	}else{
		b++;
	}
	for(int i=0;i<G[v].size();i++){
		ll nv = G[v][i];
		if(used[nv]) continue;
		if(!used[nv]){
			dfs(nv);
		}
	}
}

int main(){
	cin >> n;
	for(i=0;i<n;i++){
		cin >> x[i] >> y[i];
		G[x[i]].pb(y[i] + 200000);
		G[y[i] + 200000].pb(x[i]);
	}
	for(int i=0;i<n;i++){
		if(!used[x[i]]){
			dfs(x[i]);
		}
		ans += a * b;
		//pe(a);p(b);
		a = b = 0;
		if(!used[y[i] + 200000]){
			dfs(y[i] + 200000);
		}
		ans += a * b;
		//pe(a);p(b);
		a = b = 0;
	}
	p(ans - n);
	return 0;
}


Measured memory_bytes: 23040
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	string s;
	cin>>s;
	int ans=700;
	rep(i,3)if(s[i]=='o')ans+=100;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, ans, a[1000], res;

int main(){
	while (cin >> n&&n){
		res = 0;
		fill(a, a + 1000, 0);
		REP(i, n)cin >> a[i];
		cin >> ans;
		int lb = -1, ub = n;
		while (ub - lb > 1){
			/*cout << ub << " " << lb << endl;*/
			int mid = (ub + lb) / 2;
			if (a[mid] < ans){
				lb = mid;
				res++;
			}
			else if (a[mid] > ans){
				ub = mid;
				res++;
			}
			else{
				res++;
				break;
			}
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;

const double PI = acos(-1.0);

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	h += m / 60, h *= 5;
	h *= PI / 30, m *= PI / 30;
	if(h > m) swap(h, m);
	double angle = min(m - h, 2 * PI + h - m);
	cout << setprecision(10) << fixed << sqrt(a * a + b * b - 2 * a * b * cos(angle)) << '\n';
}


Measured memory_bytes: 4172
import java.io.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        int n = sc.nextInt();
        sc.nextLine();
        String s = sc.next();
 
        int max = 0;
        int x = 0;
        for (int i = 0; i < n; ++i) {
            char ch = s.charAt(i);
            if (ch == 'I') {
                ++x;
            } else if (ch == 'D') {
                --x;
            }
            if (x > max) {
                max = x;
            }
        }
        _out.println(max);
    }
    private long C(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        for (long i = r; i > 1; --i) {
            res /= i;
        }
        return res;
    }
    private long P(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
int main(void){
  long long int a,b,x,res,i;
  cin>>a>>b>>x;
  if(x==1){
    cout<<b-a+1<<endl;
    return 0;
  }
  res=(b/x)-((a-1)/x);
  if(a==0&&b==0)  res=1;
  else if(a==0||b==0) res++;
  cout<<res<<endl;
  return 0;
}

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

int main(){
  int n,i;
  vector<pair<int,int> > v;
  cin >> n;
  long long a[n];
  int t;
  long long mx = 0,cnt=0;
  bool ch;
  for(i=0;i<n;i++){
    cin >> a[i];
    if(abs(a[i])-abs(mx)>0){
      mx = a[i];
      t=i;
    }
  }
  if(mx>=0)ch=true;
  else ch = false;
  for(i=0;i<n;i++){
    a[i]+=mx;
    cnt++;
    v.push_back(make_pair(t+1,i+1));
  }
  if(ch){
  	for(i=1;i<n;i++){
       a[i]+=a[i-1];
       v.push_back(make_pair(i,i+1));
       cnt++;
    }
  }else{
    for(i=n-2;i>=0;i--){
       a[i]+=a[i+1];
       v.push_back(make_pair(i+2,i+1));
       cnt++;
    }
  }
  cout << cnt << endl;
  for(i=0;i<v.size();i++){
    cout << v[i].first << " " << v[i].second << endl;
  }
  return 0;
}
    

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

int main() {
	
	long long n, tmp;
	cin >> n;
	tmp = n;
	
	cout << n << ":";
	for(long long i = 2; i * i <= n; ++i){
		while(tmp % i == 0){
			cout << " " << i;
			tmp /= i;
		}
	}
	
	if(tmp != 1) cout << " " << tmp;
	
	cout << endl;
	return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

int main()
{
    string s;
    cin>>s;
    int n=s.length();
    int ans=0;
    bool flag=true;
    rep(i,(n-1)/2)
    {
        if(s[i]!=s[n-1-i])flag=false;
    }
    if(flag)ans++;

    string ls=s.substr(0,(n-1)/2);
    string rs=s.substr((n-1)/2+1,(n-1)/2);
    bool lflag=true;
    bool rflag=true;
    rep(i,(n-1)/2)
    {
        if(ls[i]!=ls[(n-1)/2-1-i])lflag=false;
        if(ls[i]!=ls[(n-1)/2-1-i])rflag=false;
    }
    if(lflag)ans++;
    if(rflag)ans++;
    if(ans==3)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

const int MAX=2100000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for (int i=2;i<MAX;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i - 1]*inv[i]%MOD;
	}
}
long long COM(int n, int k){
	if(n<k) return 0;
	if(n<0||k<0) return 0;
	return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll power(ll x, ll y) {
	if (y==0) return 1;
	else if (y==1) return x%MOD;
	else if (y%2==0) { ll pow=power(x,y/2); return (pow*pow)%MOD; } 
	else { ll pow=power(x,y/2); return ((pow*pow)%MOD)*x%MOD; }
}

int main(){
	COMinit();
	int k; cin >> k;
	string s; cin >> s;
	int n=s.size();
	ll ans=0;
	for(int i=n;i<=n+k;i++){
		ans+=(COM(n+k,i)*power(25,n+k-i))%MOD;
		ans%=MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 54480
#include<bits/stdc++.h>//懒人专用头文件
using namespace std;
string s;char c;
main()
{
	cin>>s;
	for(register int i=1;cin>>c/*一直输入*/;i+=2/*不能是++，刚刚插入的那个字符也算一个位置*/)s.insert(i,&c/*记住，要取地址*/);
	cout<<s;/*输入文件里有回车，所以不用手动添加endl*/
}

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() {
  ll N, D;
  cin >> N >> D;
  int ans = 0;
  rep(i, N) {
    ll X, Y;
    cin >> X >> Y;
    if (X * X + Y * Y <= D * D) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<algorithm>
#include<math.h>

using namespace std;

int main() {
    double x1, x2, xp, y1, y2, yp, slope, ansx, ansy;
    int q;
    bool X_FLG = false, Y_FLG = false;
    
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    scanf("%d", &q);
    
    if(y1 == y2) {
        X_FLG = true;
    }else if(x1 == x2) {
        Y_FLG = true;
    }else {
        slope = (y2 - y1) / (x2 - x1);
    }
    
    for(int i = 0; i < q; i++) {
        scanf("%lf %lf", &xp, &yp);
        
        if(X_FLG) {
            ansx = xp, ansy = y1;
            printf("%.10lf %.10lf\n", 2 * ansx - xp, 2 * ansy - yp);
        }else if(Y_FLG) {
            ansx = x1, ansy = yp;
            printf("%.10lf %.10lf\n", 2 * ansx - xp, 2 * ansy - yp);
        }else {
            ansx = (yp*(x2-x1)*(y2-y1)+xp*(x2-x1)*(x2-x1)-y1*(y2-y1)*(x2-x1)+x1*(y2-y1)*(y2-y1))/((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
			ansy = ((x1-x2)*ansx+yp*(y2-y1)+xp*(x2-x1))/(y2-y1);
			printf("%.10lf %.10lf\n",2*ansx-xp,2*ansy-yp);
		}

	}

	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  long count = 0;
  vector<int> last1(20, -1);
  int dmin = 0;
  for (int i = 0; i < n; i++) {
    dmin++;
    for (int j = 0; j < 20; j++) {
      if ((a.at(i) >> j) % 2 == 1) {
        dmin = min(dmin, i - last1.at(j));
        last1.at(j) = i;
      }
    }
    count += dmin;
  }
  cout << count << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		int n = input();
		double dept = 100000;

		for (int i = 0; i < n; i++) {

			dept *= 1.05;

			if (dept % 1000 != 0) {

				dept = (Math.ceil(dept / 1000)) * 1000;

			}
		}

		System.out.println((int)dept);

		close();

	}

	public static int input() {

		return scanner.nextInt();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}

Measured memory_bytes: 26120
// Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:

/*

*/
#include <bits/stdc++.h>
using namespace std;

int main(){

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    int n;
    scanf("%d",&n);
    vector<double>dp(n+5,0);
    double p;
    scanf("%lf",&p);
    dp[0] =(1-p);
    dp[1] = p;

    for(int i=1;i<n;i++){
        vector<double>newdp(n+1,0);
        scanf("%lf",&p);
        for(int j = n;j>=0;j--){
            newdp[j] = (1-p)*dp[j];
            if(j-1>=0) newdp[j] = newdp[j] + p*dp[j-1];

        }
        dp = newdp;

    }
    double res = 0;
    for(int i=n/2+1;i<=n;i++){
        res = res + dp[i];
    }
    printf("%.10lf\n",res);
	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
const int inf = 1 << 28;

template<typename T> inline void chmin(T& t, T f){if(t > f)t = f;}
template<typename T> inline T sqr(T x){return x * x;}

int N, M;

int solve(vector<int>& Cs, vector<int>& xs){
    vector<int> dp(256, inf); dp[128] = 0;
    rep(i, N){
        vector<int> nxt(256, inf);
        rep(y, 256)if(dp[y] != inf){
            rep(j, M){
                int ny = max(0, min(y + Cs[j], 255));
                chmin(nxt[ny], dp[y] + sqr(xs[i] - ny));
            }
        }
        dp.swap(nxt);
    }
    return *min_element(all(dp));
}

int main(){
    while(cin >> N >> M, N|M){
        vector<int> Cs(M), xs(N);
        rep(i, M)cin >> Cs[i];
        rep(i, N)cin >> xs[i];
        cout << solve(Cs, xs) << '\n';
    }
    return 0;
}

Measured memory_bytes: 1276
#include <stdio.h>

int main(void)
{

  int i, j, N, A[100], minj, c = 0, temp;

  scanf ("%d", &N);

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

for (i = 0; i < N; i++) {
   minj = i;
 
 for (j = i; j < N; j++) {
  if (A[j] < A[minj]) {
   minj = j;
}
}
 if(i != minj) {
 temp = A[minj];
 A[minj] = A[i];
 A[i] = temp;
 c++;
}
}
for (i = 0; i < N-1; i++){
 printf("%d ", A[i]);
}
 printf("%d\n%d\n",A[N-1],  c);

return 0;
}

Measured memory_bytes: 2708
#include<iostream>
#include<cstdio>
#include<cstring>

inline void check_max(int a,int &b){if(a>b)b=a;}
inline void check_min(int a,int &b){if(a<b)b=a;}

namespace YouQu____o_o________nyg_tai_qiang_le
{
	typedef std::pair<int,int> pii;
	const int N=12,M=202;

	struct outputer
	{
		int n,m,S,T;
		int w[M*M];
		pii E[M*M];
		void reset(int n_){n=n_,m=0;}
		void insert(int u,int v,int k){E[++m]=pii(u,v);w[m]=k;}
		void output()
		{
			printf("%d %d\n",n+1,m);
			for(int i=1;i<=m;i++)
			{
				printf("%d %d ",E[i].first+1,E[i].second+1);
				if(w[i]==-1)printf("X\n");
				else if(w[i]==-2)printf("Y\n");
				else printf("%d\n",w[i]);
			}
			printf("%d %d\n",S+1,T+1);
		}
	}d;

#define idx(p) (p)
#define idy(p) (201-(p))

	int dis[N][N],G[M][M];
	int A,B,lim;

	int calc(int x,int y)
	{
		int ret=23333;
		for(int i=0;i<=lim;i++)
			for(int j=0;j<=lim;j++)
				check_min(x*i+y*j+G[i][j],ret);
		return ret;
	}

	void solve()
	{
		lim=100;

		scanf("%d%d",&A,&B);
		for(int i=1;i<=A;i++)
			for(int j=1;j<=B;j++)
				scanf("%d",&dis[i][j]);

		for(int i=0;i<=lim;i++)
			for(int j=0;j<=lim;j++)
			{
				G[i][j]=0;
				for(int x=1;x<=A;x++)
					for(int y=1;y<=B;y++)
						check_max(dis[x][y]-x*i-y*j,G[i][j]);
			}

		for(int i=1;i<=A;i++)
			for(int j=1;j<=B;j++)
				if(calc(i,j)!=dis[i][j]){printf("Impossible\n");return;}

		printf("Possible\n");

		d.reset(idy(0));d.S=idx(0),d.T=idy(0);

		for(int i=0;i<lim;i++)d.insert(idx(i),idx(i+1),-1);
		for(int i=lim;i;i--)d.insert(idy(i),idy(i-1),-2);

		for(int i=0;i<=lim;i++)
			for(int j=0;j<=lim;j++)
				d.insert(idx(i),idy(j),G[i][j]);

		d.output();
	}
}

int main()
{
//	freopen("out","w",stdout);
	YouQu____o_o________nyg_tai_qiang_le::solve();
	return 0;
}


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


int main(){

    int N, M, C;
    cin >> N >> M >> C;
    int B[M];

    for(int i=0; i<M; i++){
        cin >> B[i];
    }
    int A[N][M];
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            cin >> A[i][j];
        }
    }
    int count = 0;
    for(int i=0; i<N; i++){
        int total = 0;
        for(int j=0; j<M; j++){
            total += A[i][j] * B[j];
        }

        total += C;
        if(total > 0){
            count ++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll n, m;
vector<ll> a;
string infs;
string minusinf;
string memo[10010];
string maxs(string f, string s){
    if(f[0] == '#'){
        return s;
    }
    if(s[0] == '#'){
        return f;
    }
    if(f.size() > s.size()){
        return f;
    } else if(f.size() < s.size()){
        return s;
    } else {
        if(f >= s){
            return f;
        } else {
            return s;
        }
    }
}
map<ll,ll> mp = {{1, 2}, {2, 5}, {3, 5}, {4, 4}, {5, 5}, {6, 6}, {7, 3}, {8, 7}, {9, 6}};
string rec(ll i){
    if(i == 0){
        return "";
    }
    if(memo[i] != "none") return memo[i];
    //cout << "i " << i << endl;
    string res = minusinf;
    rep(j, m){
        if(i - mp[a[j]] < 0) continue;
        res = maxs(res, rec(i - mp[a[j]]) + to_string(a[j]));
    }
    //cout << "r " << i << " " << res << endl;
    return memo[i] = res;
}

string test(){
    return "";
}

int main(void){
    cin >> n >> m;
    a.resize(m);
    rep(i, m) cin >> a[i];
    minusinf.push_back(char(35));

    rep(i, 10010){
        infs += '9';
        memo[i] = "none";
    }
    //cout << char(35) << endl;
    cout << rec(n) << endl;
}

Measured memory_bytes: 30848
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

long long f(long long b, long long n)
{
	if (n < b) return n;
	else return f(b, n / b) + n % b;
}

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

	long long N, S;
	cin >> N >> S;

	if (N < S)
	{
		cout << -1;
		return 0;
	}
	else if (N == S)
	{
		cout << N + 1;
		return 0;
	}
	else
	{
		for (long long b = 2; b <= sqrt(N); b++)
		{
			if (f(b, N) == S)
			{
				cout << b;
				return 0;
			}
		}

		long long result = 1e11 + 1;
		for(long long p = 1; p < sqrt(N); p++)
		{
			long long new_b = (N - S) / p + 1;
			if (new_b < 2) continue;

			if (f(new_b, N) == S)
			{
				result = min(result, new_b);
			}
		}

		if (result > 1e11)
		{
			cout << -1;
			return 0;
		}

		cout << result;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
string s;
bool dp[2005][3];
int main(){
	cin >> n >> s;
	dp[0][0] = 1;
	rep(i,n){
		for(int j=2;j>=0;j--){
			rep(x,105){
				if(dp[x][j] == false) continue;
				dp[x*10+s[i]-'0'][j+1] = 1;
			}
		}
	}
	int ans = 0;
	for(int i=0;i<1000;i++) if(dp[i][3])ans++;
	cout<<ans<<endl;}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    char ch1,ch2;
    int a,b;
    cin>>ch1>>ch2;
    if (ch1=='A')
        a=10;
        if (ch1=='B')
            a=11;
        if (ch1=='C')
            a=12;
        if (ch1=='D')
            a=13;
        if (ch1=='E')
            a=14;
        if (ch1=='F')
            a=15;
        if (ch2=='A')
        b=10;
        if (ch2=='B')
            b=11;
        if (ch2=='C')
            b=12;
        if (ch2=='D')
            b=13;
        if (ch2=='E')
            b=14;
        if (ch2=='F')
            b=15;
            if (a>b)
                cout<<">"<<endl;
            else if (a==b)
                cout<<"="<<endl;
            else cout<<"<"<<endl;
    return 0;
}


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

dp = [float("inf")]*(10**5+10)
dp[0] = 0

for i in range(N-1):
    Mi = min(K+1,N-i)
    for j in range(1,Mi):
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))

print(dp[N-1])


Measured memory_bytes: 55520
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

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

		double total = 0;
		for (int i=0; i<n; i++) {
			a[i]=new Integer(sc.nextInt());
			total += a[i];
		}
		sc.close();		
		String ans = "Yes";
		Arrays.sort(a, Collections.reverseOrder());

		for (int i=0; i<m; i++) {
			if (a[i]<total/(m*4)) {
				ans = "No";
				break;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
typedef pair<int,int> P;
const int INF=1e9;
const int MOD= 1000000007;
int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>> a(h,vector<char>(w));
    rep(i,h) rep(j,w) cin>>a[i][j];
    vector<vector<int>> dat(h,vector<int>(w));
    dat[0][0]++;
    rep(i,h) rep(j,w){
        if(i==0&&j==0) continue;
        if(0<=i-1&&a[i-1][j]=='.') dat[i][j]+=dat[i-1][j];
        if(0<=j-1&&a[i][j-1]=='.') dat[i][j]+=dat[i][j-1];
        dat[i][j]%=MOD;
    }
    cout<<dat[h-1][w-1];
}

Measured memory_bytes: 8560
'use strict'

function main(input){
  const lines = input.split('\n');
  const ABCDEF = lines.shift().split(' ').map(x => parseInt(x));
  const A = ABCDEF[0];
  const B = ABCDEF[1];

  const C = ABCDEF[2];
  const D = ABCDEF[3];

  const E = ABCDEF[4];
  const F = ABCDEF[5];

  let water = [];
  let sugers = [];
  for(var i=0;i<=F;i++){
    for(var j=0;j<=F;j++){
      let c_water = 100*(A*i+B*j);
      if(c_water<=F){ water.push(c_water); }

      let suger = C*i + D*j;
      if(suger<=F){ sugers.push(suger); }
    }
  }


//--------------
  let sugerWater = []; // とりうる砂糖水の量
  let sugerWeight = []; // とりうる砂糖の量

  // とりうる砂糖水と砂糖の量を列挙
  for(let i = 0; i <= water.length; i++){
    for(let j = 0; j <= sugers.length; j++){
      let sw = water[i] + sugers[j]; // 砂糖水の量
      let meltSuger = 100 * sugers[j] / water[i]; // 水に溶ける砂糖の量
      if( sw <= F && meltSuger <= E){
        sugerWater.push(sw);
        sugerWeight.push(sugers[j]);
      }
    }
  }  

  let results = [];
  for(let i=0;i<water.length;i++){
    for(let j=0;j<sugers.length;j++){      let total = water[i] + sugers[j];
      let melt_suger = 100*sugers[j]/water[i];

      if( (total <= F) && (melt_suger <= E) ){
        results.push([water[i], sugers[j]]);
      }
    }
  }





  // 各砂糖水と砂糖の量から、濃度を求める
  let noudo = 0;
  let noudoIndex = 0;
  for(let i = 0; i < sugerWater.length; i++){
    let noudoTmp = (100 * sugerWeight[i]) / sugerWater[i]; // 砂糖水の濃度
    if(noudoTmp > noudo){
      noudo = noudoTmp;
      noudoIndex = i;
    }
  }
  
  console.log(sugerWater[noudoIndex] + ' ' + sugerWeight[noudoIndex]);

return;
//--------------


  let tmp_density = 0.0;
  let result = [];
  for(let i=0;i<results.length;i++){
      let current_density = (100*results[i][1])/(results[i][0]+results[i][1]);
      if(current_density > tmp_density){ 
        tmp_density = current_density;
        result = results[i];
      }
  }

//console.log(result);
  console.log((result[0] + result[1])+' '+result[1]);
}
main( require('fs').readFileSync( '/dev/stdin', 'utf8') );


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

using namespace std;

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;

  if (s == u) {
    cout << max(a - 1, 0) << " " << b << endl;
  } else {
    cout << a << " " << max(b - 1, 0) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.*;
import java.util.Map.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }

        Map<Integer, Integer> ans = new TreeMap<>(Comparator.reverseOrder());
        int min = a.get(0);
        for (int i = 1; i < n; i++) {
            if (a.get(i) <= min) {
                min = a.get(i);
                continue;
            }
            int b = Math.abs(a.get(i) - min);
            if (!ans.containsKey(b)) {
                ans.put(b, 0);
            }
            ans.put(b, ans.get(b) + 1);
        }
        System.out.println(ans.values().toArray()[0]);
    }
}


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

int main(void){
	int a0, l;
	while(cin >> a0 >> l, a0+l){
		vector<int> a(20);
		a[0] = a0;
		int i = 0, j = 0;
		while(1){
			vector<int> keta(l);
			int a_ = a[i++];
			for(int k = 0; k < l; ++k){
				keta[k] = a_%10;
				a_ /= 10;
			}
			sort(keta.begin(), keta.end());
			int small=0;
			for(int k = 0; k < l; ++k){
				small *= 10;
				small += keta[k];
			}
			sort(keta.rbegin(), keta.rend());
			int large=0;
			for(int k = 0; k < l; ++k){
				large *= 10;
				large += keta[k];
			}
			a[i] = large - small;
			for(j = 0; j < i-1; ++j){
				if(a[j] == a[i]) break;
			}
			if(a[j] == a[i]) break;
		}
		printf("%d %d %d\n", j, a[i], i-j);
	}
	return 0;
}


Measured memory_bytes: 3220