akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;
const double PI = acos(-1);

#ifdef tejasp
#include "library/debugger.cpp"
#else
#define trace(...) {}
#define cotra(...) {}
#define end_routine() {}
#define localsys 0
#define endl '\n'
#endif

std::vector<vll> adj(500010);
vi dist(500010);

void dijkstra(int s, vi &d)
{
    d.assign(sz(d),mod);
    d[s] = 0;
    using PII = pair<int, int>;
    priority_queue<PII, vector<PII>, greater<PII>> q;
    q.push({0, s});
    while (!q.empty()) {
        int v = q.top().second;
        int d_v = q.top().first;
        q.pop();
        if (d_v != d[v])    continue;

        for (auto to : adj[v]) {
            if (d[v] + to.ss < d[to.ff]) {
                d[to.ff] = d[v] + to.ss;
                q.push({d[to.ff], to.ff});
            }
        }
    }
}


int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    map<pll,int> mp;
    cin>>n>>m;
    fol(i,0,m)
    {
        cin>>u>>v>>temp;
        if(mp.count({u,temp})==0) mp[{u,temp}]=n+(2*i)+1;
        if(mp.count({v,temp})==0) mp[{v,temp}]=n+(2*i)+2;
        adj[u].pb({mp[{u,temp}],1});
        adj[mp[{u,temp}]].pb({u,0});
        adj[v].pb({mp[{v,temp}],1});
        adj[mp[{v,temp}]].pb({v,0});
        adj[mp[{u,temp}]].pb({mp[{v,temp}],0});
        adj[mp[{v,temp}]].pb({mp[{u,temp}],0});
    }
    dijkstra(1,dist);
    if(dist[n]==mod) cout<<-1<<endl;
    else cout<<dist[n]<<endl;
    return 0;
}

signed main()
{
    #ifdef tejasp
            freopen("input.txt", "rt", stdin);
            freopen("output.txt", "wt", stdout);
    #endif
    if(!localsys) { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
    end_routine();
    if(localsys) system("pause");
}

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

using namespace std;


void Task() {
      string s;
      cin >> s;
      int ans = 7;
      if (s == "SAT") {
            ans = 1;
      }
      else if (s == "FRI") {
            ans = 2;
      }
      else if (s == "THU") {
            ans = 3;
      }
      else if (s == "WED") {
            ans = 4;
      }
      else if (s == "TUE") {
            ans = 5;
      }
      else if (s == "MON") {
            ans = 6;
      }
      cout << ans << endl;
}

signed main() {
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr); cout.tie(nullptr);

      int tc = 1;
      while (tc--) {
            Task();
      }
}


Measured memory_bytes: 3624
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)


Measured memory_bytes: 47360
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll sq(ll x) {return (x * x) % MOD;}
ll modP(ll a, ll b) {return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);}

queue <int> Q[3];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	for (int i = 0; i < 3; i++){
		string s; cin >> s;
		for (int j = 0; j < s.size(); j++){
			Q[i].push(s[j] - 'a');
		}
	}
	int x = 0;
	while (!Q[x].empty()){
		int t = Q[x].front();
		Q[x].pop();
		x = t;
	}
	cout << (char)('A' + x) << endl;
	return 0;
}



Measured memory_bytes: 256
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC diagnostic error "-std=c++14"

#define isNum(a) (a>='0'&&a<='9')
#define SP putchar(' ')
#define EL putchar('\n')
#define ri register int

template<class T>
inline void in(T&);
template<class T>
inline void out(const T&);

typedef long long ll;
using std::min;
using std::max;
using std::abs;
using std::sort;
using namespace std;

double n;

int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%lf",&n);
    printf("%.12lf\n",n*n*n/27.0);
    return 0;
}

template<class T>
void in(T &Re)
{
    T k=0;
    char ch=getchar();
    int flag=1;
    while (!isNum(ch))
	{
        if (ch=='-')
		{
            flag=-1;
        }
        ch=getchar();
    }
    while (isNum(ch))
	{
        k=(k<<1)+(k<<3)+ch-'0';
        ch=getchar();
    }
    Re=flag*k;
}

template<class T>
void out(const T &Wr)
{
    if (Wr<0)
	{
        putchar('-');
        out(-Wr);
    }
	else
	{
        if (Wr<10)
		{
            putchar(Wr+'0');
        }
		else
		{
            out(Wr/10);
            putchar((Wr%10)+'0');
        }
    }
}




Measured memory_bytes: 256
from itertools import accumulate
import sys
input = sys.stdin.readline

N = int(input())
t = list(accumulate([0] + list(map(int, input().split())) + [0]))
v = [0] + list(map(int, input().split())) + [0]
prev = 0
ans = 0
T = t[-1]
for i in range(0, 2*T+1):
    i /= 2
    cur = i
    for j in range(N+1):
        l = t[j]
        r = t[j+1]
        u = v[j+1]
        if i < l:
            cur = min(cur, u + (l - i))
        elif i > r:
            cur = min(cur, u + (i - r))
        else:
            cur = min(cur, u)
    ans += (prev + cur) / 4
    prev = cur
print(ans)

