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

string strPlusStr(const string& s1, const string& s2)
{
	string ans, a = s1, b = s2;
	int flag = 0;
	if (a.size() < b.size()) swap(a, b);

	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	int n = a.size() - b.size();
	for (int i = 0; i < n; i++)
	{
		b.push_back('0');
	}

	for (int i = 0; i < a.size(); i++)
	{
		int A = a[i] - '0';
		int B = b[i] - '0';
		int sum = (A + B + flag);
		ans.push_back(sum % 10 + '0');
		if (sum > 9) flag = 1;
		else flag = 0;
	}
	if (flag) ans.push_back('1');
	reverse(ans.begin(), ans.end());
	return ans;
}

void split(string str, char v, string& substr1, string& substr2)
{
	for (int i = 0; i < str.size(); i++)
	{
		if (str[i] == v)
		{
			substr1 = str.substr(0, i);
			substr2 = str.substr(i + 1, str.size() - i - 1);
			return;
		}
	}
}

bool isEqual(string str)
{
	string a, b, c, tmp;
	split(str, '+', a, tmp);
	split(tmp, '=', b, c);

	if (strPlusStr(a, b) == c) return true;
	return false;
}

int main()
{
	string str;
	while (cin >> str)
	{
		for (int i = 0; i <= 9; i++)
		{
			string s = str;
			replace(s.begin(), s.end(), 'X', char(i + '0'));
			if (isEqual(s))
			{
				cout << i << endl;
				break;
			}
			if (i == 9)
			{
				cout << "NA" << endl;
				break;
			}
		}
	}

	return 0;
}

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

