akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<numeric>
#include<limits.h>
#include<utility>
#include<cstdlib>
#include<bitset>
#define LP(i,n) for(int i=0;i<n;i++)
#define LPIN(n,a) for(int i=0;i<n;i++)cin >> a[i]
using namespace std;

int main(){
int a,b;
cin >> a >> b;
cout << max({a+b,a-b,a*b}) << endl;
return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,LL>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL V<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define SE second
#define PI acos(-1.00)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define edl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V<LL>v,w,zz;
map<LL,LL>ww,u,st;
V<LL>uuu[500005];
V<pair<LL,LL> >uu;
map<pair<LL,LL>,LL> vo,vu,uh,ve;
set<LL>uo;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r;
    string a,b,c;
    DL x,y,d,e,f,g,h;
    char ch;
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
//    cin>>tt;
    while(tt--)
    {
        cin>>n>>a;
        k=0;
        for(i=0;a[i];i++)
        {
            if(a[i]!='.')
            {
                k=(k*10)+(a[i]-'0');
            }
        }
        n*=k;
        cout<<n/100<<endl;
    }
    return 0;
}


Measured memory_bytes: 15376
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, A: "List[int]"):

    for k in range(K):
        B = [0] * N

        for i in range(N):
            l = max(0, i - A[i])
            r = i + A[i]

            B[l] += 1
            if r + 1 < N:
                B[r + 1] -= 1

        for i in range(1, N):
            B[i] += B[i - 1]

        A = B.copy()
        if sum(A) == N*N:
            break
    print(*A)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)


if __name__ == "__main__":
    main()


Measured memory_bytes: 158912
#include<stdio.h>

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