Measured memory_bytes: 42860
#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, k, q;
  cin >> n >> k >> q;
  map<int, int> mp;
  rep(i, q) {
    int a;
    cin >> a;
    a--;
    mp[a]++;
  }

  rep(i, n) {
    if (k - q + mp[i] > 0) {
      puts("Yes");
    } else {
      puts("No");
    }
  }
  return 0;
}


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

int main()
{
    int H, W, K;
    cin>>H>>W>>K;
    vector<string> S(H);
    for (string &s: S)
        cin>>s;

    int ans = (W-1)*(H-1);
    for (int b=0; b<1<<(H-1); b++)
    {
        int a = 0;
        for (int i=0; i<H-1; i++)
            a += b>>i&1;

        vector<int> P(H);
        int p = 0;
        for (int i=0; i<H; i++)
        {
            P[i] = p;
            if (b>>i&1)
                p++;
        }
        p++;

        bool okok = true;
        vector<int> C(p);
        vector<int> T(p);
        for (int x=0; x<W; x++)
        {
            for (int i=0; i<p; i++)
                T[i] = 0;
            for (int y=0; y<H; y++)
                T[P[y]] += S[y][x]-'0';
            bool ok = true;
            for (int i=0; i<p; i++)
                if (C[i]+T[i]>K)
                    ok = false;
            if (!ok)
            {
                a++;
                for (int i=0; i<p; i++)
                    C[i] = 0;
            }
            for (int i=0; i<p; i++)
                C[i] += T[i];
            for (int i=0; i<p; i++)
                if (C[i]>K)
                    okok = false;
        }
        if (okok)
            ans = min(ans, a);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	int pn = 1;
	if (*ci == '-') {
		pn = -pn;
		ci++;
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return pn * tmp;
}

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


	int N;
	N = getint();

	ll dp00 = 0;
	ll dp11 = 0;
	ll dp02 = -1e18;

	int n = N / 2;
	if (N % 2) {
		rep(i, n) {
			int a = getint();
			if (dp11 < dp00) dp11 = dp00;
			dp00 += a;
			dp02 += a;
			if (dp02 < dp11) dp02 = dp11;
			dp11 += getint();
		}
		if (dp11 < dp00) dp11 = dp00;
		dp02 += getint();
		if (dp02 < dp11) dp02 = dp11;
		printf("%lld\n", dp02);
	}
	else {
		rep(i, n) {
			if (dp11 < dp00) dp11 = dp00;
			dp00 += getint();
			dp11 += getint();
		}
		if (dp11 < dp00) dp11 = dp00;
		printf("%lld\n", dp11);
	}


	Would you please return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a%3==0 || b%3==0 || (a+b)%3==0)
        cout<<"Possible"<<endl;
    else
        cout<<"Impossible"<<endl;
    return 0;
}

Measured memory_bytes: 256
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li		int32_t
#define lli		long long
#define ulli unsigned long long

#define pn			 printf("\n")
#define nl			 cout<<'\n'
#define sf(N)        scanf("%lld",&N)
#define pf(N)        printf("%lld",N)
#define sf1(N1,N2)    scanf("%lld %lld",&N1,&N2)
#define pf1(N1,N2)    printf("%lld %lld",N1,N2)
#define sf2(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define pf2(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define sl          cout<<' '
#define ps          printf(" ")

#define rep(i,a,b)	for(i=a;i<b;i++)
#define repr(i,a,b)	for(i=a;i>b;i--)
#define elif		else if
#define mset(a,b)	memset(a,b,sizeof(a))

#define pb		push_back
#define pob		pop_back
#define itr		iterator
#define sz()	size()
#define szof    sizeof
#define lb		lower_bound
#define ub		upper_bound
#define mp		make_pair
#define vlli    vector<lli>
#define plli	pair<lli,lli>
#define vplli	vector<plli >
#define F   	first
#define S		second
#define Dup     erase(unique(V.begin(),V.end()),V.end())

#define bs      binary_search
#define ub      upper_bound
#define lb      lower_bound

#define ALL(V)  V.begin(),V.end()

#define MX1     100000
#define MX2     1000000
#define Inf     1000000000000000
#define mod		1000000007
using namespace std;

lli Power(lli a,lli b)
{
    lli result=1;

    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }

        b=b>>1;
        a=(a*a)%mod;
    }

 return result;
}

int main()
{
    opt;

    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // ONLINE_JUDGE*/

    string s;
    cin>>s;

    if(s[0]=='9' or s[1]=='9')
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }




 return 0;
}


Measured memory_bytes: 256
N, Y = map(int, input().split())
for x in range(N+1):
    for y in range(N-x+1):
        if (10000*x + 5000*y + 1000*(N-x-y) == Y) and (N-(x+y))>=0:
            print(x, y , N-(x+y))
            exit()
else:
    print('-1 -1 -1')

Measured memory_bytes: 8960
#pragma region Template

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <bitset>
#include<map>
#include<cmath>
#include <set>
#include<limits.h>
#include<fstream>

#define lli long long int
#define l long
#define us unsigned short
#define mod 1000000007

