akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int main() {
	int N,i,flag;
	string ans;
	flag = 0;
	cin >> N;
	for(i=0;i<N;i++){
		cin >> ans;
		if (ans == "Y") {
			flag = 1;
		}
	}
	if (flag == 0) {
		cout << "Three" << endl;
	}
	else {
		cout << "Four" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
double b[1919];
signed main() {
	double n, t, a,inf=10000000000,ans;
	cin >> n >> t >> a;
	for (int i = 0; i < n; i++)cin >> b[i];
	for (int i = 0; i < n; i++) {
		double p = t -b[i] * 0.006;
		double q = abs(a - p);
		if (q < inf) {
			inf = q;
			ans = i+1;
		}
	}
	cout << ans << endl;
	ll
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define eps 1e-67
#define pf printf
#define sf scanf
#define sd(n) scanf("%d",&n)
#define sd2(n1,n2) scanf("%d %d",&n1,&n2)
#define slf(n) scanf("%lf",&n)
#define slf2(n1,n2) scanf("%lf %lf",&n1,&n2)
#define sLf(n1) scanf("%Lf",&n1)
#define sLf2(n1,n2) scanf("%Lf %Lf",&n1,&n2)
#define sl(n) scanf("%lld",&n)
#define sl2(n1,n2) scanf("%lld %lld",&n1,&n2)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define repb(i,a,b) for(long long int i=a;i>=b;i--)
#define repa(i,a,b,c) for(long long int i=a;i<b;i=i+c)
#define reps(i,a,b,c) for(long long int i=a;i>b;i=i-c)
#define asort(a) sort(a.begin(),a.end())
#define asortb(a,comp) sort(a.begin(),a.end(),comp)
#define arev(a) reverse(a.begin(),a.end())
#define all(v) (v).begin(),(v).end()
#define allc(v,comp) (v).begin(),(v).end(),comp
#define allrc(v,a,b,comp) (v).begin()+a,(v).end()-b,comp
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define pbb pop_back
#define mp make_pair
#define mt make_tuple
#define bs(v,x) binary_search(v.begin(),v.end(),x)
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define tl(c) towlower(c)
#define root(x) sqrt(x)
#define power(a,n) pow(a,n)
#define tu(c) towupper(c)
#define sq(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define mx 1000
#define MX 100000
#define mod 1000000007
using namespace std;
typedef string str;
typedef long long int ll;
typedef double lf;
typedef long double llf;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef char ch;
typedef map<ll,ll> mp;
void Solve()
{
    int n,m,i,j;
    cin>>n>>m;
   string a[n+1];
   string b[m+1];
   string s,ss;
   int c=0;
   rep(i,0,n)
   {
       cin>>s;
       a[i]=s;
   }
   int flag=0;
   rep(i,0,m)
   {
       cin>>ss;
       b[i]=ss;
   }
   rep(i,0,n-m+1)
   {
       rep(j,0,n)
       {
           c=0;
           rep(k,0,m)
           {
               if(a[i+k].substr(j,m)==b[k])
               {
                   c++;
               }
           }
           if(c==m)
           {
              flag=1;
              goto ans;
           }

       }
   }
   ans:
   if(flag==1)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;


}
int main()
{
    Solve();
    return 0;
}


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

int main(){
    int group[]={-1,1,2,1,3,1,3,1,1,3,1,3,1};
    int x,y;
    cin>>x>>y;
    if(group[x] == group[y]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
long long  INF=1'0000'0000'0000'0000'00;
using namespace std;

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

int x=A*B;
int y=A+B;
int z=A-B;
int ans=0;
ans=max(x,y);
ans=max(ans,z);


cout<<ans<<endl;



 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
char a;
cin>>a;
if(a=='A'||a=='B'||a=='C'||a=='D'||a=='E'||a=='F'||a=='G'||a=='H'||a=='I'||a=='J'||a=='K'||a=='L'||a=='M'||a=='N'||a=='O'||a=='P'||a=='R'||a=='S'||a=='T'||a=='U'||a=='V'||a=='W'||a=='X'||a=='Y'||a=='Z')
cout<<"A"<<endl;
else cout<<"a"<<endl;

}

Measured memory_bytes: 3616
fun main(args: Array<String>) {
    val l1 = readLine()!!.split(" ").map{ it.toInt() }
    val s = readLine()!!
    val x = l1[1] + l1[2]
    var cnt = 0
    var cntb = 0
    for (i in 0 until l1[0]) {
        if (s[i] == 'a') {
            if (cnt < x) {
                cnt++
                println("Yes")
            } else {
                println("No")
            }
        } else if (s[i] == 'b') {
            cntb++
            if (cnt < x && cntb <= l1[2]) {
                cnt++
                println("Yes")
            } else {
                println("No")
            }
        } else {
            println("No")
        }
    }
}

Measured memory_bytes: 42524
#include<stdio.h>

#include<algorithm>


using namespace std ;



int ans[ 50000 + 1 ] ;

int coin[ 20 ] ;


int main()
{
	int n ,m ;
	scanf( "%d %d" ,&n ,&m ) ;


	int i ,j ;
	for( i = 0 ; i < m ; ++i )
	{
		scanf( "%d" ,&coin[ i ] ) ;

		++ans[ coin[ i ] ] ;
	}

	
	for( i = 1 ; i < n ; ++i )
	{
		for( j = 0 ; j < m ; ++j )
		{
			if( i + coin[ j ] <= n )
			{
				ans[ i + coin[ j ] ] = ans[ i + coin[ j ] ] ? min( ans[ i + coin[ j ] ] ,ans[ i ] + 1 ) : ans[ i ] + 1 ;
			}
		}
	}


	printf( "%d\n" ,ans[ n ] ) ;


	return 0 ;
}

Measured memory_bytes: 2924
#pragma warning(disable:4996)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;

#define INF 0x3fffffff
typedef long long ll;

#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define pb push_back

const int maxn = 5000 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }

int n;
char x[maxn];
int dp[maxn][maxn];

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

void solve()
{
	scanf("%d", &n);
	scanf("%s", x);
	int len = strlen(x);
	ll ans = 1;
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			add(dp[i][max(j - 1, 0)], dp[i - 1][j]);
			add(dp[i][j + 1], 2 * dp[i - 1][j] % mod);
		}
	}
	ans = dp[n][len];
	int inv2 = po(2, mod - 2);
	for (int i = 1; i <= len; i++)
	{
		ans *= inv2;
		ans %= mod;
	}
	printf("%lld", ans);
}

int main()
{

	solve();
	return 0;
}


Measured memory_bytes: 98048
#include<bits/stdc++.h>
using namespace std;
int main(){
    int p,q,r;
    cin>>p>>q>>r;
    vector<int>vec={p,q,r};
    sort(vec.begin(), vec.end());
    int l=vec.at(0)+vec.at(1);
    cout<<l<<endl;
    
    
  
  }
    
  


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

typedef long long ll;
ll K;
int N, M;
bool ok(const vector<ll> &A, const vector<ll> &B, int num)
{
    ll sum = 0;
    int a = 0, b = 0;
    if(N + M < num) return false;
    while(a + b < num)
    {
        if(a < N) sum += A[a++];
        else sum += B[b++];
    }
    --a;
    while(1){
        if(sum <= K) return true;
        if(a < 0 || b >= M) break;
        else{
            sum -= A[a--];
            sum += B[b++];
        }
    }
    return false;
}

int main()
{
    cin >> N >> M >> K;
    vector<ll> A(N), B(M);
    for(int i=0;i<N;++i)
        cin >> A[i];
    for(int i=0;i<M;++i)
        cin >> B[i];
    ll l = 0, r = 1001001001;
    ll mid;
    while(l + 1 < r)
    {
        mid = (l + r) / 2;
        if(ok(A, B, mid)) l = mid;
        else r = mid;
    }
    cout << r - 1 << endl;
}

Measured memory_bytes: 6416
import heapq
N = int(input())
V = list(map(int, input().split()))
heapq.heapify(V)
for i in range(N-1):
    a, b = heapq.heappop(V), heapq.heappop(V)
    heapq.heappush(V, (a + b) / 2)
print(heapq.heappop(V))

Measured memory_bytes: 3060
#include <vector>
#include <tuple>
#include <queue>
#include <utility>
#include <iostream>

// Graph template (start)
template <class... Args>
struct Edge
{
	int from, to;
	std::tuple<Args...> values;
	Edge(int from, int to, Args... values)
		: from(from), to(to), values(values...) {}
};

template <class E>
auto operator<(const E &e, const E &f)
{
	return e.values > f.values;
}

template <class... Args>
class Graph
{
	using Edges = std::vector<Edge<Args...>>;
	std::vector<Edges> graph_;

  public:
	Graph(int n) : graph_(n) {}
	std::size_t size() { return graph_.size(); };
	std::size_t size() const { return graph_.size(); };
	auto &operator[](unsigned int x) { return graph_[x]; }
	const auto &operator[](unsigned int x) const { return graph_[x]; }
	void AddEdge(int s, int t, Args... v) { graph_[s].emplace_back(s, t, v...); }
	void AddEdge(Edge<Args...> e) { graph_[e.from].push_back(e); }
};
// Graph template (end)

using Weight = long long;
constexpr long long kWEIGHT_INF = 1e18;

template <class... Args>
auto Dijkstra(const auto &g, int s)
{
	const int n = g.size();
	std::vector<Weight> dist(n, kWEIGHT_INF); //各点における始点sからの距離が入る
	std::vector<int> prev(n, -1);			  //各点における最短路の親が入る
	dist[s] = 0;
	std::priority_queue<Edge<Weight>> q;
	q.emplace(-2, s, dist[s]);
	while (!q.empty())
	{
		auto now = q.top();
		q.pop();
		int parent = now.from, u = now.to;
		if (prev[u] != -1)
		{
			continue;
		}
		else
		{
			prev[u] = parent;
		}
		for (const auto &e : g[u])
		{
			int v = e.to;
			auto cost = std::get<0>(e.values);
			if (dist[v] > dist[u] + cost)
			{
				dist[v] = dist[u] + cost;
				q.emplace(u, v, dist[v]);
			}
		}
	}
	return std::make_pair(dist, prev);
}

int main()
{
	int n, m, root;
	std::cin >> n >> m >> root;
	Graph<Weight> g(n);
	for (int i = 0; i < m; ++i)
	{
		int s, t;
		Weight d;
		std::cin >> s >> t >> d;
		g.AddEdge(s, t, d);
	}
	auto dist = Dijkstra(g, root).first;
	for (int i = 0; i < n; ++i)
	{
		if (dist[i] == kWEIGHT_INF)
			std::cout << "INF" << std::endl;
		else
			std::cout << dist[i] << std::endl;
	}
}
// be checked by AOJ(GRL-1-A).


Measured memory_bytes: 19992
using System;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Collections.Generic;
using System.Linq;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            long mod = 1000000007;
            long ans = 0;
            var n = myRead.readInt();
            var s = myRead.readLongArray();
            long sum = 0;
            for (int i = 0; i < n; i++)
            {
                sum += s[i];
            }
            for (int i = 0; i < n - 1; i++)
            {
                sum -= s[i];
                ans += (s[i] * (sum % mod)) % mod;
                ans %= mod;
            }
            WriteLine(ans);
        }
    }
    public static class myRead
    {
        public static int readInt() { return int.Parse(ReadLine()); }
        public static long readLong() { return long.Parse(ReadLine()); }
        public static string readStr() { return ReadLine(); }
        public static int[] readIntArray() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        public static long[] readLongArray() { return ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        public static string[] readStrArray() { return ReadLine().Split(' '); }
    }


    public static class MyMath
    {
        public static long Factorical(long n)
        { return n <= 1 ? 1L : n * Factorical(n - 1); }
        public static long Permutation(long n, long m)
        { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); }
        public static long Combination(long n, long m)
        { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); }
        public static long Gcd(long n, long m)
        { return n % m == 0 ? m : Gcd(m, n % m); }
        public static long Lcm(long n, long m)
        { return n * m / Gcd(n, m); }
        public static long Pow(long n, long m)
        { return m == 0 ? 1L : m == 1 ? n : n * Pow(n, m - 1); }
    }


}

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