int main() {
	int N;
	cin >> N;
	long A[100005];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	long J[100005] = {};
	for (int i = 0; i < N-1; i++) {
		if (A[i] > A[i + 1]) J[i + 1] = -1;
		else if (A[i] < A[i + 1]) J[i + 1] = 1;
	}
	long ans = 1,now=0;
	for (int i = 0; i < N; i++) {
		if (now == 0) now = J[i];
		else if (now != J[i]&&J[i]!=0) {
			now = 0;
			ans += 1;
		}
	}
		cout << ans << endl;
		return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
ll power(ll x,ll y,ll p) 
{ 
    ll res=1;  
    x=x%p;
    while (y > 0) 
    { 
        if(y&1) 
            res=(res*x)%p; 
        y=y>>1;
        x=(x*x)%p;   
    } 
    return res; 
}
const ll L = 1e5 + 5;
ll arr[L];
ll dp[L];
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll i,j,n,k;
	cin >> n >> k;
	for(i=0;i<n;i++)
		cin >> arr[i];
	for(i=1;i<n;i++)
	{
		dp[i] = dp[i-1] + abs(arr[i] - arr[i-1]);
		for(j=2;j<=k;j++)
		{
			if(i-j>=0)
				dp[i] = min(dp[i-j] + abs(arr[i] - arr[i-j]),dp[i]);
			else
				break;
		}
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1792
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
 public static void main (String[] args) throws java.lang.Exception
 {
  InputStreamReader is = new InputStreamReader(System.in);
                BufferedReader br = new BufferedReader(is);
  int su = Integer.parseInt(br.readLine());//秒入力
  int h = su / 3600;
  int m = (su % 3600) / 60;
  int s = su - (3600 * h + m * 60);
  System.out.println(h+":"+m+":"+s);
 }
}


Measured memory_bytes: 24424
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    
    std::vector<long long> v(n);
    int cnt = 0;
    long long min_element = LONG_MAX;
    long long sum = 0;
    for(int i=0; i<n; i++){
        long long c;
        cin >> c;
        sum += abs(c);
        min_element = min(min_element, abs(c));
        if (c < 0)cnt++;
    }

    if (cnt % 2 == 1){
        sum -= 2 * min_element;
    }
    
    cout << sum <<endl;
    
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; int K;
    cin >> S >> K;
    int ans1 = 0, ans2 = 0, ans3 = 0;
    string SS = S + S;
    string SSS = S + S + S;
    rep(i, S.length() - 1) {
        if (S[i] == S[i + 1]) {ans1++; S[i + 1] = '0';}
    }
    rep(i, SS.length() - 1) {
        if (SS[i] == SS[i + 1]) {ans2++; SS[i + 1] = '0';}
    }
    rep(i, SSS.length() - 1) {
        if (SSS[i] == SSS[i + 1]) {ans3++; SSS[i + 1] = '0';}
    }
    int increase = ans2 - ans1;
    int increase2 = ans3 - ans1;
    if (increase2 != increase * 2) {
        //cout << ans1 << " " << increase << " " << increase2 << endl;
        
        cout << ans1 + increase * (K / 2) + (ans3 - ans2) * ((K - 1)/ 2) << endl;
        return 0;
    }
    //assert(increase2 == increase * 2);
    cout << ans1  + increase * (K - 1) << endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

def pow(N,R,mod):
    ans = 1
    i = 0
    while((R>>i)>0):
        if (R>>i)&1:
            ans *= N
            ans %= mod
        N = (N*N)%mod
        i += 1
    return ans%mod


def main():
    N,K = map(int,input().split())
    li = [0 for _ in range(K)]

    mod = 10**9+7
    ans = 0
    for i in range(K,0,-1):
        mm = K//i
        mm = pow(mm,N,mod)

        for j in range(2,(K//i)+1):
            mm -= li[i*j-1]    
        li[i-1] = mm


        ans += (i*mm)%mod
        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()

    



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

using namespace std;

bool p[2000001];
int pr[2000001];

int main()
{
    p[0] = p[1] = 1;
    for (int i = 4; i <= 2000000; i += 2) p[i] = 1;
    
    
    int ind = 0;
    pr[ind++] = 2;
    for (int i = 3; i * i <= 2000000; i += 2){
        if (!p[i]){
            for (int j = 3 * i; j <= 2000000; j += 2 * i) p[j] = 1;
        }
    }
    for (int i = 3; i <= 2000000; i++) if (!p[i]) pr[ind++] = i;
    
    int n;
    while (scanf("%d", &n) && n){
        if (binary_search(pr, pr + 100000, n) == 1) printf("0\n");
        else printf("%d\n", *upper_bound(pr, pr + 100000, n) - *(lower_bound(pr, pr + 100000, n) - 1));
    }
    
    return (0);
}

Measured memory_bytes: 5404
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	char buf[2000];
	int a,b,c;

	while(fgets(buf,sizeof(buf),stdin)!=NULL){
		c=1;
		a=atoi(strtok(buf," ")); b=atoi(strtok(NULL,"\n"));
		a+=b; while(a/=10) c++;

		cout<<c<<endl;

	}

}

Measured memory_bytes: 0
n, c = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(n)]

re_lst = []
for i in reversed(range(n)):
    re_lst.append([abs(c-lst[i][0]), lst[i][1]])

r_accum = []
s = 0
for i in range(n):
    s += lst[i][1]
    r_accum.append(s)

l_accum = []
s = 0
for i in range(n):
    s += re_lst[i][1]
    l_accum.append(s)

r_max = 0
r_max_lst = []
for i in range(n):
    r_max = max(r_max, r_accum[i] - lst[i][0])
    r_max_lst.append(r_max)
    
l_max = 0
l_max_lst = []
for i in range(n):
    l_max = max(l_max, l_accum[i] - re_lst[i][0])
    l_max_lst.append(l_max)

rd_max = 0
for i in range(n-1):
    pt = r_accum[i] - 2*lst[i][0]
    pt += l_max_lst[(n-1)-i-1]
    if pt > rd_max:
        rd_max = pt
            

ld_max = 0
for i in range(n-1):
    pt = l_accum[i] - 2*re_lst[i][0]
    pt += r_max_lst[(n-1)-i-1]
    if pt > ld_max:
        ld_max = pt

print(max(r_max, l_max, rd_max, ld_max))

Measured memory_bytes: 55156
N = int(input())
A = list(map(int, input().split()))
k = 'APPROVED'
for i in A:
  if i % 2 == 0:
    if i % 3 == 0:
      pass
    elif i % 5 == 0:
      pass
    else:
      k = 'DENIED'
print(k)

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

using namespace std;
typedef long long ll;
//ループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//コンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    string s;
    int k;
    cin >> k >> s;
    string ans = "";

    if((int)s.size()<=k) cout << s;
    else {
        REP(i,k) ans += s.at(i);
        ans += "...";
        cout << ans;
    }
}

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