#define vi vector<int>
#define vus vector<unsigned short>
#define vlli vector<long long int>
#define vs vector<string>
#define mii map<int,int>

#define w(t) int t; cin>>t;while(t--)

using namespace std;

#pragma endregion

int main()
{
	lli n;
	vlli v(100006);
	vlli dp(100006);

	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> v[i];
	}

	dp[2] = abs(v[2]-v[1]);

	for(int i = 3; i <= n; i++)
	{
		dp[i] = min(dp[i-1]+abs(v[i]-v[i-1]), dp[i - 2] + abs(v[i] - v[i - 2]));
	}

	cout << dp[n] << endl;

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> stairs(n);
    vector<int> updated_stairs(n);
    for (int i=0;i<n;i++){
        cin >> stairs[i];
    }

    if (n==1){
        cout << "Yes" << endl;
    } else {
        updated_stairs[0] = stairs[0];
        int diff;
        string flag="Yes";
        for (int i=1;i<n;i++){
            diff = stairs[i] - updated_stairs[i-1];
            if (diff < 0){
                flag = "No";
                break;
            } else if (diff == 0){
                updated_stairs[i] = stairs[i];
            } else {
                updated_stairs[i] = stairs[i] - 1;
            }
        }
        cout << flag << endl;
    }
    return 0;

}

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

int main()
{
	int a;
	cin >> a;
	if( a < 1200 )
		cout << "ABC";
	else if ( a < 2800 )
		cout << "ARC";
	else
		cout << "AGC";
}

Measured memory_bytes: 3576
#include <stdio.h>
int main(void){
    int i,n;
    int a[100];
    scanf("%d\n",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=n-1;i>=0;--i){
        printf("%d",a[i]);
        if(i>0){
            putchar(' ');
        }
    }
    
    putchar('\n');
    
    return 0;
}


Measured memory_bytes: 2140
class RollingHash(object):
    """
        construct: O(N)
        query:
            hash: O(1)
            lcp: O(logN)
            search: O(N)
    """
    __base1 = 1007;
    __mod1 = 10 ** 9
    __base2 = 1009;
    __mod2 = 10 ** 7

    def __init__(self, s):
        n = len(s)
        self.__s = s
        self.__n = n
        b1 = self.__base1;
        m1 = self.__mod1
        b2 = self.__base2;
        m2 = self.__mod2
        H1, H2 = [0] * (n + 1), [0] * (n + 1)
        P1, P2 = [1] * (n + 1), [1] * (n + 1)
        for i in range(n):
            H1[i + 1] = (H1[i] * b1 + (s[i])) % m1
            H2[i + 1] = (H2[i] * b2 + (s[i])) % m2
            P1[i + 1] = P1[i] * b1 % m1
            P2[i + 1] = P2[i] * b2 % m2
        self.__H1 = H1
        self.__H2 = H2
        self.__P1 = P1
        self.__P2 = P2

    @property
    def str(self):
        return self.__s

    @property
    def len(self):
        return self.__n

    def hash(self, l, r=None):
        """
            l,r: int (0<=l<=r<=n)
            return (hash1,hash2) of S[l:r]
        """
        m1 = self.__mod1
        m2 = self.__mod2
        if r is None: r = self.__n
        assert 0 <= l <= r <= self.__n
        hash1 = (self.__H1[r] - self.__P1[r - l] * self.__H1[l] % m1) % m1
        hash2 = (self.__H2[r] - self.__P2[r - l] * self.__H2[l] % m2) % m2
        return hash1, hash2

    @classmethod
    def lcp(cls, rh1, rh2, l1, l2, r1=None, r2=None):
        """
            rh1,rh2: RollingHash object
            l1,l2,r1,r2: int 0<=l1<=r1<=r1.len, 0<=l2<=r2<=rh2.len
            return lcp length between rh1[l1:r1] and rh2[l2:r2]
        """
        if r1 is None: r1 = rh1.__n
        if r2 is None: r2 = rh2.__n
        assert 0 <= l1 <= r1 <= rh1.__n and 0 <= l2 <= r2 <= rh2.__n
        L = 0
        R = min(r1 - l1, r2 - l2)
        if rh1.hash(l1, l1 + R) == rh2.hash(l2, l2 + R): return R
        while R - L > 1:
            H = (L + R) // 2
            if rh1.hash(l1, l1 + H) == rh2.hash(l2, l2 + H): L = H
        else:
            R = H
        return L

    @classmethod
    def search(cls, pattern, text):
        """
        pattern,text: RollingHash object
        return list of index i's satisfying text[i:] starts with pattern
        """
        n = text.__n;
        m = pattern.__n
        res = []
        for i in range(n - m + 1):
            if text.hash(i, i + m) == pattern.hash(0, m):
                res.append(i)
        return res


def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    dA = [A[i] ^ A[(i + 1) % N] for i in range(N)]
    dB = [B[i] ^ B[(i + 1) % N] for i in range(N)]

    dA += dA
    # 今回は数字を扱うのでRollingHash: init() ord削除し対応
    RHa = RollingHash(dA)
    RHb = RollingHash(dB)
    query = RHb.hash(0, N - 1)
    ans = []
    for i in range(N):
        val = RHa.hash(i, i + N - 1)
        if val == query:
            ans.append((i, A[i] ^ B[0]))
    ans.sort()
    for k, x in ans:
        print(k, x)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 171404