int main(){
    int N;
    cin >> N;
    vector<int> a(3*N+1);
    for(int i = 1;i <= 3*N;i++) cin >> a[i];
    vector<LL> p(N+1), q(N+2, 1e18);
    priority_queue<int, vector<int>, greater<int>>  que;
    LL sum = 0;
    for(int i = 1;i < N;i++){
        sum += a[i];
        que.push(a[i]);
    }
    for(int i = N;i <= 2*N;i++){
        sum += a[i];
        p[i-N] = sum;
        que.push(a[i]);
        sum -= que.top();
        que.pop();
    }
    sum = 0;
    priority_queue<int> que2;
    for(int i = 3*N;i > 2*N+1;i--){
        sum += a[i];
        que2.push(a[i]);
    }
    for(int i = 2*N+1;i >= N+1;i--){
        sum += a[i];
        q[i-N-1] = min(sum, q[i-N]);
        que2.push(a[i]);
        sum -= que2.top();
        que2.pop();
    }
    LL ans = -1e18;
    for(int i = 0;i <= N;i++){
        ans = max(ans, p[i]-q[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4088
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
p = li()

min_p = p[0]
cnt = 0
for i in range(n):
    if min_p >= p[i]:
        cnt += 1
    min_p = min(min_p,p[i])
print(cnt)

Measured memory_bytes: 33824
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if (0 >= a && 0 <= b) {
        cout << "Zero" << endl;
        return 0;
    }
    if (a > 0) {
        cout << "Positive" << endl;
        return 0;
    }
    if (b < 0) {
        a -= b - 1;
    }
    a = abs(a);
    if (a % 2 == 1) {
        cout << "Negative" << endl;
    } else {
        cout << "Positive" << endl;
    }
}




Measured memory_bytes: 3596
/* 
    AABRA KA DABRA.. !! 
*/
#include "bits/stdc++.h"
using namespace std;
typedef long double ld;
#define int long long
#define RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(i=0; i <n; i++)
#define repv(i,k,n) for(int i=k; i<=n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define endl '\n'
#define deb(x) cout<<#x<<" = "<<x<<endl
#define gcd __gcd
#define inf LLONG_MAX
#define minf LLONG_MIN 
const int mod = (int)(1e9+7);

int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
bool is_power_2(int n)  { return log2(n)==floor(log2(n));}
bool is_prime(int n){   for(int i=2; i*i<=n; i++)   if(n%i==0)  return 0;   return 1;}

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

/*                                                                 
    ╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩╦═╩═╦═╩═╦═╩═╦═╩═╦═╩╦═╩═╦═╩═╦═╩═╦═╩═╦═╩╦═╩═╦═╩═╦ 
*/  




void solve()
{   
    int n,i,j,k,m;
    cin>>n;
    int ar[n];
    map<int,int> mp;
    int sum=0;
    rep(i,n)
    {   
        cin>>ar[i];
        sum += ar[i];
        mp[ar[i]]++;
    }
    int q;
    cin>>q;
    while(q--)
    {
        int a,b;
        cin>>a>>b;
        m = mp[a];
        mp[a] = 0;
        mp[b] += m;
        sum -= a*m;
        sum += b*m;
        cout<<sum<<endl;
    }
}   
signed main()
{
    RAGE;
    int t=1;
    //  cin>>t;
    while(t--)
        solve();

    return 0;
}

Measured memory_bytes: 10240
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int max(int a,int b){return (a>b ? a:b);}
int min(int a,int b){return (a<b ? a:b);}

int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
//これは昇べきの順のソート

//int compare_int(const void *a, const void *b){return *(int*)b - *(int*)a;}
//これは降べきの順のソート

//qsort(配列, 長さ, sizeof(int), compare_int);

double BS(int array[],int len,int target);

//////////////////////////////////////////

int a,b,c,d,e,k;

int main(){
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&k);
    if((e-a)>k){
        printf(":(\n");
    }else{
        printf("Yay!\n");
    }

    
    
    return 0;
}



///////////////////////////////////////////


double BS(int array[],int len,int target){ //(配列,長さ,見つける値)
    int low,mid,high;

    low = 0;
    high = len-1;

    int mark;

    while(low <= high){
        mid = (low + high) / 2;
        if(array[mid] == target){
            mark = 0;
            break;
        }else if(array[mid] < target){
            low = mid + 1;
            mark = 1;
        }else{
            high = mid - 1;
            mark = -1;
        }
    }
    if(mark == 0){
        return mid; //配列の何番目か（０から）
    }else if(mark == 1){
        return (double)mid + 0.5;//なかったらどこのあいだか
    }else{
        return (double)mid - 0.5;
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    ios;
    string s; cin >> s;
    rep(i,s.size())
        cout << 'x';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  map<int,bool> s;
  for (int i = 0; i < n; ++i)
  {
    int tmp;
    cin>>tmp;
    s[tmp]=true;
  }
  int q;
  cin>>q;
  int ans=0;
  for (int i = 0; i < q; ++i)
  {
    int tmp;
    cin>>tmp;
    if(s[tmp]) ans++;
  }
  cout<<ans<<endl;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;


ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    (a *= a) %= MOD;
    n >>= 1;
  }
  return res;
}

const ll maxf = 10000000;
ll fact[maxf+5];
ll ifact[maxf+5];

void fact_init(){
  fact[0] = 1;
  for(ll i=1; i<=maxf; i++) fact[i] = (fact[i-1] * i) % MOD;
  ifact[maxf]=modpow(fact[maxf],MOD-2);
  for(ll i=maxf; i>=1; i--) ifact[i-1] = (ifact[i] * i) % MOD;
}

ll comb(ll n, ll r){
  if(n<r || n<0 || r<0) return 0;
  if(fact[0] == 0) fact_init();
  return ((fact[n] * ifact[n-r]) % MOD * ifact[r]) % MOD;
}

ll naive_comb(ll n, ll r){
  ll res = 1;
  for (ll i = n; i > n - r; i--) res = res * i % MOD;
  for (ll i = 1; i <= r; i++) res = (res * modpow(i, MOD-2)) % MOD;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  vll a(n);
  rep(i,n) cin>>a[i];
  vsort(a);
  
  ll ma=0;
  irep(i,k-1,n){
    (ma+=a[i]*comb(i,k-1))%=MOD;
  }
  reverse(all(a));
  ll mi=0;
  irep(i,k-1,n){
    (mi+=a[i]*comb(i,k-1))%=MOD;
  }
  ll ans=(ma-mi+MOD)%MOD;
  cout<<ans<<endl;
}

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

int main() {
string S  ;
    cin >> S ;
bool hitachi=true;
for (int j=0;j<S.size()-1;j+=2){
 if( S[j]!='h'||S[j+1]!='i'){
  hitachi=false;
 }
}  
 if(S.size()%2==1){
    hitachi=false;
  }
  
  if(hitachi==true){
  cout << "Yes"<< endl;
  }  
  else cout <<"No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll int
#define fi first
#define deb(x) cout<<#x<<" "<<x<<endl;
#define debarr(a) cout<<#a<<endl;for(auto i: a) cout<<i<<" ";
#define se second
#define cnt(i) __builtin_popcountll(i)
#define pb emplace_back
#define mp make_pair
#define tc while(t--)
#define fo(n) for(int i=0;i<n;i++)
#define foj(m,n) for(int j=m;j<n;j++)
#define INF 9999999999
#define pra(a,n) fo(n)cout<<a[i]<<" ";cout<<endl;
#define vp vector<pair<int,int>>
#define vc vector<int>
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pp pair<ll,ll>
#define ispow2(x)  x && (!(x&(x-1)))
#define copy(a,b,n) copy_n(a,n,b) 
#define create(a,m,n) iota(a,a+n,m)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define maximum(a,n)  ll* i1,maxi; i1 = std::max_element(a, a+n);maxi=*i1 
#define minimum(a,n)  ll* i1,mini; i1 = std::min_element(a, a+n);mini=*i1 
using namespace std;
ll n,a[200005]={0};


  



signed main(){
    fio
    cin>>n;
    fo(n)
    cin>>a[i];
    map<int,int> m;
    fo(n)
    m[a[i]]+=1;

    ll ans=0;
    fo(n)
    {ll flag=1;
    foj(1,sqrt(a[i])+1)
    {
        if(a[i]%j==0 )
        {
            if(m[j]>0 and j!=a[i])
            {flag=0;
                break;
            }
            if((j==1 and m[a[i]]>1) or (j>1 and m[a[i]/j]>0))
            {
                flag=0;
                break;
            }
        }
    }    
        ans+=flag;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 33192
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
arr=list(map(int,input().split()))
if not(x in arr):
  print(x)
  exit()
i=0
while True:
  if not(x-i-1 in arr):
    print(x-i-1)
    exit()
  elif not(x+i+1 in arr):
    print(x+i+1)
    exit()
  i+=1

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

bool ft_print_num(int n) {
    if (n == 0) {
        return false;
    } else if (n % 10 == 3) {
        return true;
    }
    return ft_print_num(n / 10);
}

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

    int n;
    cin >> n;

    for (int i = 1; i < n + 1; i++) {
        if (i % 3 == 0) {
            cout << ' ' << i;
        } else if (ft_print_num(i)) {
            cout << ' ' << i;
        }
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int solve_left(const string& s, int n, int q, const vector<char>& t, const vector<char>& d) {
	int l = -1, r = n;
	while(r - l > 1) {
		int m = (l + r) / 2;
		int now = m, minidx = m;
		for (int i = 0; i < q; ++i) {
			if (s[now] == t[i]) now += (d[i] == 'L') ? -1 : 1;
			minidx = min(now, minidx);
		}
		if (minidx < 0) l = m;
		else r = m;
	}
	return l;
}

int solve_right(const string& s, int n, int q, const vector<char>& t, const vector<char>& d) {
	int l = -1, r = n;
	while(r - l > 1) {
		int m = (l + r) / 2;
		int now = m, maxidx = m;
		for (int i = 0; i < q; ++i) {
			if (s[now] == t[i]) now += (d[i] == 'L') ? -1 : 1;
			maxidx = max(now, maxidx);
		}
		if (maxidx >= n) r = m;
		else l = m;
	}
	return r;
}

int main(int argc, char const *argv[])
{
	int n, q; cin >> n >> q;
	string s; cin >> s;
	vector<char> t(q), d(q); rep(i, q) cin >> t[i] >> d[i];

	int left = solve_left(s, n, q, t, d);
	int right = solve_right(s, n, q, t, d);
	// printf("%d %d\n", left, right);

	int del = (left + 1) + (n - right);
	printf("%d\n", n - del);
	return 0;
}

Measured memory_bytes: 900
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
      	int B = sc.nextInt();
		int C = sc.nextInt();
      int X = C-(A-B);
        if(X<0){
        System.out.print(0);
        }
      else{
		System.out.print(C-(A-B));
      }
	}
}

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

using namespace std;

using int64 = long long;

vector<int> PermutationProduct(const vector<int>& p, const vector<int>& q) {
  int n = p.size();
  vector<int> r(n);
  for (int i = 0; i < n; i++) {
    r[i] = p[q[i]];
  }
  return r;
}

vector<int> PermutationPower(const vector<int>& p, int64 k) {
  int n = p.size();

  if (k == 0) {
    vector<int> r(n);
    for (int i = 0; i < n; i++) r[i] = i;
    return r;
  }
  
  if (k == 1) {
    return p;
  }
  
  if (k % 2 == 1) {
    vector<int> q = PermutationPower(p, k - 1);
    return PermutationProduct(p, q);
  } else {
    vector<int> q = PermutationPower(p, k / 2);
    return PermutationProduct(q, q);
  }
}

vector<int> PermutationInverse(const vector<int>& p) {
  int n = p.size();
  vector<int> r(n);
  for (int i = 0; i < n; i++) {
    r[p[i]] = i;
  }
  return r;
}

void DumpVector(vector<int> xs) {
  for (int x : xs) {
    cout << x << " ";
  }
  cout << endl;
}

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

  // vector<int> r({1, 2, 3, 4, 0});
  // DumpVector(PermutationPower(r, 0));
  // DumpVector(PermutationPower(r, 1));
  // DumpVector(PermutationPower(r, 2));
  // DumpVector(PermutationPower(r, 3));
  // DumpVector(PermutationPower(r, 4));
  // DumpVector(PermutationPower(r, 5));

  int n;
  cin >> n;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }
  vector<int64> ds(n - 1);
  for (int i = 0; i < n - 1; i++) {
    ds[i] = xs[i + 1] - xs[i];
  }

  vector<int> p(n - 1);
  for (int i = 0; i < n - 1; i++) {
    p[i] = i;
  }

  // cout << "p: "; DumpVector(p);

  int m;
  int64 k;
  cin >> m >> k;
  for (int i = 0; i < m; i++) {
    int op;
    cin >> op;
    op -= 2;
    swap(p[op], p[op + 1]);
  }

  // cout << "p: "; DumpVector(p);
  p = PermutationPower(p, k);
  
  int64 cur = xs[0];
  cout << cur << endl;
  for (int i = 0; i < n - 1; i++) {
    cur += ds[p[i]];
    cout << cur << endl;
  }
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n){
    cin >> a[i];
    if(a[i]%2==0){
      if(!(a[i]%3==0||a[i]%5==0)){
        cout << "DENIED" <<endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" <<endl;
  return 0;
}

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

int main() {
  vector<int> p(124,0);
  string s;
  cin >> s ;
  for ( int i=0 ; i<s.size() ; i++){
    p[(int)(s.at(i))]++;
}
  for ( int i=0 ; i<125 ; i++){
    if (p[i]>=2){
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int cnt = 0;
    for (int i = 0; i < N; ++i)
    {
        int a;
        cin >> a;
        cnt += a - 1;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 384
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    }
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt), * )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(n: i32,);
    let mut r = 0;
    for i in 1..n+1 {
        let s: String = i.to_string();
        if s.len() % 2 != 0 {
            r += 1;
        }
    }
    println!("{}", r);
}


Measured memory_bytes: 4352
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

N,K = map(int,input().split())
A,B = np.array([input().split() for _ in range(N)], dtype=np.int64).T

ks = [K]
x = K
while x:
    ks.append(x-1)
    x -= x&(-x)

answer = 0
for k in ks:
    select = (A & k == A)
    answer = max(answer, B[select].sum())

print(answer)

Measured memory_bytes: 53024
st = input()
hash_set = set()
for item in st:
    hash_set.add(item)

a = "abcdefghijklmnopqrstuvwxyz"

flag = False
for item in a:
    if not item in hash_set:
        print(item)
        flag = True
        break

if flag == False:
    print("None")


Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){			// s>H>C>D
	int n, m;    //nはカードの枚数　ｍはカードの数字
	cin >> n;
	int cards[4][13] = {0};
	char b; //ｂはカードの種類（ハートとか）

	for (int i = 0; i < n; i++) {
		cin >> b >> m;

		if(b == 'S') cards[0][m-1] = 1;  //Sのとき0とする   持っているカードに１と印をつける
		else if(b == 'H') cards[1][m-1] = 1;//Hのとき１
		else if(b == 'C') cards[2][m-1] = 1;//Cのとき２
		else if(b == 'D') cards[3][m-1] = 1;//Dのとき３

	}


	for (int j = 0; j < 4; j++) { //カードの種類

		for (int k = 0; k < 13; k++) { //カードの数字
		    if(cards[j][k] == 0){
		        
		        if(j == 0) {cout << "S " << k+1 << endl;}
		        if(j == 1) {cout << "H " << k+1 << endl;}
		        if(j == 2) {cout << "C " << k+1 << endl;}
		        if(j == 3) {cout << "D " << k+1 << endl;}
		    }
		}
	}

	
	return 0;
}


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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  string s;

  cin >> s;

  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());

  char c = 'a';
  REP (i, int(s.size())) {
    if (s.at(i) == c) {
      c++; 
    }
    else {
      cout << c << "\n";
      exit(0);
    }
  }
  if (s.size() == 26) cout << "None" << "\n";
  else cout << c << "\n";
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MOD 100000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    double L;
    cin >> L;

    printf("%.012f\n", pow(L / 3, 3));

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;


int main()
{
	int i, j, k, l, m, X, Y,sum,flag;
	flag = 0;
	sum = 0;
	cin >> i >> j >> k >> l;
	if (abs(k - i) <= l) {
		cout << "Yes" << endl;
	}
	else if (abs(j - i) <= l && abs(k - j) <= l) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
	
    return 0;
}



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

#define ll long long
#define ar array

const int mxN=1e5,INF=999999999;
int  a[mxN], c[2*100*mxN+1];

/* 1. If you can't keep solution in mind, then visualize it on a paper.
 * 2. Try to identify the type of problem - DP, Greedy, Graph, Constructive, 
 * 	  Prefix/Suffix, Difference Array, BIT/Segment Tree, etc.
 * 3. Look at the problems from different perspectives - reverse the problem, 
 * 	  add instead of delete (maybe?)
 * 4. Divide difficult solutions into cases and/or sequences.
 * 5. Use math rules to solve Nested Summation.
 * 6. Optimisation problems are generally solved with DP, greedy, binary search or brute-force.
 * ------------------------------------------------------------------ 
 */

void solve() {
    string s,t;
	cin >> s;cin>>t;
	int maxm=0;
	for(int i=0;i<s.size()-t.size()+1;i++){
	    string pk=s.substr(i,t.size());
	   //cout<<pk<<endl;
	    int k=0;
	    for(int j=0;j<t.size();j++){
	        if(pk[j]==t[j]){
	            k++;
	        }
	    }
	    maxm=max(maxm,k);
	}
	cout<<t.size()-maxm;
}

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

	int t=1;

	for(int i=1; i<=t; ++i) {
	//	cout << "Case #" << i << ": ";
		solve();
	}
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    int n;
    cin >> n;
    Int a[n];
    Int b[n];
    rep(i,n) cin >> a[i] >> b[i];
    sort(a, a+n);
    sort(b, b+n);
    int ans = 0;
    if (n % 2 == 1) {
        int m = n/2;
        ans = b[m] - a[m] + 1;
    }
    else {
        int m1 = n/2 - 1;
        int m2 = n/2;
        ans = (b[m2] + b[m1]) - (a[m2] + a[m1]) + 1;
    }
    cout << ans << endl;
}




Measured memory_bytes: 6752
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    ll N, M; cin >> N >> M;
    map<int, int> mp;
    rep(i, M) {
        ll a, b; cin >> a >> b;
        mp[a]++; mp[b]++;
    }
    reps(i, N) cout << mp[i] << endl;
}