int main (){
    int a, b, c,max=0, min =100;
    cin >> a >> b >> c;
    int array[3]= {a,b,c};
    for(int i=0; i <3; i++){
        if(array[i]>=max){
            max = array[i];
        }
        if(array[i]<=min){
            min = array[i];
        }
    }
    cout << max - min;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define el '\n'
typedef long long ll;
typedef pair<ll, ll> pii;
ll ar[100005];
pii chg[100005];

bool cmp(pii a, pii b) {
  if (a.second == b.second) return a.first > b.first;
  return a.second > b.second;
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  sort(ar, ar+n, greater<int>());
  for (int i = 0; i < m; i++) {
    cin >> chg[i].first >> chg[i].second;
  }
  sort(chg, chg+m, cmp);
  ll sum = 0;
  int en = n-1, lo, hi, mid, best;
  for (int i = 0; i < m; i++) {
    best = -1;
    lo = 0, hi = en;
    while (lo <= hi) {
      mid = (lo + hi) /  2;
      if (ar[mid] > chg[i].second) {
        lo = mid + 1;
      } else {
        best = mid;
        hi = mid-1;
      }
    }
    if (best == -1) {
      break;
    } else {
      sum += min(chg[i].first, (en - best + 1LL)) * chg[i].second;
      if (chg[i].first >= en - best + 1) {
        en = best-1;
      } else {
        en = best - 1 + (en - best + 1 - chg[i].first);
      }
    }
  }
  for (int i = en; i >= 0; i--) {
    sum += ar[i];
  }
  cout << sum << el;
  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
	int in;
	while(cin>>in,in){
	int out=0;
	loop(i,1,in){
		int sum=0;
		loop(j,i,in+1){
			sum+=j;
			if(sum==in){out++;break;}
			else if(j>in)break;
		}
	}
	cout<<out<<endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <list>
using namespace std;
class NewList: private vector<list<int> >
{
public:

	NewList(int n): vector<list<int> >(n) {}

	void insert(int t, int x)
	{
		at(t).push_back(x);
	}

	void dump(int t)
	{
		if (!at(t).empty())
		{
			list<int>::iterator iter = at(t).begin();
			while (1)
			{
				cout << *iter;
				if (++iter == at(t).end())
				{
					cout << endl;
					return;
				}
				else
				{
					cout << " ";
				}
			}
		}
		else
		{
			cout << endl;
		}
	}

	void splice(int s, int t)
	{
		list<int>::iterator iter = at(t).end();
		at(t).splice(iter, at(s));
	}

};

int main()
{
	int n;
	cin >> n;
	NewList a(n);
	cin >> n;
	for (int i=0; i<n; ++i)
	{
		int c;
		cin >> c;
		if (c == 0)
		{
			int t, x;
			cin >> t >> x;
			a.insert(t, x);
		}
		else if (c == 1)
		{
			int t;
			cin >> t;
			a.dump(t);
		}
		else
		{
			int s, t;
			cin >> s >> t;
			a.splice(s, t);
		}
	}
	return 0;
}




Measured memory_bytes: 18716
X = int(input())
for A in range(1000):
  for B in range(-1000,1000):
    if A ** 5 - B ** 5 == X:
    #if (A ** 4) + B * (A ** 3) + (B ** 2) * (A ** 2) + (B ** 3) * A + (B ** 4) == int(X / (A-B)):
      print(A,B)
      exit(0)

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll nCrmod(ll n,ll r){ll x=1,y=1; rep(i,r){x=x*(n-i)%mod; y=y*(i+1)%mod;} return x*powmod(y,mod-2)%mod;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n;
	cin >> n;
	vs ans(n);
	rep(i,n){
		vll a(3);
		rep(j,3) cin >> a[j];
		sort(all(a));
		if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2]) ans[i]="YES";
		else ans[i]="NO";
	}
	for(auto&& e:ans) cout << e << endl;
	return 0;
}


Measured memory_bytes: 3232
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

int v[100010];
map<int,int> q;

int main()
{
    //freopen("file.in","r",stdin);
    //freopen("file.out","w",stdout);
    int n,k,maxx=0;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&v[i]);
        q[v[i]]==1;
        maxx=max(maxx,v[i]);
    }
    if(k>maxx) {printf("IMPOSSIBLE");return 0;}
    for(int i=1;i<=n;i++)
        if(v[i]==k) {printf("POSSIBLE");return 0;}
    int a,b=v[1];
    for(int i=2;i<=n;i++)
    {
        a=b;
        b=v[i];
        while(1)
        {
            int r=a%b;
            if(r==0) break;
            a=b;
            b=r;
        }
    }
    if(k%b==0) printf("POSSIBLE");
    else printf("IMPOSSIBLE");
}


Measured memory_bytes: 5376
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

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

ll H,W;
vector<vector<char>> vec;