import sys
import itertools

# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics


# bit を使ってci を管理する

def toBit(n): 
    return bin(eval('0b' + str(n)))

def main():

    n = int(sys.stdin.readline().rstrip())

    schedule = [toBit(''.join(str(x) for x in sys.stdin.readline().split())) for _ in range(n)]
    profit_table = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)]

    maximum_profit = -10**10
    for open_pattern in itertools.product('01', repeat=10):
        open_pattern = toBit(''.join(open_pattern))
        if open_pattern == '0b0':
            continue
        profit = 0
        for i in range(n):
            checked = schedule[i]
            number_of_periods = bin(eval(checked) & eval(open_pattern)).count('1')
            profit += profit_table[i][number_of_periods]
        maximum_profit = max(maximum_profit, profit)

    print(maximum_profit)

if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define mem(v,x) memset(v,x,sizeof(v))
#define N 100005

using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
    int n;
    cin>>n;
    ll sum = 0;
    int t = 0;
    for(int i=1;i<=n;i++){
        if(i%3!=0 && i%5!=0){
            sum+=i;
        }
    }
    cout<<sum;
	return 0;
}


Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10**6)

MOD = 10**9+7


def make_cmb_table(n):
    fact = [1]
    for i in range(1, n+1):
        fact.append(fact[i-1] * i % MOD)

    ifact = [0] * (n+1)
    ifact[n] = pow(fact[n], MOD-2, MOD)
    for i in range(n, 0, -1):
        ifact[i-1] = ifact[i] * i % MOD
    return (fact, ifact)


def combination(n, r, table):
    if r > n:
        return 0
    return table[0][n] * table[1][n - r] * table[1][r] % MOD


def permutation(n, k, table):
    return table[0][n] * table[1][n - k] % MOD


def main(input, print):
    n, m = map(int, input().split())
    ans = 0
    table = make_cmb_table(10**6+5)
    for i in range(n+1):
        now = combination(n, i, table)
        now %= MOD
        now *= (-1) ** i
        now *= permutation(m, i, table)
        now %= MOD
        now *= permutation(m-i, n-i, table) ** 2
        now %= MOD
        ans += now
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 157144
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;

int main()
{
	int N, K, d;
	std::vector<int> A;

	std::cin >> N >> K;

	for(int i=0; i<K; i++){
		std::cin >> d;
		for(int j=0; j<d; j++){
			int tmp;
			cin >> tmp;
			A.push_back(tmp);
		}
	}

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

	
	cout << N-A.size();

	return 0;
	
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i)  
#else
  #define DUMP(i)  
#endif

#define TOSTRING(x) #x
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define SZ(x) ((int) (x).size())
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;


int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  while(cin >> s){
    string sub = "";
    bool ans = true;
    string words[4] = {"dream", "dreamer" , "erase", "eraser"};
    REP(i,SZ(s)){
      sub = sub + s[i];
      if(sub.size() > 7){
	ans = false;
	break;
      }
      int next = i + 1;
      //eraserならこれ以上長くはならない
      if(sub == "eraser")sub = "";

      DUMP(sub == "dream");
      DUMP(s[next]);

      
      //eraseならeraserになる可能性がある
      if(sub == "erase"){
	if(next < SZ(s)){
	  //次の文字がrでない(eraseで止まるのが確定)
	  if(s[next] != 'r'){
	    sub = "";
	  }
	}
	//この文字で最後
	else{
	  sub = "";
	  break;
	}
      }
      //dreamerならdream + eraseかdreamerなのかわからない
      else if(sub == "dreamer"){
	if(next < SZ(s)){
	  //dreamer[a]ならdream,era...が確定
	  if(s[next] == 'a')sub = "er";
	  //dreamer[d]ならdrea...が始まってる
	  else if(s[next] == 'd'){
	    sub = "";
	  }
	  else if(s[next] == 'e') sub = "";
	}
	//この文字で最後
	else{
	  sub = "";
	  break;
	}
      }
      //dreamならこれで終わりかdreamerになるかわからない
      else if(sub == "dream"){
	if(next < SZ(s)){
	  //dream[d]ならdrea..が次に続く
	  if(s[next] == 'd'){
	    sub = "";
	  }
	  DUMP(sub);
	  //そうでないならdreamerの形に必ずなるので処理をしない

	  //この文字で最後
	}else{
	  sub = "";
	  break;
	}
      }
      DUMP(i);
      DUMP(sub);
    }
    DUMP(sub);
    if(sub != "") ans = false;
    if(ans)cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}


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

int main(){
    ll n;
    cin >> n;
    vector<ll> judge(4);
    for (int i = 0; i < 4; i++){
        judge[i] = 0;
    }
    string s;
    for (ll i = 0; i < n; i++){
        cin >> s;
        if (s == "AC"){
            judge[0]++;
        }else if(s == "WA"){
            judge[1]++;
        }else if(s == "TLE"){
            judge[2]++;
        }else{
            judge[3]++;
        }
    }
    cout << "AC" << " x " << judge[0] << endl;
    cout << "WA" << " x " << judge[1] << endl;
    cout << "TLE" << " x " << judge[2] << endl;
    cout << "RE" << " x " << judge[3] << endl;

    
}

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

typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back

int a[200005],vis[1000005];
int main() {
    int n;
    cin>>n;
    ii cin>>a[i],vis[a[i]]++;
    sort(al(a));
    int cnt=0;
    for(int i=1;i<=n;++i) {
        int ok=1;
        if(vis[a[i]]>1) ok=0;
        for(int j=1;j*j<=a[i];++j) {
            if(a[i]%j) continue;
            if(j!=a[i] && vis[j]) ok=0;
            if(a[i]/j!=a[i] && vis[a[i]/j]) ok=0;
            if(!ok) break;
        }
        cnt+=ok;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 8140
#include<bits/stdc++.h>
using namespace std;
int n,a[100007],dp[100007];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	dp[1]=0;
	dp[0]=1e9+7;
	for(int i=2;i<=n;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n];
}

Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
int main (){
    vector < int > num;
    int a,b,c,n;
    cin>>a>>b>>c;
    cin>>n;
    num.push_back(a);
    num.push_back(b);
    num.push_back(c);
    sort(num.begin(),num.end());
    for(int i=0;i<n;i++){
        num[2] = num[2]*2;
    }
    cout<<num[0]+num[1]+num[2]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
void print(int A[], int n)
{
    int i;
    for (i = 0; i < n; i++)
    {
        printf("%d", A[i]);
        if (i < n - 1)
            printf(" ");
    }
    printf("\n");
}
void InsertionSort(int A[], int n)
{
    int i, j, v;
    for (i = 1; i <= n - 1; i++)
    {
        v = A[i];
        j = i - 1;
        while (A[j] > v && j >= 0)
        {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        print(A, n);
    }
}

int main()
{
    int A[100], N, i;
    scanf("%d", &N);
    for (i = 0; i < N; i++)
        scanf("%d", &A[i]);
    print(A, N);
    InsertionSort(A, N);
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
//#define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
//rep(i, v.size()) v[i]=i;
#define int long long
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>

using namespace std;

signed main(){
  int a, b;
  cin >> a >> b;
  if(a == 1 || b == 1)cout << 1 << endl;
  else if(a * b % 2 == 0)cout << (a * b) / 2 << endl;
  else cout << ((a * b) / 2 ) + 1 << endl;
}


Measured memory_bytes: 256
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,K = map(int,S().split())
A = LI()

from itertools import accumulate

ANS = A+[0]

for i in range(K):
    B = [0]*(N+1)
    for j in range(N):
        B[max(0,j-ANS[j])] += 1
        B[min(N,j+ANS[j]+1)] -= 1
    ANS = list(accumulate(B))
    for i in range(N):
        if ANS[i] != N:
            break
    else:
        break

del ANS[N]
print(*ANS)

Measured memory_bytes: 179056
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<numeric>
using namespace std;

int main(){
  string str;
  int a;
  int x = 0;
  int max= 0;
  cin >> a >> str;
  for(std::string::iterator it = str.begin(); it != str.end(); ++it) {
   if(*it == 'I'){
    x++;
    if(x > max){
     max = x;
    }
   }else if(*it == 'D'){
    x--;
   }
  }
  cout << max;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define int long long 
#define f(i,a,b) for (int i= a; i <b; ++i)
using namespace std;
int solve(int h[],int b[],int n)
{
    int dp[n];
    dp[0]=b[0];
    map<int,int> m;
    m[h[0]]=dp[0];
    int ans=b[0];
    for(int i=1;i<n;i++)
    {
        dp[i]=b[i];
        auto it=m.upper_bound(h[i]);
        if(it!=m.begin())
        {
            it--;
            dp[i]+=it->second;
        }
        m[h[i]]=dp[i];
        ans=max(ans,dp[i]);
        it=m.upper_bound(h[i]);
        while(it!=m.end()&&it->second<=dp[i])
        {
            auto temp=it;
            temp++;
            m.erase(it);
            it=temp;
        }
    }
    return ans;
}
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int h[n],b[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    cout<<solve(h,b,n);
}



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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

// policy-based
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;	


using namespace std;


typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
 
const ll MAX = 1e6+1;
const ll inf = 1e12;

int main(){
	ll n,l,r,d;
	cin >> l>>r>>d;
	ll ans = 0;
	f(i,l,r+1) if(i%d == 0) ans++;
	cout << ans << endl;

}



Measured memory_bytes: 3560
#include <stdio.h>

int main()
{
	int a[30];
	int w,n,i,an,bn,nazo;
	scanf("%d",&w);
	for(i=0;i<w;i++)a[i]=i+1;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	scanf("%d,%d",&an,&bn);
	nazo=a[an-1];a[an-1]=a[bn-1];a[bn-1]=nazo;
	}
	for(i=0;i<w;i++)printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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; }

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

    int p, q, r; cin >> p >> q >> r;
    int ans = 1e9;
    ans = min(p + q, ans);
    ans = min(q + r, ans);
    ans = min(r + p, ans);
    COUT(ans);
}

Measured memory_bytes: 256
from collections import deque
x,y,a,b,c = map(int,input().split())
red = [int(i) for i in input().split()]
g = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]
red.sort(reverse=True)
g.sort(reverse=True)
g = g[:y]
gw = g+w
gw.sort(reverse=True)
gwrui = []
rui = 0
for i in range(y+c):
    rui += gw[i]
    gwrui.append(rui)
red = red[:x]
rrui = []
rui = 0
for i in range(x):
    rui += red[i]
    rrui.append(rui)
rrui = [0] + rrui
ans = 0
oisr = 0
lgw = len(gw)
#print(red,gw,gwrui)
for i in range(0,x+1):
    temp = rrui[i]
    if x+y-i <= lgw:
        temp += gwrui[x+y-i-1]
        ans = max(ans,temp)
print(ans)

Measured memory_bytes: 31784
# coding: utf-8
# Your code here!
n=int(input())
ans=[]
num=[]
total=0
for i in range(2):
    a=input().split(" ")
    b=[]
    for j in range(n):
        b.append(int(a[j]))
        total+=int(a[j])
    num.append(b)
for i in range(n):
    sum=0
    if i==0:
        for j in range(1,n):
            sum+=num[0][j]
        ans.append(sum)
    elif i==n-1:
        for j in range(0,n-1):
            sum+=num[1][j]
        ans.append(sum)
    else:
        for j in range(i):
            sum+=num[1][j]
        for k in range(i+1,n):
            sum+=num[0][k]
        ans.append(sum)
print(total-min(ans))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
typedef long long ll;

int main() {
    ll a,b,k;
    cin >> a >> b >> k;
    ll mi = min(a, k);
    a -= mi;
    k -= mi;
    mi = min(b, k);
    b -= mi;
    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>

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

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

void dfs(ll i,ll n,int* num){
	if(i>n){
		return;
	}

	string temp=to_string(i);
	int num_3=0,num_5=0,num_7=0;
	rep(l0,temp.size()){
		if(temp[l0]=='3'){
			num_3++;
		}
		if(temp[l0]=='5'){
			num_5++;
		}
		if(temp[l0]=='7'){
			num_7++;
		}
	}
	if(num_3>0 & num_5>0 & num_7>0){
		(*num)++;
	}

	dfs(i*10+3,n,num);
	dfs(i*10+5,n,num);
	dfs(i*10+7,n,num);
}

int main() {
	ll n;
	cin >> n;
	int number=0;
	dfs(0,n,&number);
	cout << number << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
using namespace std;
int main() {
    int n, q; scanf("%d%d", &n, &q);
    while (q --) {
        int i, j; scanf("%d%d", &i, &j); -- i; -- j;
        if (n == 1) {
            i = j = min(i, j);
        } else {
            while (i != j) {
                ((i > j ? i : j) -= 1) /= n;
            }
        }
        printf("%d\n", i + 1);
    }
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
using ll = long long;
using ull = unsigned long long;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<ll>> vvl;
typedef vector<vector<string>> vvs;
typedef vector<bool> vb;
const ll md = 1000000007;
vector<ll> fact(1e6 + 7), invfact(1e6 + 7);

ll fn(ll a, ll r, ll n, ll mod = md) {
    ll res = 1, x = r%mod;
    ll ans = 0;
    while(n) {
        if(n&1) ans = (x*ans + res)%mod;
        res = ((res*x)%mod + res%mod)%mod;
        x = (x*x)%mod;
        n = n/2;
    }
    ans = (ans*a)%mod;
    return ans;
}

ll nCr(ll n, ll r) {
    if(r == 0) return 1;
    ll num = fact[n];
    ll den = (invfact[r] % md *invfact[n-r] % md)%md;
    return (num*den)%md;
}

ll mul(ll a, ll b, ll mod = md) {
    ll res = (a%mod * b%mod)%mod;
    return res;
}

ll mulm(ll a, ll b, ll mod = md) {
    ll r = 0;
    a %= mod;
    while (b) {
        if (b & 1) r = (r+a)%mod;
        a = (a+a)%mod;
        b = b/2;
    }
    r %= mod;
    return r;
}

ll power(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = n/2;
        x = (x*x)%mod;
    }
    return res;
}

ll power2(ll x, ll n) {
    ll res = 1;
    while (n)  
    {  
        if (n & 1)  res = (res*x);  
        n = n/2; 
        x = (x*x);  
    }  
    return res;
}

bool is_prime(ll x) {
    if(x == 1 || x == 0) return false;
    for(int i=2; i*i <= x; i++) {
        if(x%i == 0) return false;
    }
    return true;
}

ll compgcd(ll n, vector<ll> const &primes) { 
    ll res = n; 
    for (ll i=0; primes[i]*primes[i] <= n; i++) {
        if (n % primes[i]== 0) { 
            res -= (res / primes[i]); 
            while (n%primes[i]== 0) {
               n/=primes[i]; 
            }
        } 
    } 
    if (n > 1) {
       res -= (res / n); 
    }
    return res; 
} 

void sieve(vector<bool> &prime, vector<ll> &primes, ll lim) {
    for(int i = 2; i*i <= lim; i++) {
        if(prime[i]) {
            for(int j = 2; j*i <= lim; j++) {
                prime[j*i] = false;
            }
        }
    }
    for(int i = 2; i <= lim; i++) {
        if(prime[i]) {
            primes.push_back(i);
        }
    }
}

void sieveGCD(ll lim, vector<ll> &tab, vector<ll> const &primes) {
    for(int  i = 1; i <= lim; i++) {
        tab[i] = i;
    }
    for(int i = 0; i<primes.size() && primes[i] <= lim; i++) {
        tab[primes[i]] = primes[i]-1;
        for(int j = 2; primes[i]*j <= lim; j++) {
            tab[primes[i]*j] = (tab[primes[i]*j]/primes[i])*(primes[i]-1);
        }
    }
}

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a+b) {
        cout << min(k,a) << endl;
    } else {
        ll sum = a;
        k -= (a+b);
        sum -= k;
        cout << sum << endl;
    }
    return 0; 
}

Measured memory_bytes: 18652
s = input()
aa = int(s[:2])
bb = int(s[2:])
aa_mm = False
bb_mm = False
if 1 <= aa <= 12:
    aa_mm = True
if 1 <= bb <= 12:
    bb_mm = True
if aa_mm and bb_mm:
    print("AMBIGUOUS")
elif bb_mm:
    print("YYMM")
elif aa_mm:
    print("MMYY")
else:
    print("NA")

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

int main() {
	int n, x;
	cin >> n >> x;
	vector<long long> price(n), pages(n);
	for (int i = 0; i < n; i++) {
		cin >> price[i] >> pages[i];
	}
	vector<long long> dp(x + 1, 0);
	for (int i = 0; i < n; i++) {
		for (int j = x; j >= price[i]; j--)
			dp[j] = max(dp[j] , pages[i] + dp[j - price[i]]);
	}
	cout << dp[x] << endl;

}

Measured memory_bytes: 4032
#include<iostream>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
vector<vector<int>>adj(1e5+1);
int n;
vector<int> bfs(int i){
    queue<int> q;
    q.push(i);
    vector<int> visit(n+1,0);
    vector<int> ans(n+1,1e6);
    ans[1]=0;
    while(!q.empty()){
        int st=q.front();
        q.pop();
        visit[st]=1;
        for(auto j:adj[st]){
            if(visit[j]==0){
                visit[j]=1;
                q.push(j);
                ans[j]=st;
            }
        }
    }
    return ans;
}
int main(){
    int m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector<int> ans=bfs(1);
    for(int i=2;i<=n;i++)if(ans[i]==1e6) {
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    for(int i=2;i<=n;i++)cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 10676
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};

int main(){
    ll a, b, c, d; cin >> a >> b >> c >> d;

    ll ansac = a * c;
    ll ansad = a * d;
    ll ansbc = b * c;
    ll ansbd = b * d;

    cout << max(ansac,max(ansad,max(ansbc,ansbd)));



}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,N;
  cin>>N;
  A=N/100;
  B=(N-A*100)/10;
  C=N%10;
  if(A==7||B==7||C==7)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include<functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <stack>

#define LL long long
#define pii pair<int,int>
#define pLL pair<LL,LL>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<LL>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<LL>
#define vecpii vector<pii>
#define vecpLL vector<pLL>
#define vecbL vector<bool>
#define endl "\n"
#define REP(e,v) for(auto e:v)
#define rep(i, a, n) for(LL i = a; i < n;i++)

using namespace std;

int inp(){
	int x;
	scanf("%d",&x);
	return x;
}
LL linp(){
	LL x;
	scanf("%lld",&x);
	return x;
}

void outp(int i){
	printf("%d",i);
}

void loutp(LL i){
	printf("%lld",i);
}

LL mod(LL i){
	return i % 1000000007;
}


int gcd(int i,int j){
	if(j != 0)
		return gcd(j, i % j);
	else
		return i;

}

int ABC_swap(){
	LL X =linp();
	LL Y =linp();
	LL Z =linp();

	printf("%lld %lld %lld", Z, X, Y);
	return 0;
}

int Popular_vote(){

	 LL N ,M;

	 N = linp();
	 M = linp();

	 priority_queue<LL, vector<LL> > que;

	 int sumV = 0;

	 rep(i , 0, N){
		 LL in = linp();
		que.push(in);
		 sumV += in;
	 }


	 int count = 0;
	 double canV = (double)sumV /( 4.0 * M);

	 while(que.top() >= canV && !que.empty()){
	 	 	count++;
	 	 	que.pop();
	 }

	 if(count >= M){
		 printf("Yes\n");
	 }
	 else{
		 printf("No\n");
	 }


	 return 0;
}

signed main() {

	//ABC_swap();
	Popular_vote();
	return 0;
}



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

int main() {
	int a, b, c;
	int x, y;

	cin >> a >> b >> c >> x >> y;

	int sum = 0;
	if (a + b < c * 2) {
		sum += a * x + b * y;
	}
	else {
		sum += min(x, y) * 2 * c;

		int d;
		if (x == min(x, y)) {
			d = b;
		}
		else {
			d = a;
		}

		if (d < c * 2) {
			sum += d * (max(x, y) - min(x, y));
		}
		else {
			sum += c * 2 * (max(x, y) - min(x, y));
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<map>
#include<bitset>
#include<assert.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<set>
#include<queue>
#define long long long
using namespace std;
const int N=1e6,mod=1e9+7;
int aa[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n,k;cin>>n>>k;
  if(k==1||k==n+n-1)cout<<"No\n",exit(0);
  cout<<"Yes\n";

  aa[n]=k;aa[n-1]=k-1;aa[n+1]=k+1;
  int cnt=0;
  for(int i=1;i<=n+n-1;i++)
  {
    if(aa[i])continue;cnt++;
    if(cnt>=k-1&&cnt<=k+1){i--;continue;}
    aa[i]=cnt;
  }
  for(int i=1;i<=n+n-1;i++)cout<<aa[i]<<" ";cout<<endl;
  return 0;
}

Measured memory_bytes: 2432
#include <iostream>
using namespace std;
int main(void)
{
	double we;
	while(scanf("%lf",&we)!=EOF){
		if(we<=48) cout<<"light fly" << endl;
		else if(48<we&&we<=51) cout<<"fly"<<endl;
		else if(51<we&&we<=54) cout<<"bantam"<<endl;
		else if(54<we&&we<=57) cout<<"feather"<<endl;
		else if(57<we&&we<=60) cout<<"light"<<endl;
		else if(60<we&&we<=64) cout<<"light welter"<<endl;
		else if(64<we&&we<=69) cout<<"welter"<<endl;
		else if(69<we&&we<=75) cout<<"light middle"<<endl;
		else if(75<we&&we<=81) cout<<"middle"<<endl;
		else if(81<we&&we<=91) cout<<"light heavy"<<endl;
		else if(91<we) cout<<"heavy"<<endl;
	}
	return 0;
}

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

#define ll long long int
#define inv(name,Type,size) vector<Type> name(size);for(int index=0;index<size;index++) cin>>name[index];
#define F(a,n,i) for(int i=a;i<n;i++)
#define FLL(a,n,i) for(long long int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()

const int mod=1000000007;
const int modpro=988244353;

const int di[8]={-1,0,1,0,-1,1,1,-1},dj[8]={0,1,0,-1,1,1,-1,-1};


void solve(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans = a*c;
	ans = max(ans,a*d);
	ans = max(ans,b*c);
	ans = max(ans,b*d);
	cout<<ans;
}

int main()
{

  //freopen("out", "w", stdout);
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  //int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();
  
  cerr<<endl << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << " ms\n";
}



Measured memory_bytes: 3784
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int k, n;cin >> k >> n;
	vector<int> a(n),b(n);
	rep(i, n) {
		cin >> a[i];
		if (i != 0) b[i] = a[i] - a[i - 1];
	}
	b[0] = k - a[n - 1] + a[0];
	sort(b.begin(), b.end());
	ll sum = 0;
	rep(i, n - 1) {
		sum += b[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 1920
def c_flip(N, M):
    if N == 1 and M == 1:
        # 1枚のカードが1回裏返される
        return 1
    elif N == 1 or M == 1:
        # 1列の両端のカードは2回、その他のカードは3回裏返される
        return max(N, M) - 2
    else:
        # 四隅は4回、その他の周上は6回、それ以外は9回裏返される
        return (N - 2) * (M - 2)
    return None 

N,M = [int(i) for i in input().split()]
print(c_flip(N, M))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(a) cout<<#a<<":"<<a<<endl;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll N=1e6+7;
const ll mod=1e9+7;
ll maxn,minn;
ll T,n;
ll W;
ll dp[N];
ll w[N];
ll v[N];

int main() {
	cin>>n>>W;
	for(ll i=1;i<=n;i++) {
		scanf("%lld%lld",w+i,v+i);
	}
	memset(dp,INF,sizeof(dp));
	maxn=0;
	dp[0]=0;
	for(ll i=1; i<=n; i++) {
		for(ll j=N/10+1; j>=v[i];j--) {
			dp[j]=min(dp[j-v[i]]+w[i],dp[j]);
			if(dp[j]<=W){
				maxn=max(maxn,j);
			}
		}
	}
	cout<<maxn<<endl;


	return 0;
}





Measured memory_bytes: 11392
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>

using namespace std;


int main() {

	int N, M;
	cin >> N >> M;
	if (N == M) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}



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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int a, b, c;
    cin>>a>>b>>c;
    if(a > b) swap(a, b);
    if(b > c) swap(b, c);
    if(a > b) swap(a, b);
    cout<<a<<' '<<b<<' '<<c<<'\n';
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

int main(){
    int x, a, b;
    cin >> x >> a >> b;

    if(abs(x-a) > abs(x-b)) cout << "B" << endl;
    else cout << "A" << endl;
}

Measured memory_bytes: 256