Measured memory_bytes: 3640
#include <iostream>

int main(){
  int x[5];
  for(int i = 0; i < 5; i++) std::cin >> x[i];

  int min = 10;
  int min_iter = -1;
  int ret = 0;
  for(int i = 0; i < 5; i++){
    if(x[i]%10 < min && x[i]%10 != 0){
      min = x[i]%10;
      min_iter = i;
    }
  }
  for(int i = 0; i < 5; i++){
    if(i != min_iter){
      if(x[i]%10 == 0) ret += x[i];
      else ret += (x[i]/10 + 1)*10;
    }
    else ret += x[i];
  }

  std::cout << ret << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

#define say(args) cout << (args) << endl
#define rep(i, a) for (int i = 0; i < a; i++)

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> buttons(n);
  rep(i, n) {
    cin >> buttons[i];
    buttons[i] -= 1;
  }

  int index = 0, count = 0;
  while (index != 1) {
    index = buttons[index];
    count += 1;
    if (count > n) {
      count = -1;
      break;
    }
  }

  say(count);

}


Measured memory_bytes: 640
from operator import mul
from functools import reduce
 
 
def cmb(n, r):
    if r > n:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under
  
N,K= map(int, input().split())
red = N - K
for i in range(K):
    bluesc = cmb(K - 1 , i)
    redsc = cmb(red + 1 , i + 1) 
    ans = (redsc * bluesc) % (10**9+7)
    print(ans)