void solve() {
	queue<pair<int, int>> Q;

	cin >> H >> W;
	vec.resize(H, vector<char>(W));

	vector<vector<int>> check(H, vector<int>(W, INT_MAX));

	rep(j, H) rep(i, W) {
		cin >> vec[j][i];
		if (vec[j][i] == '#') {
			Q.push(make_pair(j, i));
			check[j][i] = 0;
		}
	}

	int ans = 0;

	while (Q.size() != 0) {

		pair<int, int> P = Q.front();
		Q.pop();

		pair<int, int> tmp = make_pair(P.first+1, P.second);
		if (tmp.first >= 0 && tmp.first < H && tmp.second >= 0 && tmp.second < W) {
			if (check[tmp.first][tmp.second] > check[P.first][P.second] + 1) {

				check[tmp.first][tmp.second] = check[P.first][P.second] + 1;
				Q.push(make_pair(tmp.first, tmp.second));

			}
		}

		tmp = make_pair(P.first - 1, P.second);
		if (tmp.first >= 0 && tmp.first < H && tmp.second >= 0 && tmp.second < W) {
			if (check[tmp.first][tmp.second] > check[P.first][P.second] + 1) {

				check[tmp.first][tmp.second] = check[P.first][P.second] + 1;
				Q.push(make_pair(tmp.first, tmp.second));

			}
		}

		tmp = make_pair(P.first, P.second + 1);
		if (tmp.first >= 0 && tmp.first < H && tmp.second >= 0 && tmp.second < W) {
			if (check[tmp.first][tmp.second] > check[P.first][P.second] + 1) {

				check[tmp.first][tmp.second] = check[P.first][P.second] + 1;
				Q.push(make_pair(tmp.first, tmp.second));

			}
		}

		tmp = make_pair(P.first, P.second - 1);
		if (tmp.first >= 0 && tmp.first < H && tmp.second >= 0 && tmp.second < W) {
			if (check[tmp.first][tmp.second] > check[P.first][P.second] + 1) {

				check[tmp.first][tmp.second] = check[P.first][P.second] + 1;
				Q.push(make_pair(tmp.first, tmp.second));

			}
		}

	}

	rep(i, H) {
		rep(j, W) {
			ans = max(ans, check[i][j]);
		}
	}

	cout << ans;


	return;
}

int main() {
	solve();
	cout << endl;
	return 0;
}


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

stack<int>B;

void func(int x, int n) {
    for (int i = 0; i < n; i++) {
        B.push(x%2);
        x = x / 2;
    }
}

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int>C(N);
    vector<vector<int>>A(N, vector<int>(M));
    for (int i = 0; i < N; i++) {
        cin >> C.at(i);
        for (int j = 0; j < M; j++) {
            cin >> A.at(i).at(j);
        }
    }
    vector<int>s(M);
    int c, ans = -1;
    bool check;
    for (int i = 0; i < pow(2, N); i++) {
        for (int j = 0; j < M; j++) {
            s.at(j) = 0;
        }
        c = 0;
        check = true;
        func(i, N);
        for (int j = 0; j < N; j++) {
            if (B.top() == 0) {
                for (int k = 0; k < M; k++) {
                    s.at(k) += A.at(j).at(k);
                }
                c += C.at(j);
            }
            B.pop();
        }
        for (int j = 0; j < M; j++) {
            if (s.at(j) < X) {
                check = false;
                break;
            }
        }
        if (check) {
            if (ans != -1) {
                ans = min(ans, c);
            }
            else {
                ans = c;
            }
        }
    }
    cout << ans;
}

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

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

using namespace std;

int main(){
  string s;cin>>s;
  ll result=0, c=0;
  rep(i, s.size()){
    if(s[i]=='B')c++;
    else result+=c;
  }
  cout<<result;
  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    double r = sc.nextDouble();
    double pi = Math.PI;
    double area = r*r*pi;
    double length = 2*r*pi;
    System.out.printf("%f %f",area,length);
    sc.close();
  }
}


Measured memory_bytes: 28248
n = int(input())
a = list(map(int,input().split()))
sum = 1
if 0 in a:
    sum = 0
    print(sum)
    exit()
for i in range(n):
    if sum == 0:
        break
    sum = sum * a[i]
    if sum > 10**18:
        sum = -1
        break
print(sum)



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

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
int N ;
    cin >> N ;
int minimum=1000;
  
  for (int i=1;i<=N/2;i++){
   int X=findSumOfDigits(i)+findSumOfDigits(N-i);
   if (X<minimum){
   minimum=X ;
   }
  }
  cout << minimum << endl;  
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

		List<Integer> list = divList(m);
		Collections.reverse(list);
		for (long ans : list) {
			if (ans * n <= m) {
				System.out.println(ans);
				return;
			}
		}
	}

	static List<Integer> divList(int n) {
		List<Integer> list = new ArrayList<>();
		int end = (int) Math.sqrt(n);
		for (int i = 1; i <= end; i++) {
			if (n % i == 0) {
				list.add(i);
			}
		}
		int i = end * end == n ? list.size() - 2 : list.size() - 1;
		for ( ; i >= 0; i--) {
			list.add(n / list.get(i));
		}
		return list;
	}
}


Measured memory_bytes: 22740
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
int a, b;
void solve() {
    cin >> a >> b;
    cout << max(max(a + a - 1, b + b - 1), a + b) << endl;
    return;
}
//逆元を求める関数
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;
}
int main(int args, char* argv[]) {
    solve();
}

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

int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  
  if (L > R) {
   cout << "Left" << endl;
  }
  else if (L == R) {
    cout << "Balanced" << endl;
  }
  else if ( L < R) {
    cout << "Right" << endl;
  }

}