int main(void){
	while(1){
		int n;
		scanf("%d",&n);
		if(n==0){
			break;
		}
		int sonzai[6][6][6][6][6][6];
		rep(a,6){
			rep(b,6){
				rep(c,6){
					rep(d,6){
						rep(e,6){
							rep(f,6){
								sonzai[a][b][c][d][e][f]=0;
							}
						}
					}
				}
			}
		}
		
		int now[6];
		for(int q=0;q<n;q++){
			for(int i=0;i<6;i++){
				char str[10];
				scanf("%s",str);
				switch(str[0]){
					case 'C':now[i]=0;break;
					case 'Y':now[i]=1;break;
					case 'R':now[i]=2;break;
					case 'M':now[i]=3;break;
					case 'G':now[i]=4;break;
					case 'B':now[i]=5;break;
				}
			}
			int temp;
			for(int i=0;i<4;i++){
				for(int j=0;j<4;j++){
					
					sonzai[now[0]][now[1]][now[2]][now[3]][now[4]][now[5]]=1;
					
					temp=now[2];
					now[2]=now[4];
					now[4]=now[3];
					now[3]=now[1];
					now[1]=temp;
				}
				temp=now[0];
				now[0]=now[2];
				now[2]=now[5];
				now[5]=now[3];
				now[3]=temp;
			}
			temp=now[0];
			now[0]=now[1];
			now[1]=now[5];
			now[5]=now[4];
			now[4]=temp;
			
			for(int j=0;j<4;j++){
					
				sonzai[now[0]][now[1]][now[2]][now[3]][now[4]][now[5]]=1;
				
				temp=now[2];
				now[2]=now[4];
				now[4]=now[3];
				now[3]=now[1];
				now[1]=temp;
			}
			
			temp=now[0];
			now[0]=now[1];
			now[1]=now[5];
			now[5]=now[4];
			now[4]=temp;
			temp=now[0];
			now[0]=now[1];
			now[1]=now[5];
			now[5]=now[4];
			now[4]=temp;
			
			for(int j=0;j<4;j++){
					
				sonzai[now[0]][now[1]][now[2]][now[3]][now[4]][now[5]]=1;
				
				temp=now[2];
				now[2]=now[4];
				now[4]=now[3];
				now[3]=now[1];
				now[1]=temp;
			}
		}
		int cont=0;
		rep(a,6){
			rep(b,6){
				rep(c,6){
					rep(d,6){
						rep(e,6){
							rep(f,6){
								cont+=sonzai[a][b][c][d][e][f];
							}
						}
					}
				}
			}
		}
		printf("%d\n",n-cont/24);
	}
	return 0;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> v(N, vector<int>(M, 0)), loc(N, vector<int>(M+1, 0));
	vector<vector<bool>> s(N, vector<bool>(M, 0));
	for(int i=0; i<N; ++i){
	    for(int j=0; j<M; ++j){
	        cin >> v[i][j];
	        loc[i][v[i][j]]=j;
	    }
	}
	int ans=N;
	for(int i=0; i<M; ++i){
	    vector<int> cnt(M+1, 0);
	    for(int j=0; j<N; ++j){
	        int a=0;
	        while(s[j][a]) ++a;
	        ++cnt[v[j][a]];
	    }
	    int mx=0;
	    for(int j=1; j<=M; ++j){
	        if(cnt[mx]<cnt[j]) mx=j;
	    }
	    ans=min(ans, cnt[mx]);
	    for(int j=0; j<N; ++j) s[j][loc[j][mx]]=1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int N; cin >> N;
    vector<Int> A(N+1); rep(i, 0, N+1) cin >> A[i];
    vector<Int> B(N); rep(i, 0, N) cin >> B[i];
    Int res = 0;

    rep(i, 0, N) {
        Int defeated = min(A[i], B[i]);
        res += defeated;
        B[i] -= defeated;

        defeated = min(A[i+1], B[i]);
        res += defeated;
        A[i+1] -= defeated;
    }

    cout << res << endl;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <stack>

using namespace std;

int main() {
    stack<int> s1;
    stack<pair<int, int> > s2;
    stack<pair<int, int> > s3; // 表示用
    char c;
    int sum = 0;
    int pos = 0;
    while (1) {
        scanf("%c", &c);
        if (c == '\\') {
            s1.push(pos);
        } else if (c == '_') {

        } else if (c == '/') {
            if (!s1.empty()) {
                int d = pos - s1.top();
                int area = d;
                sum += d;
                while (!s2.empty() && s2.top().first > s1.top()) {
                    area += s2.top().second;
                    s2.pop();
                }
                s2.push(make_pair(s1.top(), area));
                s1.pop();
            }
        } else {
            break;
        }
        pos++;

    }
    printf("%d\n", sum);
    printf("%lu", s2.size());
    while (!s2.empty()) {
        s3.push(s2.top());
        s2.pop();
    }
    while (!s3.empty()) {
        printf(" %d", s3.top().second);
        s3.pop();
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2752
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int x, y;
	scanf("%d%d", &x, &y);
	int ans = 0;
	if (x <= 3) ans += (4 - x) * 100000;
	if (y <= 3) ans += (4 - y) * 100000;
	if (x == 1 && y == 1) ans += 400000;
	printf("%d\n", ans);
}


Measured memory_bytes: 256
x = int(input())

oni = 0
while 1:
	if (1+oni)*100 == x:
		print(1)
		exit(0)
	elif (1+oni)*100 > x:
		break
	else:
		oni += 1
if oni == 0:
	print(0)
	exit(0)
sa = x - oni*100
cnt = 0
for i in range(5):
	j = 5 - i
	while sa >= j:
		sa -= j
		cnt += 1
	if sa == 0:
		break
if cnt <= oni and sa == 0:
	print(1)
else:
	print(0)


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

typedef long long i64;

const i64 MOD = 1e9 + 7;

template<class T>
T modularExp(T base, i64 exp)
{
	T answer(1);

	while (exp)
	{
		if (exp & 1)
			answer = answer * base % MOD;
		base = base * base % MOD;
		exp = exp >> 1;
	}
	return answer;
}

struct Matrix
{
	i64 data[4][4];

	Matrix(i64 x)	// Load a filled matrix
	{
		memset(data, 0x00, sizeof data);
		for (int i = 0; i < 4; i++)
			data[i][i] = x;
	}

	i64 * operator [](unsigned index)
	{
		return this->data[index];
	}

	Matrix operator *(const Matrix & rhs) const
	{
		Matrix result(0);

		for (int k = 0; k < 3; k++)
			for (int i = 0; i < 3; i++)
				for (int j = 0; j < 3; j++)
					result[i][j] = (result[i][j]
							+ data[i][k] * rhs.data[k][j] % MOD) % MOD;
		return result;
	}

	Matrix operator %(i64 modular)
	{
		return (*this);
	}
};

char mp[1005][1005];
i64 N, M, K;
i64 blkCnt, adjCnt;
i64 upDown, leftRight;

int solve()
{
	if (K <= 1)
		return 1;
	if (upDown && leftRight)
		return 1;
	if (!upDown && !leftRight)
		return modularExp(blkCnt, K - 1);
	if (!upDown)
		swap(upDown, leftRight);

	Matrix x(0);
	x[0][0] = x[1][1] = blkCnt;
	x[1][2] = 1;
	x[2][2] = upDown;

	x = modularExp(x, K - 2);

	i64 V(0), E(0);
	int tmp[3] =
	{ blkCnt, adjCnt, adjCnt * upDown };

	for (int i = 0; i < 3; i++)
		V = (V + x[0][i] * tmp[i] % MOD) % MOD;
	for (int i = 0; i < 3; i++)
		E = (E + x[1][i] * tmp[i] % MOD) % MOD;

	return (V - E + MOD) % MOD;
}

void countAdj()
{
	// Count adjacent blocks
	for (int i = 0; i < N; i++)
		leftRight += (mp[i][0] == '#' && mp[i][M - 1] == '#');
	for (int i = 0; i < M; i++)
		upDown += (mp[0][i] == '#' && mp[N - 1][i] == '#');
	// Count total blocks
	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++)
			blkCnt += (mp[i][j] == '#');

	if (upDown)
		for (int i = 0; i < N - 1; i++)
			for (int j = 0; j < M; j++)
				adjCnt += (mp[i][j] == '#' && mp[i + 1][j] == '#');
	else
		for (int i = 0; i < N; i++)
			for (int j = 0; j < M - 1; j++)
				adjCnt += (mp[i][j] == '#' && mp[i][j + 1] == '#');
}

int main()
{
	cin >> N >> M >> K;
	for (int i = 0; i < N; i++)
		cin >> mp[i];
	cerr << "Input Finished !" << endl ;
	countAdj();
	cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String word;
        int count = 0;
        word = in.readLine();
        while (true) {
            String[] text;
            text = in.readLine().split(" ");
            if (text[0].equals("END_OF_TEXT")) {
                break;
            }
            for (String str : text) {
                str = str.toLowerCase();
                if (str.matches(word)) {
                    count++;
                } else {
                    continue;
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 24708
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 200005;
int n, m;
ll k;
ll a[maxn];
ll b[maxn];
ll pref1[maxn];
ll pref2[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> m >> k;
    for(int i=1;i<=n;i++)cin >> a[i];
    for(int i=1;i<=m;i++)cin >> b[i];
    for(int i=1;i<=n;i++)pref1[i] = pref1[i - 1] + a[i];
    for(int i=1;i<=m;i++)pref2[i] = pref2[i - 1] + b[i];
    int rez = 0;
    for(int i=0;i<=n;i++){
        ll kol = pref1[i];
        ll fali = k - kol;
        int l = 1, r = m, ans = 0;
        while(l <= r){
            int mid = (l + r) / 2;
            if(pref2[mid] <= fali){
                l = mid + 1;
                ans = mid;
            }
            else r = mid - 1;
        }
        if(kol <= k)rez = max(rez, i + ans);
    }
//    cout << endl << endl;
    for(int i=0;i<=m;i++){
        ll kol = pref2[i];
        ll fali = k - kol;
//        cout << "kol: " << kol << endl;
//        cout << "fali: " << fali << endl;
        int l = 1, r = n, ans = 0;
        while(l <= r){
            int mid = (l + r) / 2;
            if(pref1[mid] <= fali){
                l = mid + 1;
                ans = mid;
            }
            else r = mid - 1;
        }
//        cout << "ans: " << ans << endl;
        if(kol <= k)rez = max(rez, i + ans);
//        cout << endl;
    }
    cout << rez << endl;
    return 0;
}


Measured memory_bytes: 9852
#include <stdio.h>
#include <stdlib.h>
int c(const void *v1,const void *v2){
    return *(int *)v1-*(int *)v2;
}
int main(void){
    int num,linex[199],liney[199],i,n,d,x,y;
    linex[0]=0,liney[0]=0;
    for(;scanf("%d",&num),num;){
        for(i=0;x=0,y=0,i<num-1;i++){
            scanf("%d %d",&n,&d);
            switch(d){
                case 0:x=-1; break;
                case 1:y=1;  break;
                case 2:x=1;  break;
                case 3:y=-1; break;
            }
            linex[i+1]=linex[n]+x;
            liney[i+1]=liney[n]+y;
        }
        qsort(linex,num,4,c);
        qsort(liney,num,4,c);
        for(x=0,y=0,i=1;i<num;i++){
            if(linex[i]==linex[i-1])
                x++;
            if(liney[i]==liney[i-1])
                y++;
        }
        printf("%d %d\n",num-x,num-y);
    }
    return 0;
}

Measured memory_bytes: 604
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, A, B = map(int, readline().split())
    diff = abs(A-B)
    if diff%2==0:
        print('Alice')
    else:
        print('Borys')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)

// abc110b 方針
// zの全探索

int main() {
  int n,m,X,Y;cin>>n>>m>>X>>Y;
  vector<int> x(n);rep(i,n) cin>>x[i];
  vector<int> y(m);rep(i,m) cin>>y[i];

  FOR(z,X+1,Y+1) {
    bool war = false;
    rep(i,n) if(z<=x[i]) war=true;
    rep(i,m) if(z>y[i]) war=true;
    if(!war) {
      cout << "No War" << endl;
      exit(0);
    }
  }
  cout << "War" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff(i,n) for(i=0;i<n;i++)
#define pb push_back
ll bg =  9982443598893;
ll power(ll x,ll y)
{
    if(y==0)
	    return 1;
	ll d = power(x,y/2);
	ll f = (d*d);
	if(y%2==0)
	  return f;
	else
	  return (f*x);	 	
}
int main()
{
	ll n,k,i;
	cin>>n>>k;
	vector<ll>vec;
	ll arr[n];
	ff(i,n)   
	   cin>>arr[i];
	ll f = (arr[0]-1);
	vec.pb(0);
	set<ll>set1;
	set1.insert(0);
	while(1)
	{
		if(set1.find(f)!=set1.end())
		   break;
		vec.pb(f);
		set1.insert(f);
		f=(arr[f]-1);	
	}
	if(k<vec.size())
	   cout<<vec[k]+1<<endl;
	else
	{
		ll back=0;
		for(i=0;i<vec.size();i++)
		{
			if(vec[i]==f)
			{
			  	back = i;
			  	break;
			}	
		}	
		k = k - back;
		ll n2 = vec.size();
		cout<<vec[back+k%(n2-back)]+1;
	}         
	return 0;
}

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

using namespace std;

#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define mod 1000000007 //998244353
#define mii map<int, int>
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>

//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word



const long long N = 200005, INF = 2000000000000000000;
//lld pi = 3.1415926535897932;
int lcm(int a, int b)
{
  int g = __gcd(a, b);
  return a / g * b;
}
int power(int a, int b, int p)
{
  if (a == 0)
    return 0;
  int res = 1;
  a %= p;
  while (b > 0)
  { if (b & 1)
      res = (res * a) % p;
    b >>= 1;
    a = (a * a) % p;
  }
  return res;
}

int testcaseva;

int sq(int x) { return 1ll * x * x; }


int32_t main() {

  int n;
  cin >> n;
int   m= (n%1000) ;
int k=n/1000 +1;
if(n%1000==0)
    cout << 0 << endl;
else 
  cout << k*1000 -n << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void printAnswer(int index_a, int index_b){
    cout << index_a+1 << " " << index_b+1 << endl;
}

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

    // input
    int N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    ll min_val = A[0];
    ll min_val_index = 0;
    ll max_val = A[0];
    ll max_val_index = 0;

    FOR(i, 0, N){
        ll val = A[i];
        if(val > max_val){
            max_val = val;
            max_val_index = i;
        }
        else if(val < min_val){
            min_val = val;
            min_val_index = i;
        }
    }

    bool isAllPlus;
    if(abs(max_val)>=abs(min_val)){
        // N回で全てを + にする
        isAllPlus = true;
    }else{
        // N回で全てを - にする
        isAllPlus = false;
    }

    ll orderNum = N + (N-1);
    p(orderNum);

    FOR(i, 0, N){
        if(isAllPlus){
            A[i] += A[max_val_index];
            printAnswer(max_val_index, i);
        }else{
            A[i] += A[min_val_index];
            printAnswer(min_val_index, i);
        }
    }

    if(A[0]>=0){
        // 累積
        FOR(i, 1, N){
            A[i] += A[i-1];
            printAnswer(i-1, i);
        }
    }else{
        // 逆累積
        for(int i=N-2; i>=0; i--){
            A[i] += A[i+1];
            printAnswer(i+1, i);
        }
    }

    // p("check");
    // for(auto a : A){
    //     cout << a << " ";
    // }
    // cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    int A[N];
    for(int i=0; i<N; i++) cin>>A[i];
    
    int cnt=0;
    bool flag=false;
    while(1){
        for(int i=0; i<N; i++){
            if(A[i]%2) flag=true;
            else A[i]/=2;
        }
        if(flag) break;
        else cnt++;
    }
    cout<<cnt<<endl;
}

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;
char _;
bool neg;
int _p;
char _b[50];
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#ifdef getchar_unlocked
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define max(...) maxx(__VA_ARGS__)
#define min(...) minn(__VA_ARGS__)
typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
void scan (char *x) {for(_p=0;(_=getchar())!=' '&&_!=10;x[_p++]=_);}
template <typename t> void scan (t& x) {neg=0;while((x=getchar())<'0') neg=x=='-'; for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0'); if(neg)x=-x;}
template <typename t, typename ...r> void scan (t& x, r&... xs) {scan(x); scan(xs...);}
template <typename t> t maxx (const t &a, const t &b) {return a > b ? a : b;}
template <typename t, typename ...r> t maxx (const t &a, const r &...b) {return maxx(a,maxx(b...));}
template <typename t> t minn (const t &a, const t &b) {return a < b ? a : b;}
template <typename t, typename ...r> t minn (const t &a, const r &...b) {return minn(a,minn(b...));}
template <typename t> void uin (t &a, const t &b) {a = minn(a,b);}
template <typename t, typename ...r> void uin (t &a, const r &...b) {a = minn(a,b...);}
template <typename t> void uax (t &a, const t &b) {a = maxx(a,b);}
template <typename t, typename ...r> void uax (t &a, const r &...b) {a = maxx(a,b...);}
void print (char *x) {for(_p=0;x[_p];putchar(x[_p++]));}
template <typename t> void print (t a) {if(a==0){putchar('0');return;}if(a<0)putchar('-'), a=-a;for(_b[_p=0]='0'+a%10;a/10;_b[++_p]='0'+(a/=10)%10);for (;~_p;putchar(_b[_p--]));}
template <typename t, typename ...r> void print (t &a, r &...b) {print(a);putchar(' ');print(b...);}
template <typename t, typename ...r> void println (t &a, r& ...b) {print(a,b...);putchar(10);}
void printlns (){}
template <typename t, typename ...r> void printlns (t &a, r &...b) {print(a); putchar(10); printlns(b...);}
const int MN = 505, MQ = 3e3+2, MOD = 1e9+7, BASE = 131;
int sq (int n) {return n*n;}
int main() { 
    int n;
    scanf ("%d",&n);
    vector<int> perm(n); vector<pii> towns(n);
    for (int i = 0; i < n; i++) perm[i] = i;
    for (auto &a : towns) scanf ("%d%d",&a.first,&a.second);
    int cnt = 0; double tot = 0;
    do {
		++cnt;
		for (int i = 0; i < n-1; i++) tot += sqrt(sq(towns[perm[i]].first-towns[perm[i+1]].first)+sq(towns[perm[i]].second-towns[perm[i+1]].second));
	} while (next_permutation(all(perm)));
	printf ("%.7f\n",tot/cnt);
    return 0;
}





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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


int N;
vector<double> p;
double dp[3005][3005];

void solve() {
    cin >> N;
    p.resize(N);
    rep(i, N) cin >> p[i];

    dp[0][0] = 1.0;
    rep(i, N){
        rep(j, N){
            dp[i+1][j+1] += dp[i][j]*p[i];
            dp[i+1][j] += dp[i][j]*(1-p[i]);
        }
    }

    double res=0;
    for(int i=(N+1)/2; i<=N; i++) res += dp[N][i];

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 74880
#include<bits/stdc++.h>
using namespace std;
 
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
#define DOR(i,s,t) for(int i=(s),_t=(t); i>=_t; --i)
#define EOR(i,x) for(int i=Head[x]; ~i; i=Nxt[i])

typedef long long ll;

const int M=(int)1e5+50;
const int Mod=(int)1e9+7;

char str[M];
int cnt[30];

int main() {
	int n;
	scanf("%d%s",&n,str+1);
	FOR(i,1,n) {
		++cnt[str[i]-'a'];
	}
	ll res=1;
	FOR(i,0,25) {
		res*=cnt[i]+1;
		res%=Mod;
	}
	--res;
	if(res<0) res+=Mod;
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 384
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=SI()
    if "7" in n:print("Yes")
    else:print("No")

main()

Measured memory_bytes: 9132
n=int(input())
heights=[int(i) for i in input().split()]

dp=[0]*n
dp[1]=abs(heights[1]-heights[0])

for i in range(2,n):
  dp[i]=min(dp[i-2]+abs(heights[i]-heights[i-2]), dp[i-1]+abs(heights[i]-heights[i-1]))
print(dp[n-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

ll MOD = 1000000007;


map<ll, ll> prime;//[素数の値, 指数]の形で値を保持するmap
void factorization(ll n){
  ll i = 2;
  ll temp = n;
  if (temp % i == 0){
    if (prime.find(i) == prime.end()){
      prime[i] = 0;
    }
  }
  while (i*i <= n){
    ll ind = 0;
    while (temp % i == 0){
      ind++;
      temp /= i;
    }
    prime[i] = max(prime[i], ind);
    i++;
  }
  if (temp != 1){
    if (prime.find(temp) == prime.end())prime[temp] = 0;
    ll one = 1;
    prime[temp] = max(prime[temp], one);
  }
}

long long modinv(long long a, long long m) {//aのmod mにおける逆元を求める
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int main(){
  int N; cin >> N;
  vector <ll> A(N);
  rep(i, N) cin >> A[i];
  ll lcm = 1;
  rep(i, N){
    factorization(A[i]);
  }
  for (auto itr = prime.begin(); itr != prime.end();itr++){
    rep(i, itr->second){
      lcm *= itr->first;
      lcm %= MOD;
    }
  }
  ll ans = 0;
  rep(i, N){
    ans += (lcm*modinv(A[i], MOD))%MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4264
// you**can**do**anything :~  
#include <bits/stdc++.h>
#define ll long long
#define read(i) scanf("%lli" , &i)
const int maxn=5e5+10;
using namespace std;
vector<ll>abj[545445];
int main() {
set<string>s;
string ss;
ll n;
cin>>n;
for(int i=0 ;i<n ;i++){
	cin>>ss;
	s.insert(ss);
}
cout<<s.size();
} 

Measured memory_bytes: 31944
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

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

	Int N, K;
	cin >> N >> K;

	Int ans = 0;
	Int n;
	for (Int i = 1; i <= N; i++) {
		n = (N + 1) / i;
		ans += max(0LL, i - K) * n + max(0LL, N - (K + n * i) + 1);
	}
	cout << (K==0?N*N:ans) << "\n";
}

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


int main(){
	
	int A,B,ans;
	char op;
	cin>>A>>op>>B;
	switch (op){
		case '+':
		ans=A+B;
		break;
		
		case '-':
		ans=A-B;
		break;
		default:
			cout<<"not valid operator"<<endl;
	}
	cout<<ans;
	return 0;
}

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

int main() {
	
	int N;
	cin >> N;
	int B[100010]{};
	for (int i = 0; i < N - 1; i++) cin >> B[i];

	int ans = 0;
	ans += B[0];
	ans += B[N - 2];
	for (int i = 1; i < N - 1; i++)
	{
		ans += min(B[i], B[i - 1]);
	}


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

Measured memory_bytes: 640
KIND = 26
l=int(input())
s=input()

alpha_list = []
for i in range(0, KIND):
    alpha_list.append(0)

for i in s:
    alpha_list[ord(i)-ord('a')] += 1

ret = 1
for num in alpha_list:
    ret *= (num + 1)
print((ret-1)%(1000000000+7))


Measured memory_bytes: 3188
#coding:utf-8
class Combination:
    def __init__(self,N,P=10**9+7):
        if N > 10**7:
            self.fact = lambda x: x * self.fact(x-1) % P if x > 2 else 2
            self.perm = lambda x, r: x * self.perm(x-1,r-1) % P if r > 0 else 1
            self.cmb = lambda n,r: (self.perm(n,min(n-r,r)) * pow(self.fact(min(n-r,r)) ,P-2 ,P) % P) if r > 0 else 1
        else:
            self.__fact = [1] * (N+1)
            self.__inv = [1] * (N+1)
            self.__inv_fact = [1] * (N+1)
            for i in range(2,N+1):
                self.__fact[i] = self.__fact[i-1] * i % P
                self.__inv[i] = - self.__inv[P%i] * (P//i) % P
                self.__inv_fact[i] = self.__inv_fact[i-1] * self.__inv[i] % P
            self.fact = lambda n: self.__fact[n]
            self.perm = lambda n,r: self.__fact[n] * self.__inv_fact[n-r] % P
            self.cmb = lambda n,r: (self.__fact[n] * self.__inv_fact[n-r] * self.__inv_fact[r] % P) if r > 0 else 1






import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7
    from collections import deque
    
    n,k = LMIIS()
    cmb = Combination(2*n)
    ans = 1
    for i in range(1,min(n,k+1)):
        ans = (ans + cmb.cmb(n,i) * cmb.cmb(n-1,i)) % MOD
    print(ans)

    
if __name__ == '__main__':
    main()

Measured memory_bytes: 83316
#include "bits/stdc++.h"
using namespace std;
#define int long long
int dp[(int)1e6+10];
const int INF = 2e18;
int32_t main()
{
	int n,lim;
	cin >> n >> lim;
	int sum=0;
	for(int i=0;i<=1e6+5;i++) dp[i]=INF;
	dp[0]=0;
	for(int i=1;i<=n;i++)
	{
		int w,v;
		cin >> w >> v;
		sum+=v;
		for(int i=sum;i>=v;i--)
		{
			dp[i]=min(dp[i],dp[i-v]+w);
		}
	}
	int ans = -(2e18);
	for(int i=1;i<=1e6+5;i++)
	{
		if(dp[i]<=lim)
		{
			ans=max(ans,i);
		}
	}
	cout << ans;
}


Measured memory_bytes: 8064
from fractions import gcd
n, k = map(int, input().split())

"""
さいころの目がiとするとき、得点をk以上にするには
int(log(i))+x >= kを満たすxの回数。つまりk-log(i)回連続で表が出れば良い
"""
import math
ans = 0 # 後でnで割る

for i in range(1, n+1):
    ans += 1/n * 2**(-max(0, math.ceil(math.log2(k/i))))
print(ans)

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in(),K=in();
	vector<int> H(N);
	REP(i,N){
		H[i]=in();
	}
	sort(ALL(H));
	int minH = 1e9+7;
	for(int i=0;i+K-1<N;i++){
		minH = min(minH,H[i+K-1]-H[i]);
	}

	cout << minH << endl;
	return 0;
}


Measured memory_bytes: 640
A,B,AB,X,Y = map(int,input().split())
ans = 0
if 2*AB < A+B:
    A = min(2*AB,A)
    B = min(2*AB,B)
    ans += 2*AB*min(X,Y)
    if X>Y:
        ans += A*(X-Y)
    else:
        ans += B*(Y-X)
    print(ans)
else:
    print(A*X+B*Y)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a==b)
        cout<<c<<endl;
    else if(a==c)
        cout<<b<<endl;
    else if(b==c)
        cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

typedef long long ll;

using namespace std;

int N, X, Y;
int cnt[2000 + 5];

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

	scanf("%d %d %d", &N, &X, &Y);

	for (int i = 1; i <= N; ++i)
	{
		for (int j = i + 1; j <= N; ++j)
		{
			int dist = min({ j - i, ABS(i - X) + 1 + ABS(j - Y), ABS(i - Y) + 1 + ABS(j - X) });
			cnt[dist]++;
		}
	}

	for (int i = 1; i <= N - 1; ++i)
	{
		printf("%d\n", cnt[i]);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (typeof((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(typeof(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    int n, r;
    while (cin >> n >> r) {
        if (n == 0) break;
        
        deque<int> hana(n);
        for (int i = 0; i < n; ++i) hana[i] = n-i;
        for (int i = 0; i < r; ++i) {
            int c, p;
            cin >> p >> c;
            vint temp;
            for (int k = 0; k < c; ++k) {
                temp.PB(hana[p-1]);
                hana.erase(hana.begin()+p-1);
            }
            reverse(ALL(temp));
            for (int k = 0; k < c; ++k) {
                hana.push_front(temp[k]);
            }
            
            //for (int i = 0; i < n; ++i) cout << hana[i] << ","; cout << endl;
        }
    
        cout << hana[0] << endl;
    }
    
    return 0;
}


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

using namespace std;

int main (void) {
    int N, K;
    cin >> N >> K;
    map<int, int> ball;
    int a;
    for ( int i=0; i<N; i++ ) {
        cin >> a;
        ball[a]++;
    }

    /* 各ボールの値の数をソートできるように
     * vector に入れ替える */
    vector<int> n_num;
    for ( auto itr : ball ) {
        n_num.push_back(itr.second);
    }

    sort(n_num.begin(), n_num.end());

    /* ボールの数が少ない方から書き換えていく */
    int idx = 0;
    int ans = 0;
    int kinds = ball.size() - K;
    while ( kinds > 0 ) {
        ans += n_num.at(idx);
        idx++;
        kinds--;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10748
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <cfloat>
using namespace std;

int solve(int money, int year, vector<int>& a, vector<double>& b, vector<int>& c)
{
    int n = a.size();
    int ret = 0;
    for(int i=0; i<n; ++i){
        int balance = money; // c
        int interest = 0;    // q
        for(int j=0; j<year; ++j){
            interest += balance * b[i];
            if(a[i] == 1){
                balance += interest;
                interest = 0;
            }
            balance -= c[i];
        }
        balance += interest;
        ret = max(ret, balance);
    }
    return ret;
}

int main()
{
    int m;
    cin >> m;
    for(int i=0; i<m; ++i){
        int money, year, n;
        cin >> money >> year >> n;
        vector<int> a(n), c(n);
        vector<double> b(n);
        for(int i=0; i<n; ++i)
            cin >> a[i] >> b[i] >> c[i];

        cout << solve(money, year, a, b, c) << endl;
    }
}

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


public class Main {

	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		//int n = Integer.parseInt(sc.next());
		String s = sc.next();
		int n = Integer.parseInt(s.substring(s.length()-1 ,s.length()));
		Integer[] a = {2,4,5,7,9};
		Integer[] b = {0,1,6,8};
		Integer[] c = {3};
		if(Arrays.asList(a).contains(n)) {
			System.out.println("hon");
		}else if(Arrays.asList(b).contains(n)) {
			System.out.println("pon");
		}else {
			System.out.println("bon");
		}
		
	}
}


Measured memory_bytes: 27004
use std::io;
use std::cmp::min;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let x = v[1];
	let mut m:Vec<i32> = Vec::new();
	let mut sum = 0;
	for i in 0..n {
		let v:Vec<i32> = procon_read();
		sum += v[0];
		m.push(v[0]);
	}
	let mut mini = 1000;
	for i in m {
		mini = min(mini, i);
	}
	println!("{}", n + (x - sum)/mini);
}

Measured memory_bytes: 4352
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    a: i32,
    s: String,
  }
  if a >= 3200 {
    puts!("{}\n", s);
  } else {
    puts!("red\n");
  }
}


Measured memory_bytes: 4352
// C - Maximal Value

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> n;
  vlli d(n - 1), e;
  rep(i, 0, n - 1)
  {
    cin >> d[i];
  }
  ans += d[0];
  rep(i, 1, n - 1)
  {
    c = min(d[i - 1], d[i]);
    ans += c;
  }
  ans += d[n - 2];

  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque

def bfs(graph,v=1):
    #args:
    #   graph グラフ本体
    #   v 現在注目しているノード（スタート地点）
    arrow = [-1]*len(graph) #矢印がどこを向いているか
    q = deque()
    q.append(v)
    arrow[v] = 0
    while q:

        now = q.popleft()
        for next_v in graph[now]:
            if arrow[next_v] != -1:
                continue
            else:
                q.append(next_v)
                arrow[next_v] = now
    return arrow

def main():
    n,m = map(int,input().split())
    graph = [[] for _ in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        graph[a].append(b)
        graph[b].append(a)
    answer = bfs(graph)
    print("Yes")
    for ans in answer[2:]: #矢印が置かれているのは2部屋目以降
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 34692
#include <bits/stdc++.h>
#define pb push_back
#define sz(V) ((int)(V).size())
using namespace std;
typedef long long ll;
void fg(vector<int> G[], int a, int b) { G[a].pb(b); G[b].pb(a); }

const int MAXN = 100005;

vector<int> G[MAXN];

int dep[MAXN], cnt[MAXN];

int N;

void f(int i, int d) {
	dep[i] = d;
	int c = 0, x = 0;
	for(int v : G[i]) {
		if(dep[v]) continue;
		f(v, d+1);
		c++;
		x ^= cnt[v];
	}
	cnt[i] = x + 1;
}

int main() {
	cin >> N;
	for(int i = 1, a, b; i < N; i++) {
		cin >> a >> b;
		fg(G, a, b);
	}
	f(1, 1);
	puts(1 == cnt[1] ? "Bob" : "Alice");
	return 0;
}

Measured memory_bytes: 12800
#include <stdio.h>
#include <algorithm>

using namespace std;
using ll = long long;
int main() {
	int n, A[100001], B[100001], C[100001];
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", A + i);
	sort(A, A + n);
	A[n] = 1e9 + 1;
	for (int i = 0; i < n; i++)
		scanf("%d", B + i);
	sort(B, B + n);
	B[n] = 1e9 + 1;
	for (int i = 0; i < n; i++)
		scanf("%d", C + i);
	sort(C, C + n);
	C[n] = 1e9 + 1;

	ll dp[3][100000];

	int low = 0;
	for (int i = 0; i < n; i++) {
		while (A[low] < B[i])
			low++;
		dp[1][i] = low;
	}
	ll total = 0;
	low = 0;
	for (int i = 0; i < n; i++) {
		while (B[low] < C[i])
			total = total + dp[1][low++];
		dp[2][i] = total;
	}
	total = 0;
	for (int i = 0; i < n; i++)
		total = total + dp[2][i];
	printf("%lld\n", total);
}

Measured memory_bytes: 3712