Measured memory_bytes: 3944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007
 
#define INF 999999
 
int dp[45][405][405];
 
int main(){
  int n,ma,mb;
  cin>>n>>ma>>mb;
  int a[n],b[n],c[n];
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
  }
  for(int i=0;i<=44;i++){
    for(int j=0;j<=404;j++){
      for(int k=0;k<=404;k++){
        if(j==0&&k==0) dp[i][j][k]=0;
        else dp[i][j][k]=INF;
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<=400;j++){
      for(int k=0;k<=400;k++){
        if(j<a[i] || k<b[i]){
          dp[i+1][j][k]=dp[i][j][k];
        }else{
          dp[i+1][j][k]=min(dp[i][j][k],dp[i][j-a[i]][k-b[i]]+c[i]);
        }
      }
    }
  }
 
  int ans=INF;
  for(int i=0;i<=n;i++){
    for(int j=1;j*ma<=400&&j*mb<=400;j++){
      ans=min(ans,dp[i][j*ma][j*mb]);
    }
  }
  if(ans==INF) cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 29184
def LIS(A):
    dp = [-A[0]]
    for a in A[1:]:
        if -a >= dp[-1]:
            dp.append(-a)
        else:
            dp[bisect_right(dp, -a)] = -a
    return len(dp)

##################################################################################################################

import sys
input = sys.stdin.readline
from bisect import *

N = int(input())

A = [int(input()) for _ in range(N)]

print(LIS(A))

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

using namespace std;

#define ll long long




void solve() {

	int n;
	cin >> n;
	int a[n + 1], b[n + 1];
	for(int i = 0; i < n + 1; i++) {
		cin >> a[i];
	}
	for(int i = 0; i < n; i++) {
		cin >> b[i];
	}
	b[n] = 0;
	ll total = 0;
	//a = monsters;
	//b = heroes
	for(int i = 0; i < n + 1; i++) { 
		int mn = min(a[i], b[i]);
		a[i] -= mn;
		b[i] -= mn;
		total += mn;
		if(i + 1 == n + 1) {
			break;
		}
		mn = min(a[i + 1], b[i]);
		a[i + 1] -= mn; 
		b[i] -= mn;
		total += mn;
	}
	cout << total << "\n";

	

	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

Measured memory_bytes: 4396
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;

void IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}

const int N=1e6+3,M=1e3+5,mod=1e9+7,dx[]={1,-1,0,0},
                                    dy[]={0,0,1,-1};
const double eps=1e-9;

int tc,n,a[N],d,x,k,ans;

char s[N];

bool ok[N];

int main(){
    //IO();
    scanf("%d%d",&n,&k);
    for(int i = 0 ; i < k ; i++){
        scanf("%d",&d);
        while(d--){
            scanf("%d",&x);
            ok[x] = true;
        }
    }
    for(int i = 1 ; i <= n ; i++)
        ans += !ok[i];
    printf("%d\n",ans);
}

Measured memory_bytes: 3832
#include<iostream>
#include<vector>
#include<map>
using namespace std;
using ll=long long;
int main() {
    int n;cin>>n;
    map<vector<int>,int> mp;
    for(int i=0;i<n;i++) {
        string s;
        cin>>s;
        vector<int> v(26);
        for(auto &c:s) v[c-'a']++;
        mp[v]++;
    }
    ll res=0;
    for(auto &e:mp)
        res+=ll(e.second)*(e.second-1)/2;
    cout<<res;
    return 0;
}

Measured memory_bytes: 18944
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;


int main()
{
	int n, t, a;
	cin >> n >> t >> a;
	long long h[1000];
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
	}

	double m = 100000000;
	int place = 0;
	for (int i = 0; i < n; i++) {
		double temp = t - h[i] * 0.006;
		double diff = abs(a - temp);
		if (diff < m)
		{
			m = diff;
			place = i + 1;
		}
	}

	cout << place;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int l;
    cin >> l;
    l--;
    if (l == 1) {
        cout << 2 << " " << 2 << '\n';
        cout << 1 << " " << 2 << " " << 0 << '\n';
        cout << 1 << " " << 2 << " " << 1 << '\n';
        return 0;
    }
    if (l == 2) {
        cout << 2 << " " << 3 << '\n';
        cout << 1 << " " << 2 << " " << 0 << '\n';
        cout << 1 << " " << 2 << " " << 1 << '\n';
        cout << 1 << " " << 2 << " " << 2 << '\n';
        return 0;
    }
    int n = 3, k = 7;
    while (k <= l) {
        n++;
        k *= 2;
        k++;
    }
    vector<vector<int>> ans;
    k = 0;
    for (int i = 0; i < n - 1; i++) {
        ans.push_back({i + 1, i + 2, 1 << (n - i - 2)});
        ans.push_back({i + 1, i + 2, 0});
        k += 1 << (n - i - 2);
    }
    debug(k);
    while (k < l) {
        k++;
        int d = l - k;
        if (d == 0) {
            ans.push_back({1, n, l});
            break;
        }
        if (d == 1) {
            ans.push_back({1, n, l});
            ans.push_back({1, n, l - 1});
            break;
        }
        if (d == 2) {
            ans.push_back({1, n, l});
            ans.push_back({1, n, l - 1});
            ans.push_back({1, n, l - 2});
            break;
        }
        int m = n - 2, e = 7;
        while (e <= d) {
            m--;
            e *= 2;
            e++;
        }
        ans.push_back({1, m, k});
        k += e / 2;
    }
    cout << n << " " << ans.size() << '\n';
    for (auto v : ans) {
        for (auto i : v) {
            cout << i << " ";
        }
        cout << '\n';
    }
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>       /* sqrt */
using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int ans[1001];

void PrimeFactorization(int a) {
	int j = 0;
	for(int n=a,ns=2; n>=ns; ns++ )
	{
		for(j=0; n%ns==0; j++ )            // 割り切れる間繰り返す
		{
			n/=ns;
		}
		if ( j==0 ) continue;               // 1回も割り切れなかった
		ans[ns] += j;
//		cout << ns << " " << j << "\n";
	}
}

int main()
{
	ll n;
	cin >> n;
	// 6 * 5 * 4 * 3 * 2 * 1
	// 720
	//
	for (int i = 0; i < 1001; i++) {
		ans[i] = 0;
	}
	for (int i = n; i > 0; i--) {
		PrimeFactorization(i);
	}

	ll a = 1;
	for (int i = 0; i < 1001; i++) {
		if (ans[i] != 0) {
			a = ((a*(ans[i]+1)%MOD));
//			cout << a << "\n";
		}
	}

	cout << a << "\n";

}


        // 2! = 2
        // 1,2      -> 2ko
        // 2 = 1,2

        // 3! = 6
        // 1,2,3,6  -> 4ko
        // 3-> 1,3


	// 4! = 24
	// 1,2,3,4,6,8,12,24 -> 8ko
        // 4 -> 1,2,4

        // 5! = 120
        //  1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120 -> 16 ko
        // 5 -> 1,2,5

        // 6!= 720
        //  1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 30, 36, 40, 45, 48, 60, 72, 80, 90, 120, 144, 180, 240, 360, 720 -> 30ko
        // 1,2,3,6


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, a, ganjil=0;
	scanf("%d", &n);
	while(n--) {
		scanf("%d", &a);
		if(a%2 == 1) ganjil++;
	}
	
	if(ganjil%2 == 1) printf("NO\n");
	else printf("YES\n");
	return 0;
}

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