Measured memory_bytes: 3588
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
//int NUMOFDIV(int n) 素因数分解して+1してかける奴
int NUMOFDIV2(int n) {
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR (int x) {
	if (x ==1)
		return false;
	if (x == 2)
		return true;
	if (x%2==0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
using namespace std;
#pragma endregion
signed main() {
	int N,sum=0,M,p,x;
	cin >> N;
	vector <int> T(N);
	rep(i, N) {
		cin >> T[i];
		sum += T[i];
	}
	cin >> M;
	rep(i, M) {
		cin >> p >> x;
		cout << sum + x - T[p-1]<<endl;
	}
}

Measured memory_bytes: 256
<?php
	list($a, $b, $C) = explode(" ", trim(fgets(STDIN)));
	$h = $b * sin(deg2rad($C));
	echo $a * $h / 2 . "\n";
	echo $a + $b + sqrt($a*$a + $b*$b - 2*$a*$b*cos(deg2rad($C))) . "\n";
	echo $h . "\n";

Measured memory_bytes: 6624
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

N, A = inpl()
X = [int(x) - A for x in input().split()]


DP = [0]*(5001)
DP[2500] = 1

for x in X:
    DP2 = [0]*(5001)
    for i in range(50, 4950):
        DP2[i+x] += DP[i] + DP[i+x]
    DP = DP2

print(DP[2500] - 1)

Measured memory_bytes: 3064
#include<cstdio>
using namespace std;
int main(void){
    int A,B;
    char op;
    scanf("%d %c %d",&A,&op,&B);
    if(op=='+'){
        printf("%d\n",A+B);
    }else{
        printf("%d\n",A-B);
    }
    return 0;
}

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

int caut (int st , int dr,int n)
{
    int mid=(st+dr)/2;
    //cout<<(int)(mid * 1.08)<<endl;
    
    if((int) (mid *1.08 ) == n) return mid;
    if(st>=dr) return 0;
    if((int)(mid *1.08) < n) return caut (mid+1,dr,n);
        else 
        return caut (st,mid,n);
       
}


int main() {
    int n;
    cin>>n;
    int rez= caut(1,50000,n);
    
    if(rez) cout<<rez;
    else cout<<":(";
  
    return 0;
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    ll n; cin >> n;
    ll a, b, ans = INF;
    if(n==0){
        cout << 1 << endl;
        return 0;
    }
    for(a=1;a*a<=n;a++){
        if(n%a!=0) continue;
        ll b = n/a;
        chmin(ans, max((ll)log10(a)+1, (ll)log10(b)+1));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int H, W;
    cin >> H >> W;
    if (H == 0 && W == 0){
      break;
    }
    for (int i = 0; i < H; i++){
      for (int j = 0; j < W; j++){
        cout << '#';
      }
      cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

bool dp[100005];
string table[5]={"dream","dreamer","erase","eraser"};

signed main()
{
    string s; cin>>s;
    int N=s.size();

    s=' '+s; 
    dp[0]=true;
    
    for(int i=1;i<=N-4;i++){
        if(!dp[i-1]) continue;
        REP(j,4){
            int len=table[j].size();
            if(s.substr(i,len)==table[j]){
                dp[i+len-1]=true;
            }
        }
    }
    cout<<(dp[N]? "YES":"NO")<<endl;
    
}


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

int main(){
    int X,A,B;
    string S[3]={"delicious","safe","dangerous"};
    cin>>X>>A>>B;
    if(A>=B){
        cout<<S[0]<<endl;
    }else if(B-A<=X){
        cout<<S[1]<<endl;
    }else{
        cout<<S[2]<<endl;
    }
    return 0;
}

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

using namespace std;

typedef long long LL;

const int N = 110;

int n;
int w[N];

int main()
{
    int mina = 0x3f3f3f3f, l = 0, r = 0;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> w[i];
        l += w[i];
    }

    for(int i = n; i; i--)
    {
        l -= w[i];
        r += w[i];
        mina = min(mina, abs(l - r));
    }

    cout << mina << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;



ll n, k;

struct xyc {
	double x;
	double y;
	double c;
	double cc;
};

vector<xyc> v;

double calc_dist(double x0, double y0, double x1, double y1){
	return sqrt((x0-x1)*(x0-x1) + (y0-y1)*(y0-y1));
}
double calc_dist2(double x0, double y0, double x1, double y1){
	return (x0-x1)*(x0-x1) + (y0-y1)*(y0-y1);
}

double is_possible2( double t, ll k, double x, double y, int i0, int i1 ){
	double tt = t*t;
	for ( int i = 0; i < n; i++ ){
		if ( i == i0 || i == i1 || calc_dist2(v[i].x,v[i].y,x,y) * v[i].cc <= tt )
			if ( --k == 0 ){
				//cout << "possible t=" << t << " (" << x << ", " << y << ")" << endl;
				return true;
			}
	}
	return false;
}


bool is_possible( double t, ll k ){
	for ( int i = 0; i < n; i++ ){
		for ( int j = i+1; j < n; j++ ){
			/*
				calc_dist(P,vi)*ci = t
				calc_dist(P,vj)*cj = t
				となるPを求める
				
				calc_dist(Q,( a,0)) = d0
				calc_dist(Q,(-a,0)) = d1
				とすると、
				  Qx = (d1d1-d0d0)/4a
				  Qy = sqrt(d0d0-(Qx-a)^2) * (1 or -1)
				
				a*a-b*b は (a-b)(a+b) で計算する
			*/
			
			double Ox = (v[i].x+v[j].x)/2;
			double Oy = (v[i].y+v[j].y)/2;
			double a = calc_dist(v[i].x,v[i].y,v[j].x,v[j].y)/2;
			
			double d0 = t/v[i].c;
			double d1 = t/v[j].c;
			double Qx = (d1+d0)*(d1-d0)/(a*4); // (d1*d1-d0*d0)/(a*4);
			double tmp = (d0+(Qx-a))*(d0-(Qx-a)); // d0*d0-(Qx-a)*(Qx-a);
			if ( tmp < 0.0 ){
				//cout << "vi- (" << v[i].x << "," << v[i].y << ")" << endl;
				//cout << "vj- (" << v[j].x << "," << v[j].y << ")" << endl;
				//if ( Qx > a ){ 
					if ( is_possible2(t, k, v[i].x, v[i].y, i, i) )
						return true;
					if ( is_possible2(t, k, v[j].x, v[j].y, j, j) )
						return true;
				//}
			}
			else {
				
				double nx = v[i].x-Ox;
				double ny = v[i].y-Oy;
				double nn = 1.0/sqrt(nx*nx+ny*ny);
				nx *= nn;
				ny *= nn;
				
				double Qy = sqrt(tmp);
				double Px1 = Ox + nx*Qx + ny*Qy;
				double Py1 = Oy + ny*Qx - nx*Qy;
				double Px2 = Ox + nx*Qx - ny*Qy;
				double Py2 = Oy + ny*Qx + nx*Qy;
				
				//cout << "vi (" << v[i].x << "," << v[i].y << ")" << endl;
				//cout << "vj (" << v[j].x << "," << v[j].y << ")" << endl;
				//cout << "P1 (" << Px1 << "," << Py1 << ")" << (calc_dist(Px1,Py1,v[i].x,v[i].y)*v[i].c) << "/" << (calc_dist(Px1,Py1,v[j].x,v[j].y)*v[j].c) << endl;
				//cout << "P2 (" << Px2 << "," << Py2 << ")" << (calc_dist(Px2,Py2,v[i].x,v[i].y)*v[i].c) << "/" << (calc_dist(Px2,Py2,v[j].x,v[j].y)*v[j].c) << endl;
				
				if ( is_possible2(t,k,Px1,Py1, i, j) )
					return true;
				if ( is_possible2(t,k,Px2,Py2, i, j) )
					return true;
			}
		}
	}
	//cout << "impossible " << t << endl;
	return false;
}


int main(){
	cin >> n >> k;
	
	v.resize(n);
	for ( int i = 0; i < n; i++ ){
		cin >> v[i].x >> v[i].y >> v[i].c;
		v[i].cc = v[i].c*v[i].c;
	}
	
	if ( k == 1 ){
		cout << 0 << endl;
		return 0;
	}
	
	double tmin = 0.0;
	double tmax = 100.0 * 1000.0 * 1.4143;
	
	cout << setprecision(12);
	while ( tmax - tmin > 0.00000001 ){
		double t = (tmax+tmin)/2.0;
		
		if ( is_possible(t,k) )
			tmax = t;
		else
			tmin = t;
	}
	
	cout << tmin << endl;
	
	return 0;
}



Measured memory_bytes: 3848
N=int(input())
F=[tuple(map(int,input().split())) for _ in range(N)]
P=[tuple(map(int,input().split())) for _ in range(N)]

ans=-(10**7*N)
#営業パターンを10bitの整数であらわす(0はない)
for o in range(1,1<<10):
    #同時に営業する時間帯数のリスト
    C=[0]*N
    for t in range(10):
        #時間帯tに営業するか
        if o&1:
            for i in range(N):
                if F[i][t]==1:
                    C[i]+=1
        o>>=1
    #利益を計算
    p=0
    for i in range(N):
        p+=P[i][C[i]]
    ans=max(ans,p)

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>

int main(){
    std::string S;
    std::cin >> S;
    std::size_t n = S.size() - 1;

    long long sum = 0;
    for(int bit = 0; bit < (1 << n); bit++){
        int pre = 0;
        // iはiとi + 1の間に+を入れるの意
        for(int i = 0; i < n; i++){
            if(bit & (1 << i)){
                std::string tmp = S.substr(pre, i - pre + 1);
                sum += std::stoll(tmp);
                pre = i + 1;
            }
        }
        std::string tmp = S.substr(pre, n - pre + 1);
        sum += std::stoll(tmp);
    }

    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 256
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

string query(int i) {
	cout << i << endl;
	string res;
	cin >> res;
	if (res == "Vacant") exit(0);
	return res;
}

int main() {
	int L = 0, R;
	cin >> R;
	
	string sL = query(0), sR;
	while (1) {
		int N = R - L;
		sR = query(L + N/2);
		
		if ((N / 2) % 2) {
			if (sL == sR) {
				R = L + N/2 + 1;				
			} else {
				L = L + N/2;
				sL = sR;
			}
		} else {
			if (sL == sR) {
				L = L + N/2;
				sL = sR;
			} else {
				R = L + N/2 + 1;
			}
			
		}
	}
}
//--------------8---------------->> coding space <<-----------------8-------------//


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

int main() {
  int a, total = 0;
  rep(i, 3) {
    cin >> a;
    total += a;
  }
  cout << (total >= 22 ? "bust" : "win") << endl;
  return 0;
}


Measured memory_bytes: 3616
N, K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
A.sort(reverse=True)
F.sort()
U = 10**12
L = -1
while U - L > 1:
    x = (U+L)//2
    cnt = 0
    for i in range(N):
        if x//F[i] < A[i]:
            cnt += A[i] - x//F[i]
    if cnt > K:
        L = x
    else:
        U = x
print(U)

Measured memory_bytes: 119500
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        n:usize,
        a:[i64;n],
        uv:[(Usize1,Usize1);n-1],
    }
    let mut to = vec![vec![]; n];
    for &(u, v) in uv.iter() {
        to[u].push(v);
        to[v].push(u);
    }
    let mut dp = vec![INF; n + 1];
    dp[0] = -INF;
    let mut ans = vec![0; n];
    let mut g = G {
        n: n,
        to: to,
        a: a,
        dp: dp,
        ans: ans,
    };
    g.dfs(0, !0);
    for &a in g.ans.iter() {
        println!("{}", a);
    }
}
const INF: i64 = 1 << 60;

struct G {
    n: usize,
    to: Vec<Vec<usize>>,
    a: Vec<i64>,
    dp: Vec<i64>,
    ans: Vec<usize>,
}
impl G {
    fn dfs(&mut self, v: usize, p: usize) {
        let i = self.dp.lower_bound(&self.a[v]);
        let old = self.dp[i];
        self.dp[i] = self.a[v];
        self.ans[v] = i;
        if p != !0 {
            let t = self.ans[p];
            self.ans[v].chmax(t);
        }
        for nx in self.to[v].clone().iter() {
            if *nx == p {
                continue;
            }
            self.dfs(*nx, v);
        }
        self.dp[i] = old;
    }
}
trait ChMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}
impl<T: PartialOrd> ChMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
pub trait BinarySearch<T> {
    fn lower_bound_by<F: Fn(&T) -> bool>(&self, f: F) -> usize;
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}
impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound_by<F: Fn(&T) -> bool>(&self, f: F) -> usize {
        let mut ng = -1;
        let mut ok = self.len() as i64;
        while (ok as i32 - ng as i32).abs() > 1 {
            let mid = (ok + ng) / 2;
            if f(&self[mid as usize]) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        ok as usize
    }
    fn lower_bound(&self, x: &T) -> usize {
        self.lower_bound_by(|y| y >= x)
    }
    fn upper_bound(&self, x: &T) -> usize {
        self.lower_bound_by(|y| y > x)
    }
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void)
{
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int hour=h2-h1;
    int min=m2-m1;
    int time=hour*60+min;
    cout<<time-k<<endl;  
    return 0;
}

Measured memory_bytes: 3624
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<cstdint>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
ll longinf=(1ll<<60);
int main(){
      int K,S;
      cin>>K>>S;
      int ans=0;
      rep0(x,K+1){
            rep0(y,K+1){
                  if(S-x-y>=0&&S-x-y<=K) ans++;
            }
      }
      cout<<ans<<endl;
      return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <algorithm>
#define MOD 1000000007
#define forn(a, n) for(int a = 0; a<(int) (n); ++a)
#define dforn(a, n) for(int a = (n)-1; a>=0; --a)
#define forall(a, all) for(__typeof(all.begin()) a = all.begin(); a != all.end(); ++a)
#define EPS 0.000000000001
using namespace std;
typedef long long tint;
typedef pair<tint, tint> pii;
typedef vector<tint> vi;
typedef vector<vi> vvi;

string ans = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int nq = 0;
int editdist(string a) {
	int voy = 0;
	forn(i, ans.size()) {
		if(voy < (int) a.size()) {
			if(a[voy] == ans[i]) voy++;
		}
	}
	cout << (int) ans.size() - voy << endl;
	cout << voy << " " << a.size() << endl;
	nq++;
	return (int) max(a.size(), ans.size()) - voy;
}


int main()
{
	string caras;
	for(char c = 'a'; c <= 'z'; c++) {
		caras+=c;
	}
	for(char c = 'A'; c <= 'Z'; c++) {
		caras+=c;
	}
	for(char c = '0'; c <= '9'; c++) {
		caras+=c;
	}
	
	int n = caras.size();
	
	vector<int> tot(n, 0);
	vector<int> inans(n, 0);
	int L = 0;
	forn(i, n) {
		string lcaras = "";
		forn(j, 128) lcaras += caras[i];
		cout << "? " << lcaras << endl << flush;
		cin >> inans[i];
		//	inans[i] = editdist(lcaras);
		tot[i] = 128-inans[i];
		L += tot[i];
	}
	
	priority_queue<pair<int, string>> subs;
	forn(i, n) {
		if(tot[i] > 0) {
			string tots = "";
			forn(j, tot[i])  tots += caras[i];
			subs.push({L-(tot[i]), tots});
		}
	}
	
	while(subs.size() > 1) {
		pair<int, string> pa = subs.top();
		subs.pop();
		pair<int, string> pb = subs.top();
		subs.pop();
		string a = pa.second, b = pb.second;
		int na = a.size(), nb = b.size();
		string pref = "";
		int voya = 0, voyb = 0;
		//cout << "MERGEO " << a << " " << b << endl;
		while(voyb < nb && voya < na) {
			//cout << voya << " " << voyb << " " << pref << " " << a << " " << b << endl;
			string q = pref;
			q += b[voyb];
			for(int i = voya; i<na; i++) q += a[i];
			cout << "? " << q << endl << flush;
			int ans, qs = q.size();
			cin >> ans;
			//ans = editdist(q);
			if(ans == L-qs) {
				pref += b[voyb++];
			} else {
				pref += a[voya++];
			}
		}
		//return 0;
		for(int i = voya; i<na; i++) pref += a[i];
		for(int i = voyb; i<nb; i++) pref += b[i];
		//cout << "METO NUEVA " << pref << endl;
		subs.push({L-((int)pref.size()), pref});
	}
	
	cout << "! " << subs.top().second << endl << flush;
	//cout << nq << endl;
}


Measured memory_bytes: 3772
from collections import defaultdict

N, K = map(int, input().strip().split(" "))

d = defaultdict(int)

for i in [int(i) for i in input().strip().split(" ")]:
    d[i] += 1

if len(d.keys()) <= K:
    print(0)
else:
    cnt = len(d.keys()) - K
    n = 0
    for v in sorted(d.values())[:cnt]:
        n += v
    print(n)


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

const long long MOD = 1000000007;

const int MAX = 5100000;
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;
    }
}

ll f(int i, int j){
    return (fac[i+j] * finv[i] % MOD * finv[j] % MOD) % MOD;
}

void solve(std::vector<long long> r, std::vector<long long> c){
    COMinit();
    ll ans = 0;
    for(int i = r[0];i <= r[1];i++){
        ans += f(i+1, c[1])+MOD - f(i+1, c[0]-1);
        //if(i <= 20)cout<<f(i+1, c[1])<<" "<< f(i+1, c[1])<<endl;
        ans %= MOD;
    }
    cout<<ans%MOD<<endl;
}

int main(){
    std::vector<long long> r(2);
    std::vector<long long> c(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&r[i]);
        scanf("%lld",&c[i]);
    }
    solve(std::move(r), std::move(c));
    return 0;
}


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i, 0, n)cin >> a[i];
    ll ans=0;
    if(n==1){
        cout << a[0]/2 << endl;
        return 0;
    }
    rep(i, 1, n){
        ll x = (a[i]+a[i-1])/2;
        ans += x;
        if(a[i]!=0){
            a[i] = (a[i]+a[i-1])%2;
            a[i-1]=0;
        }
        //cout << ans << " ";
    }
    //rep(i, 0, n)cout << a[i] << " ";
    //cout << endl;
    cout << ans << endl;
}

Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <math.h>
#include <cstdio>

int main(int argc, char const *argv[]) {

        int N,K;
        std::cin >> N >> K;
        printf("%d\n", (int)(K * pow(K-1,N-1)) );
        return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  if (N * A > B){
    cout << B << endl;
  }
  else if (N * A < B){
    cout << N * A << endl;
  }
  else{
    cout << B << endl;
  }
}

Measured memory_bytes: 256