long long npackages, ntrucks;
std::vector<long long> p;

bool is_solvable(int mid)
{
  long long truck = mid;
  long long cnt = 1;
  for (int i = 0; i < (int)p.size(); i++) {
    long long package = p.at(i);
    if (truck < package) {
      cnt++;
      truck = mid;
    }
    truck -= package;
    assert(0 <= truck);
    if (ntrucks < cnt) {
      return false;
    }
  }
  return true;
}

int main()
{
  std::cin >> npackages >> ntrucks;
  p.resize(npackages);
  for (int i = 0; i < (int)p.size(); i++) {
    std::cin >> p.at(i);
  }

  long long maxitem = *std::max_element(p.begin(), p.end());
  long long ng = maxitem-1;
  long long ok = maxitem * npackages;
  while (1 < abs(ok - ng)) {
    long long mid = (ok + ng) / 2;
    if (is_solvable(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  std::cout << ok << std::endl;
  return 0;
}



Measured memory_bytes: 3616
#include <iostream>
#include <string.h>

using namespace std;

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  
  if(K <= A)
    cout << K;
  else if(K <= A + B)
    cout << A;
  else
    cout << A-(K-A-B);
  }

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

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

    map<string, int> dic{};
    string s;
    for (int i=0; i<n; i++) {
        cin >> s;
        if (dic.end() != dic.find(s)){
            dic[s]++;
        }else{
            dic[s] = 1;
        }
    }

    int nmax=0;

    vector<string> anss;

    for(auto itr = dic.begin(); itr != dic.end(); ++itr) {
        
        if (nmax == itr->second) {
            anss.push_back(itr->first);
        } else if (nmax < itr->second) {
            anss.clear();
            anss.push_back(itr->first);
            nmax = itr->second;
        }
    }

    std::sort(anss.begin(), anss.end());

    for (int i=0; i<anss.size(); i++) {
        cout << anss.at(i) << endl;
    }
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;



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

    cin.tie(0);
    ios::sync_with_stdio(false);
   
    int n; cin >> n;
    vector<pair<int,int>> A;
    rep(i,n) {
        int a; cin >> a;
        A.push_back(make_pair(a,i+1));
    }
    sort(A.begin(),A.end());
    
    rep(i,n) {
        if(i<n-1) cout << A[i].second << " ";
        else cout << A[i].second << endl;
    }
    
    
    
}


Measured memory_bytes: 1780