akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
  int a, b, x;
  cin >> a >> b >> x;
  int wholeVolume = a * a * b;
  if (x == wholeVolume / 2)
    cout << (double)45 << endl;
  else if (x > wholeVolume / 2)
  {
    double h = double(wholeVolume - x) * 2 / (a * a);
    cout << setprecision(15) << (atan(h / a) * 180 / M_PI) << endl;
  }
  else
  {
    double anotherA = double(x) * 2 / (b * a);
    cout << setprecision(15) << (atan(b / anotherA) * 180 / M_PI) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << 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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int a; cin>>a;
    cout << a + a*a + a*a*a << '\n';
    return 0;
}

Measured memory_bytes: 3500
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)


struct Problem {
	const ULL M = 1000000007;

	void Solve() {
		UL N; cin >> N;
		vector<UL> E, Ssz;
		E.assign(N, (UL)-1);
		Ssz.assign(N, 1);
		{
			vector<vector<UL>> e(N);
			vector<UL> Eswap;
			Eswap.assign(N, (UL)-1);
			rep(i, N - 1) {
				UL a, b; cin >> a >> b; a--; b--;
				e[a].push_back(b);
				e[b].push_back(a);
			}
			queue<pair<UL, UL>> q; q.push({ 0, 0 });
			{
				UL i = 0;
				while (q.size()) {
					auto p = q.front(); q.pop();
					if (Eswap[p.first] != (UL)-1) continue;
					Eswap[p.first] = i;
					E[i] = Eswap[p.second];
					for (UL nx : e[p.first]) q.push({ nx, p.first });
					i++;
				}
			}
		}

		vector<ULL> ipow2(N + 1);
		ipow2[0] = 1;
		rep(i, N) ipow2[i + 1] = ipow2[i] * 500000004 % M;

		for (UL i = N - 1; i > 0; i--) { Ssz[E[i]] += Ssz[i]; }

		vector<ULL> dp1, dp2, dp3;
		ULL off = M - ipow2[N];
		//cout << "off = " << off << endl;
		dp1.assign(N, ipow2[1] + off);
		dp2.assign(N, 0);
		dp3.assign(N, 0);
		for (UL i = N - 1; i != (UL)-1; i--) {
			ULL JOI = ipow2[N - Ssz[i]];
			ULL joi = ipow2[Ssz[i]];

			dp1[i] += M - ipow2[Ssz[i]] + ipow2[N];
			dp2[i] += dp1[i];
			dp2[i] %= M;
			if (i != 0) {
				dp1[E[i]] += M - ipow2[N - Ssz[i]] + ipow2[N];
				dp2[E[i]] += dp2[i];
			}
		}
		/*
		rep(i, N)
			cout << dp1[i] % M << " ";
		cout << endl;
		rep(i, N)
			cout << dp2[i] << " ";
		cout << endl;
		*/
		cout << dp2[0] << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 14324
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


int ask(string x){
  cout << "? " << x << endl;
  int pom;
  cin >> pom;
  return pom;
}

vector<char> alfa;
int n;
vector<string> ak;
const int LIML = 128;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  for(char x ='a';x<='z';x++)alfa.PB(x);
  for(char x ='A';x<='Z';x++)alfa.PB(x);
  for(char x ='0';x<='9';x++)alfa.PB(x);
  n = SZ(alfa);
  int dl = 0;
  R(i,n){
    string pom(LIML,alfa[i]);
    int res = LIML - ask(pom);
    if(res != 0){
      ak.PB(string(res,alfa[i]));
      dl += res;
    }
  }
  while(SZ(ak) > 1){
    sort(ALL(ak),[](string &a, string &b){
      return SZ(a) > SZ(b);
    });
    string x = ak.back();ak.pop_back();
    string y = ak.back();ak.pop_back();
    int i = 0;
    int j = 0;
    string pom;
    while(i < SZ(x) && j < SZ(y)){
      pom += y[j];
      string zap = pom + x.substr(i);
      int res = ask(zap);
      if(res + SZ(zap) == dl){
        j++;
      }else{
        pom.back() = x[i];
        i++;
      }
    }
    if(i != SZ(x))
      pom += x.substr(i);
    if(j != SZ(y))
      pom += y.substr(j);
    ak.PB(pom);
  }
  cout << "! " << ak[0] << endl;
}


Measured memory_bytes: 3800
N = int(input())
W = [0]*N
for i in range(N):
    W[i] = str(input())

flag = "Yes"

for i in range(1,N):
    if W[i][0] != W[i-1][-1]:
        flag = "No"

if len(W) != len(set(W)):
    flag = "No"
    
print(flag)


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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min(a,b)
#define rmax(a,b) a = max(a,b)

#define fi first
#define se second

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

ll n, m;
int valid(int i, int j){
	return i>=0 and i<n and j>=0 and j<m;
}

const ll N = 3e3+10;
ll mat[N][N];

ll dp[N][N][4];

ll rec(ll i, ll j, ll ac){
	if(i==n or j==m) return 0;
	ll &ans = dp[i][j][ac];
	if(ans!=-1) return ans;
	
	ans = 0;
	
	if(ac==3) rmax(ans,rec(i+1,j,0)), rmax(ans,rec(i,j+1,ac));
	else{
		rmax(ans, mat[i][j] + rec(i+1,j,0));
		rmax(ans, rec(i+1,j,0));
		
		rmax(ans, mat[i][j] + rec(i,j+1,ac+1));
		rmax(ans, rec(i,j+1,ac));
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	ll k;	
	cin >> n >> m >> k;
	
	fr(i,n) fr(j,m) fr(ac,4) dp[i][j][ac] = -1;

	
	fr(kk,k){
		ll i, j, val; cin >> i >> j >> val; i--,j--;
		mat[i][j] = val;
	}
	
	cout << rec(0,0,0) << "\n";
}


Measured memory_bytes: 356736
H,W = map(int,input().split())
MIN = 10**11
S1 = 0
S2 =  0
S3 = 0
if H%3 == 0 or W %3==0:
    print(0)
else:
    for i in range(1,H):
        S1 = i * W
        S2 = (H-i)*(W//2)
        S3 = (H-i)*(W - W//2)
        MIN = min(MIN, max(S1,S2,S3)- min(S1,S2,S3))
        
    for i in range(1,W):
        S1 = i * H
        S2 = (W-i)*(H//2)
        S3 = (W-i)*(H - H//2)
        MIN = min(MIN, max(S1,S2,S3)- min(S1,S2,S3))
        
    for i in range(1,H):
        S1 = i*W
        S2 = ((H-i)//2)*W
        S3 = H*W - S1-S2
        MIN = min(MIN, max(S1,S2,S3)- min(S1,S2,S3))
    
    for i in range(1,H):
        S1 = i*H
        S2 = ((W-i)//2) *H
        S3 = H*W - S1-S2
        MIN = min(MIN, max(S1,S2,S3)- min(S1,S2,S3))
        
    print(MIN)
       

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include "sstream"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const int N=3e5+1;
vector<int>vc;
int main() {
  //read editorial its strange
    quick
int h,n,x,y,mx=0,idx=INT_MAX;
    cin>>n>>h;
while(n--){
    cin>>x>>y; vc.push_back(y);
  if(x>mx)
      mx=x,idx=y;
  else if(x==mx){idx=min(y,idx);}

}
sort(vc.begin(),vc.end(),greater<int>());
int ans=0;
for(int i=0;i<vc.size();i++){
    if(h<=0){break;}
    else if(vc[i]>=mx)
        h-=vc[i],ans++;
    else{break;}
}
if(h<=0){ return cout<<ans,0;}
if(h%mx){ans++;}
cout<<ans+(h/mx);
}

Measured memory_bytes: 892
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

#define EPS 1e-8
#define EQ(a, b) (abs((a)-(b)) < EPS)

typedef complex<double> P;

double cross(P a, P b) {
    return a.real() * b.imag() - a.imag() * b.real();
}

double dot(P a, P b) {
    return a.real() * b.real() + a.imag() * b.imag();
}

int ccw(P p0, P p1, P p2) {
    p1 -= p0;
    p2 -= p0;
    if (cross(p1, p2) > EPS) return 1; //ccw
    if (cross(p1, p2) < -EPS) return -1; //cw
    if (dot(p1, p2) < -EPS) return 2; //left
    if (abs(p1) < abs(p2)) return -2; //right
    return 0; //mid
}

bool is_parallel(P p0, P p1, P p2, P p3) {
    P x = p1 - p0;
    P y = p3 - p2;
    return EQ(cross(x, y), 0.0);
}

bool is_orthogonal(P p0, P p1, P p2, P p3) {
    P x = p1 - p0;
    P y = p3 - p2;
    return EQ(dot(x, y), 0.0);
}

int main() {

    int Q;
    cin >> Q;

    while (Q--) {

        vector<P> p(4);
        for (int i = 0; i < 4; i++) {
            double x, y;
            cin >> x >> y;
            p[i] = P(x, y);
        }

        int ans = 0;
        if (is_parallel(p[0], p[1], p[2], p[3]))ans = 2;
        if (is_orthogonal(p[0], p[1], p[2], p[3]))ans = 1;

        cout << ans << endl;

    }

    return 0;
}














































Measured memory_bytes: 3212
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    string S;
    cin >> S;
    int ret = 0;
    FOR(i, 1, S.size())
        if (S[i] != S[i - 1])
            ret++;
    cout << ret << endl;
    return 0;
};


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

using ll = long long;
using namespace std;


int main(void){
    int n, k;

    ll ans = 0;

    cin >> n >> k;
    vector<ll> num(k, 0);
    for (int i = 1; i <= n; ++i) num[i%k]++;

    for(int a=0; a<k; a++){
        int b = (k-a)%k;  //b%k
        int c = (k-a)%k;  //c%k

        if((b+c)%k == 0){
            ll s_a = n/k + ((n%k >= a && a != 0)?1:0);
            ll s_bc = n/k + ((n%k >= b && b != 0)?1:0);
          
            ans += s_a*s_bc*s_bc;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<(int)N;i++)
 
int main() {
  int N, Alice=0, Bob=0;
  vector<int> card(111);
  cin >> N;
  rep(i,N){cin >> card.at(i);}
  sort(card.begin(),card.end(),greater<int>());
  rep(j,N)
  {
    if(j%2==0) Alice=Alice+card.at(j);
    else Bob=Bob+card.at(j);
  }
  cout << endl << Alice-Bob << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <fstream>
#define MAXSIZE 100010
#define MAXN 10
#define MAXND MAXN / 10
#define INF 99999999
#define MAXEDGE 1000000
#define MAXVERTEX 510
#define EPS 0.00001
#define PI 3.14159265
#define MOD 1000000009
#define nil NULL
typedef long long ll;
using namespace std;

int n, m;
int p[MAXSIZE], vis[MAXSIZE], mark[MAXSIZE];
vector<int> mp[MAXSIZE];

void add(int u, int v) {
    mp[u].push_back(v);
    mp[v].push_back(u);
}

int bfs(int start) {
    memset(mark, 0, sizeof(mark));
    vector<int> q;
    int head = 0;
    q.push_back(start);
    vis[start] = 1;
    mark[p[start]] = 1;
    
    while (head < q.size()) {
        int u = q[head];
        head++;
        
        for (int i = 0; i < mp[u].size(); i++) {
            int v = mp[u][i];
            if (!vis[v]) {
                q.push_back(v);
                vis[v] = 1;
                mark[p[v]] = 1;
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i < q.size(); i++) {
        if (mark[q[i]]) {
            ans++;
        }
    }
    return ans;
}

int main() {
    int x, y, ans = 0;
    
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &p[i]);
    }
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &x, &y);
        add(x, y);
    }
    
    for (int i = 1; i <= n; i++) {
        if (mp[i].size() == 0) {
            if (p[i] == i) {
                ans++;
            }
        } else {
            if (!vis[i]) {
                ans += bfs(i);
            }
        }
    }
    
    printf("%d", ans);
    
    return 0;
}


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

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


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split(" ")]
a = [a[i] - (i + 1) for i in range(0, n)]
a = sorted(a)

if n % 2 == 0:
    print(-1 * sum(a[0:n//2]) + sum(a[n//2:]))
else:
    print(-1 * sum(a[0:n//2]) + sum(a[n//2 + 1:]))

Measured memory_bytes: 26180
#include<stdio.h>
#include<stdlib.h>

int main(){
	int x,y;
	while(~scanf("%d%d",&x,&y)){
		x=abs(x);
		y=abs(y);
		int ans;
		if(x+y==1)ans=1;
		else if((x+y)%2==0)ans=x+y-(x%2?1:0);
		else ans=x+y+(x==0||y==0?1:0);
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
int mn,mx;
main()
{
	scanf("%d%d",&mn,&mx);
	int to=min(0,mx+1)-min(0,mn);
	if(mn<=0 && mx>=0)
	printf("Zero");
	else
	{
		if(to%2==0)
		printf("Positive");
		else
		printf("Negative");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl s(n + 1, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    s[i + 1] = s[i] + a;
  }
  ll ans = 1e18;
  rep(i, n - 1) {
    ll x = s[i + 1];
    ll y = s[n] - s[i + 1];
    ans = min(ans, abs(x - y));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int i, j;
  int n, q;
  cin >> n;
  dsu d(n);
  set<P> s;
  int x[n], y[n];
  VI v(n);
  VI ind(n);
  for (i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
    v[x[i]] = y[i];
    ind[x[i]] = i;
  }
  for (i = 0; i < n; i++) {
    if(s.size() == 0){
        s.insert(P(v[i],i));
        continue;
    }
    P be = *s.begin();
    if (be.fi > v[i]) be = P(v[i], i);
    while (s.size() && (*s.begin()).fi <= v[i]) {
      d.merge((*s.begin()).se, i);
      s.erase(s.begin());
    }
    s.insert(be);
  }
  VI ans(n);
  for (i = 0; i < n; i++) {
    ans[ind[i]] = d.size(i);
  }
  for (i = 0; i < n; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 14672
/**
*	  Name: Ajay Subhash Jadhav
*	  Institute: International Institute of Technology Hyderabad 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main(){
	  
  fastio();
  int n,m,i,j,t;
  cin>>n>>m;
  int choice[m]={0};
  for(i=0;i<n;i++)
  {
		cin>>t;
		while(t--)
		{
			int x;
			cin>>x;
			choice[x-1]++;	
		}
  }
  int ans=0;
  for(i=0;i<m;i++)
  	if(choice[i]==n)
  		ans++;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <map>
#include <utility>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <string>
#include <limits.h>
#include <algorithm>
#include <assert.h>

using namespace std;

#define XX 1000000007L


long long ff(long long n){
    long long ret = 1;
    while (n) {
        ret *= n;
        n--;
        ret %= XX;
    }
    return ret;
}

int main(){
    long long n,m;
    cin >> n >> m;
    if(abs(n-m) > 1){
        cout << 0 << endl;
        return 0;
    }
    long long ret =ff(n) * ff(m);
    ret %= XX;
    if(n == m){
        ret *= 2;
        ret %= XX;
    }
    cout << ret << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
using namespace std;

int main(){
	
	//fastio
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,k,ans=1,sortcount=1;

	cin>>n>>k;

	deque<int> minn;
	deque<int> maxx;

	int arr[n];
	for(int i=0;i<n;i++) cin>>arr[i];

	for(int i=0;i<k;i++){
		while(!minn.empty() && minn.back()>arr[i]){
			minn.pop_back();
		}
		minn.push_back(arr[i]);

		while(!maxx.empty() && maxx.back()<arr[i]){
			maxx.pop_back();
		}
		maxx.push_back(arr[i]);
		if(i>0 && arr[i]>arr[i-1]) sortcount++;
		else sortcount = 1;
	}

	bool lostminn = false, gainmaxx=false, sortdone = false;

	if(sortcount>=k) sortdone = true;

	for(int i=k;i<n;i++){
		lostminn = false;
		gainmaxx=false;
		
		if(arr[i-k]==minn.front()){
			lostminn=true;
			minn.pop_front();
		}
		if(arr[i-k]==maxx.front()){
			maxx.pop_front();
		}

		while(!minn.empty() && minn.back()>arr[i]){
			minn.pop_back();
		}
		minn.push_back(arr[i]);

		while(!maxx.empty() && maxx.back()<arr[i]){
			maxx.pop_back();
		}
		maxx.push_back(arr[i]);

		if(arr[i]==maxx.front()) gainmaxx = true;

		if(arr[i]>arr[i-1]) sortcount++;
		else sortcount = 1;

		if(lostminn && gainmaxx){

		}
		else{
			//cout<<i<<" "<<sortcount<<"\n";
			if(sortcount>=k){
				if(!sortdone) ans++;
				sortdone = true;
			}
			else ans++;
		}
	}

	cout<<ans<<"\n";

	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	string S;
	cin >> S;
	if(S[0]==S[1]||S[1]==S[2]||S[2]==S[3]){
		cout << "Bad" << endl;
	}else{
		cout << "Good" << endl;
	}
}

Measured memory_bytes: 256
#import
#import math
#import numpy as np
N = int(input())
#= input()
#= map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]

a = []

# dp[i][0]:Aを選んだ  dp[i][1]:Bを選んだ  dp[i][2]:Cを選んだ 

dp = [[0]*3 for _ in range(N+1)]

for _ in range(N):
    aa = list(map(int, input().split()))
    a.append(aa)

for i in range(1, N+1):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][k] = max(dp[i][k], dp[i-1][j]+a[i-1][k])

print(max(dp[-1]))

Measured memory_bytes: 50212
<?php
fscanf(STDIN,"%d %d",$d,$n);
if(trim($n)==100&&trim($d)==0){
	echo "101";
}elseif(trim($n)!=100&&trim($d)==0){
	echo $n;
}elseif(trim($d)==1&&trim($n)==100){
	echo 101*100;
}elseif(trim($d)==1&&trim($n)!=100){
	echo $n*100;
}elseif(trim($d)==2&&trim($n)==100){
	echo 101*100*100;
}elseif(trim($d)==2&&trim($n)!=100){
	echo $n*100*100;
}

Measured memory_bytes: 3700
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#define line cout << endl
using namespace std;
int a, b, c, d, e;
int main () {
	cin >> a >> b >> c >> d >> e;
	if (a == 0) cout << "1";
	else if (b == 0) cout << "2";
	else if (c == 0) cout << "3";
	else if (d == 0) cout << "4";
	else if (e == 0) cout << "5";
	line;
	return 0;
}


Measured memory_bytes: 3564
N,D =map(int,input().split())
X=[]
cnt=0
for i in range(N):
    X.append(list(map(int,input().split())))
for i in range(0,N-1):
    for j in range(i+1,N):
        dist=0
        for k in range(D):
            dist += (X[i][k]-X[j][k])**2
        if dist**0.5 % 1 ==0:
            cnt+=1
print(cnt)

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

int main (){
	int n,m;
	while ( cin >> n >> m){
		int a[n][m], b[m], sum[n];
		
		for ( int in_A_i = 0; in_A_i < n; in_A_i++){
			for ( int in_A_l = 0; in_A_l < m; in_A_l++){
				a[in_A_i][in_A_l] = 0;
			}
		}
		
		for ( int in_b_i = 0; in_b_i < m; in_b_i++){
			b[in_b_i] = 0;
		}
		
		for ( int sum_i = 0; sum_i < n; sum_i++){
			sum[sum_i] = 0;
		}
		
		for ( int i = 0; i < n; i++){
			for ( int l = 0; l < m; l++){
				cin >> a[i][l];
			}
		}
		
		for ( int k = 0; k < m; k++){
			cin >> b[k];
		}
		
		for ( int out_i = 0; out_i < n; out_i++){
			for ( int out_l = 0; out_l < m; out_l++){
				sum[out_i] += a[out_i][out_l] * b[out_l];
			}
		}
		
		for ( int out = 0; out < n; out++){
			cout << sum[out] << endl;
		}
	}	
	return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(int i = (int)(b); i < (int)(e); ++i)
#define RFOR(i, b, e) for(int i = (int)(e-1); i >= 0; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<int,int>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;

using namespace std;

ll conb(ll n, ll r) {
	if (n - r < r) { return conb(n, n - r); }
	ll tmp = 1;
	FOR(i, n - r + 1, n + 1) {
		tmp *= i;
	}
	FOR(i, 1, r + 1) {
		tmp /= i;
	}
	return tmp;
}

int main() {
	int h, w;
	cin >> h >> w;
	VS v(h);
	REP(i, h) { cin >> v[i]; }

	queue<PAIR> q;
	map<PAIR, int> memo;
	q.emplace(0, 0);
	memo[{0, 0}] = 0;

	bool flg = false;
	while (!q.empty()) {
		PAIR now = q.front();
		q.pop();
		int x = now.second;
		int y = now.first;
		if (x == w - 1 && y == h - 1) {
			flg = true;
			break;
		}
		if (x < w - 1) {
			if (v[y][x + 1] == '.' && memo.find({ y,x + 1 }) == memo.end()) {
				q.emplace(y, x + 1);
				memo[{y, x + 1}] = memo[{y, x}] + 1;
			}
		}
		if (x > 0) {
			if (v[y][x - 1] == '.' && memo.find({ y,x - 1 }) == memo.end()) {
				q.emplace(y, x - 1);
				memo[{y, x - 1}] = memo[{y, x}] + 1;
			}
		}
		if (y < h - 1) {
			if (v[y + 1][x] == '.' && memo.find({ y + 1,x }) == memo.end()) {
				q.emplace(y + 1, x);
				memo[{y + 1, x}] = memo[{y, x}] + 1;
			}
		}
		if (y > 0) {
			if (v[y - 1][x] == '.' && memo.find({ y - 1,x }) == memo.end()) {
				q.emplace(y - 1, x);
				memo[{y - 1, x}] = memo[{y, x}] + 1;
			}
		}
	}

	if (!flg) { cout << -1 << endl; return 0; }

	int count = 0;
	REPC(s, v) {
		REPC(c, s) {
			if (c == '.') {
				++count;
			}
		}
	}
	//cout << count << " " << memo[{h - 1, w - 1}] << endl;
	cout << count - memo[{h - 1, w - 1}] - 1 << endl;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc073
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            if (a[0] == '9' || a[1] == '9') { Console.WriteLine("Yes"); }
            else { Console.WriteLine("No"); }
        }
    }
}


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

typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 7654321
#define IINF 87654321987654321LL
#define MAXV 200500

ll mod = 1e9 + 7;

int A[10500], B[10500];
int main(){
	int n ;geti(n);
	ll a  = 0 ,b =  0;
	repp(i,n){
		int x; geti(x); a += x;
		A[i] = x;
	}
	repp(i,n){
		int x; geti(x); b += x;
		B[i] = x;
	}
	ll avail = 0;
	ll need = 0;
	repp(i,n){
		ll x = B[i] - A[i];
		if( x < 0 ) need += -x;
		else avail += x/2;
	}

	if( need <= avail ){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

}


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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl


signed main(){

	int N, W;
	cin >> N >> W;
	int w_base, w[4];
	vector<int> v[4];

	rep(i, 4)w[i] = 0;

	rep(i, N){
		int ww, vv;
		cin >> ww >> vv;
		if (i == 0) w_base = ww;
		w[ww - w_base]++;
		v[ww - w_base].push_back(vv);
	}
	rep(i, 4) sort(v[i].begin(), v[i].end(), greater<>());

	int ans = -INF;
	rep(a, w[0]+1)rep(b, w[1]+1)rep(c, w[2]+1)rep(d, w[3]+1){
		int cost = 0;
		if (a*(w_base + 0) + b*(w_base + 1) + c*(w_base + 2) + d*(w_base + 3) <= W){
			rep(i, a) cost += v[0][i];
			rep(i, b) cost += v[1][i];
			rep(i, c) cost += v[2][i];
			rep(i, d) cost += v[3][i];

//			cerr << cost << endl;
		}
		ans = max(ans, cost);
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
	set<int> a;
        int i;
	for (i = 0; i<3; i++){
		int n;
		cin>>n;
		a.insert(n);
	}
	if (a.size()==2){
		cout<<"Yes"<<endl;
	} else {
		cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int l,a,b,c,d,n,m,x,y,ans;
	scanf("%d %d %d %d %d",&l,&a,&b,&c,&d);
	n=a/c;
	x=a%c;
	m=b/d;
	y=b%d;
	if(x>=1){
		n=n+1;
	}
	if(y>=1){
		m=m+1;
	}
	if(n<=m){
		ans=l-m;
	}
	else if(m<=n){
		ans=l-n;
	}
	printf("%d\n",ans);
}


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

const int MOD = 1e9 + 7;

int main() {
	long long N, K;
	cin >> N >> K;
	vector<long long> K_min(N + 1), K_max(N + 1);
	for (int i = 0; i < N + 1; i++) {
		if (i == 0) {
			long long tmp = N * (N + 1) / 2; // 0 + NがN + 1個あるので
			K_min.at(N) = tmp;
			K_max.at(N) = tmp;
		} else {
			K_min.at(N - i) = K_min.at(N - i + 1) - (N - i + 1); // i個小さい方から選ぶ
			K_max.at(N - i) = K_max.at(N - i + 1) - (i - 1); // i個大きい方から選ぶ
		}
	}

	long long ans = 0;
	for (int i = K; i <= N + 1; i++) {
		long long tmp = K_max.at(i - 1) - K_min.at(i - 1) + 1; // 作れる数の種類(i個の数で作れる最大値から最小値を引いた)
		ans += tmp;
		ans %= MOD;
	}
	cout << ans << endl;
}

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

int main() {
    long long K, N;
    cin >> K >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    vector<long long> diff;
    for (int i = 1; i < N; i++) {
        diff.push_back(A[i] - A[i - 1]);
    }
    diff.push_back(K - A[N - 1] + A[0]);
    sort(diff.begin(), diff.end());
    long long res = 0;
    for (int i = 0; i < N - 1; i++) {
        res += diff[i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3956
using System;

public class hello
{
    public static void Main()
    {
        var g = 100000;
        var a = 1.05;
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var res1 = Math.Ceiling(g*a / 1000) * 1000;
            g = (int)res1;
        }
        Console.WriteLine(g);
    }
}

Measured memory_bytes: 9128
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define bit(n) (1LL<<(n))
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
struct baseN{
    int base;
    int len;
    string val; //reversed
    string digit = "0123456789ABCDEF";
    bool end = false;
    baseN(int b,int l) :base(b), len(l){
        val = string(len,'0');
    }
    baseN operator++(int){
        bool flag = true;
        for(int i=0; i < len; i++){
            if(val[i]!=digit[base-1]){
                val[i]=digit[pos(val[i])+1];
                flag = false;
                break;
            } else {
                val[i]='0';
            }
        }
        if(flag) end = true;
        return *this;
    }
    int operator[](int i){
        return pos(val[i]);
    }
    int pos(char s){
        if(s-'0'<10) return s-'0';
        else return s-'A'+10;
    }
};
#pragma endregion library
int n;    
vector<tuple<ll,ll,ll>> m;
vll ans;
const int MX = 16;
ll dpx[1<<16][16],dpy[1<<16][16];
void solve(){
    rep(i,bit(n)){
        int cnt = __builtin_popcount(i);
        rrep(j,bit(n)){
            j &= i;
            ll cost = 0;
            rep(k,n){
                if(!(bit(k)&i))
                cost += min(dpx[j][k],dpy[i-j][k]);
            }
            ans[cnt] = min(ans[cnt], cost);
        }
    }
}
int main(){
    cin >> n;
    rep(i,n){
        ll x,y,p; cin >> x >> y >> p;
        m.emplace_back(x,y,p);
    }
    ans.assign(n+1,LINF);
    rep(i,bit(n)){
        set<ll> xax = {0ll}, yax = {0ll};
        rep(j,n){
            if(bit(j)&i) yax.emplace(get<0>(m[j])),xax.emplace(get<1>(m[j]));
        }
        rep(j,n){
            ll x,y,p;
            tie(x,y,p) = m[j];
            ll now = LINF;
            auto it2 = yax.lower_bound(x);
            if(it2!=yax.end()) now = min(now, (*it2-x)*p);
            if(it2!=yax.begin()) now = min(now, (x-*(--it2))*p);
            dpy[i][j] = now;
            now = LINF;
            auto it = xax.lower_bound(y);
            if(it!=xax.end()) now = min(now, (*it-y)*p);
            if(it!=xax.begin()) now = min(now, (y-*(--it))*p);
            dpx[i][j] = now;
        }
    }
    solve();
    rep(i,n+1){
        cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 11860
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n, k = map(int, input().split())
    a = sorted([(abs(i), (1 if i > 0 else -1)) for i in map(int, input().split())], reverse=True)
    if n == k:
        s = 1
        for x in a:
            s = s * x[0] * x[1] % mod
        print(s)
        return
    if len([i for i in a if i[1] == -1]) == n:
        if k % 2 == 0:
            s = 1
            for i in a[:k]:
                s = (s * i[0]) % mod
            print(s)
        else:
            s = 1
            for i in a[-k:]:
                s = (s * i[0]) % mod
            print((-s) % mod)
        return
    s = 1
    c = 1
    for i in range(k):
        s = s * a[i][0] % mod
        c *= a[i][1]
    if c == 1:
        print(s)
        return

    x_minus1 = -1
    x_plus1 = -1
    for i in range(k):
        if a[i][1] == -1:
            x_minus1 = a[i][0]
    for i in range(k, n):
        if a[i][1] == 1:
            x_plus1 = a[i][0]
            break

    x_minus2 = -1
    x_plus2 = -1
    for i in range(k):
        if a[i][1] == 1:
            x_minus2 = a[i][0]
    for i in range(k, n):
        if a[i][1] == -1:
            x_plus2 = a[i][0]
            break
    if x_minus1 == -1 or x_plus1 == -1:
        s = (s * inverse(x_minus2)) % mod * x_plus2 % mod
        print(s)
        return
    if x_minus2 == -1 or x_plus2 == -1:
        s = (s * inverse(x_minus1)) % mod * x_plus1 % mod
        print(s)
        return
    if x_plus1 * x_minus2 > x_plus2 * x_minus1:
        s = (s * inverse(x_minus1)) % mod * x_plus1 % mod
    else:
        s = (s * inverse(x_minus2)) % mod * x_plus2 % mod
    print(s)
main()


Measured memory_bytes: 107952
first=1
while 1:
    a,b=map(int,input().split())
    if a==b==0:break
    if first==1:
        first=0
    else:
        print()
    count=0
    for i in range(a,b+1):
        if i%400==0:
            print(i)
            count+=1
        elif i%100==0:
            pass
        elif i%4==0:
            print(i)
            count+=1
    if count==0:print("NA")


Measured memory_bytes: 5716
import java.io.*;
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		String[] map = new String[10];
		map[1] = ".,!? ";
		map[2] = "abc";
		map[3] = "def";
		map[4] = "ghi";
		map[5] = "jkl";
		map[6] = "mno";
		map[7] = "pqrs";
		map[8] = "tuv";
		map[9] = "wxyz";
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for(;N-->0;)
		{
			String s = sc.next() + "0";
			
			int p = 0, j = 0;
			for (int i = 0; i < s.length(); i++)
			{
				char c = s.charAt(i);
				int q = c - '0';
				if (q == 0)
				{
					if (p != 0)
					{
						System.out.print(map[p].charAt(j));
						p = 0;
						j = 0;
					}
				}
				else
				{
					if (p == q)
					{
						j = (j + 1) % map[p].length();
					}
					else
					{
						p = q;
						j = 0;
					}
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
n,m=map(int,input().split())
l2=[0]*m
for i in range(n):
  l=list(map(int,input().split()))
  l.remove(l[0])
  for j in l:
    l2[j-1]+=1
c=0
for i in range(len(l2)):
  if l2[i]==n:
    c+=1
print(c)

Measured memory_bytes: 3060
#include <map>
#include <list>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
string s;
int main()
{
    fast;
    cin>>s;
    for (int i=0;i<=s.size();i++)
       if (s[i]==',')
          s[i]=' '; 
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#else
#define D(...) ((void)0)
#define NDEBUG
#endif
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int N=200005,P=998244353,inv2=(P+1)/2;
template<typename T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<typename T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
int n,K,a[N],id[N];
int fpow(int k1,int k2){
	int k3=1;
	for(;k2;k2>>=1,k1=1LL*k1*k1%P)if(k2&1)k3=1LL*k3*k1%P;
	return k3;
}
struct BIT{
	int t[N];
	void upd(int k1,int k2){
		for(int i=k1;i<=n;i+=i&-i)(t[i]+=k2)%=P;
	}
	int qry(int k1){
		int k2=0;
		for(int i=k1;i;i&=i-1)(k2+=t[i])%=P;
		return k2;
	}
	int qry(int l,int r){
		if(l>r)return 0;
		return (qry(r)+P-(l<=1?0:qry(l-1)))%P;
	}
}T1,T2,T3;
bool cmp(int k1,int k2){return a[k1]>a[k2];}
int main(){
	rd(n),rd(K);
	rep(i,1,n)rd(a[i]),id[i]=i;
	sort(id+1,id+1+n,cmp);
	int ans=0;
	int p=1LL*(K-1)*fpow(K,P-2)%P;
	int ip=fpow(p,P-2);
	rep(_,1,n){
		int i=id[_];
		if(i<=K){
			int sumr=1LL*inv2*T1.qry(K+1,n)%P*fpow(ip,K)%P;
			(ans+=sumr)%=P;
			int suml=1LL*inv2*T3.qry(1,K)%P;
			(ans+=suml)%=P;
		}else{
			int sumr=1LL*inv2*T1.qry(i+1,n)%P*fpow(ip,i)%P;
			(ans+=sumr)%=P;
			int summ=(P+T3.qry(K+1,i-1)-1LL*inv2*T2.qry(K+1,i-1)%P*fpow(ip,n-i+1)%P)%P;
			(ans+=summ)%=P;
			int suml=(P+T3.qry(1,K)-1LL*inv2*T3.qry(1,K)%P*fpow(p,i-K)%P)%P;
			(ans+=suml)%=P;
		}
		T1.upd(i,fpow(p,i));
		T2.upd(i,fpow(p,n-i+1));
		T3.upd(i,1);
	}
	pt(ans,'\n');
	return 0;
}

Measured memory_bytes: 7536
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;

const int INF = 0x7fffffff;

struct edge {
    int to, cap, rev;
    edge(int to, int cap, int rev): to(to), cap(cap), rev(rev) {}
};

struct ford_fulkerson {
    int N;
    vector<vector<edge> > graph;
    vector<char> visited;

    ford_fulkerson() {}
    ford_fulkerson(int _N) {
        init(_N);
    }
    void init(int _N) {
        N = _N;
        graph.resize(N);
        visited.resize(N);
    }

    void add_edge(int u, int v, int cap) {
        graph[u].push_back(edge(v, cap, graph[v].size()));
        graph[v].push_back(edge(u, 0, (int)graph[u].size()-1));
    }

    int max_flow(int s, int t) {
        int flow = 0;
        for (;;) {
            fill(visited.begin(), visited.end(), 0);
            int acc = dfs(s, t, INF);
            if (acc == 0) break;
            flow += acc;
        }
        return flow;
    }

private:
    int dfs(int v, int t, int f) {
        if (v == t) return f;
        visited[v] = 1;
        for (int i = 0; i < graph[v].size(); ++i) {
            edge& e = graph[v][i];
            if (!visited[e.to] && e.cap > 0) {
                int ff = dfs(e.to, t, min(f, e.cap));
                if (ff > 0) {
                    e.cap -= ff;
                    graph[e.to][e.rev].cap += ff;
                    return ff;
                }
            }
        }
        return 0;
    }
};

int V, E;
ford_fulkerson F;

int main() {
    cin >> V >> E;
    F.init(V);
    for (int j = 0; j < E; ++j) {
        int u, v, c;
        cin >> u >> v >> c;
        F.add_edge(u, v, c);
    }
    cout << F.max_flow(0, V-1) << endl;
    return 0;
}

Measured memory_bytes: 3140
#include<iostream>
#include<cstdio>
using namespace std;
const int N=10005;
int n;
string s[N];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>s[i];
	int ans=0;
	int A=0,B=0,BA=0;
	for(int i=1;i<=n;i++)
	{
		for(size_t j=1;j<s[i].size();j++)
			if(s[i][j-1]=='A'&&s[i][j]=='B') ans++;
		if(s[i].front()=='B'&&s[i].back()=='A') BA++;
		else if(s[i].front()=='B') B++;
		else if(s[i].back()=='A') A++;
	}
	if(BA>0)
	{
		if(A>0&&B>0) A--,B--,BA--,ans+=2;
		else if(A>0) A--,BA--,ans++;
		else if(B>0) B--,BA--,ans++;
		else BA--;
	}
	ans+=min(A,B)+BA;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
#define maxn 100005
using namespace std;

#define INF 1000000000000000LL
ll A[maxn];
ll lim[maxn];

int main(){
    int n;
    cin >> n;
    rep(i, n+1) cin >> A[i];
    lim[0] = 1;
    for(int i = 1; i < n + 1; i++){
        ll m = (lim[i-1]-A[i-1])*2LL;
        if(m < 0){
            cout << -1 << endl;
            return 0;
        }
        lim[i] = min(INF, m);
    }

    if(lim[n] < A[n]){
        cout << -1 << endl;
        return 0;
    }
    ll ret = A[n], now = A[n];
    for(int i = n - 1; i >= 0; i--){
        now += A[i];
        now = min(now, lim[i]);
        ret += now;
    }
    cout << ret << endl;
}

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

const int maxn=2e5+7;
int a[maxn];


int main (){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int ans2,ans1;
    if(x>=y){
        ans1=y*(a+b);
        ans1+=(x-y)*a;
        ans2=y*2*c;
        ans2+=(x-y)*a;
    }
    else {
        ans1=x*(a+b);
        ans1+=(y-x)*b;
        ans2=x*2*c;
        ans2+=(y-x)*b;
    }
    int ans=min(ans1,ans2);
    cout<<min(ans,min(a*x+b*y,max(x,y)*2*c))<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

cnt;
int main(){
    int k,s;
    scanf("%d%d",&k,&s);
    rep(i,0,k+1)rep(j,0,k+1){
        int z=s-i-j;
        if(z>=0&&z<=k)cnt++;
    }
    printf("%d",cnt);
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        System.out.println(solve(in));
        
      }
      
      public static String solve(Scanner in) {
        int K = in.nextInt();
        long ans = 0;
        for (int i = 1; i <= K; i++) {
          if (i % 3 == 0 && i % 5 == 0) continue;
          else if (i % 3 == 0) continue;
          else if (i % 5 == 0) continue;
          else ans += i;
        }
        return String.valueOf(ans);
      }
      
    
}

Measured memory_bytes: 35844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		sc.close();
		int p = X;
		while(!prime(p)){
			p++;
		}
		System.out.println(p);
	}

	//素数判定(O(√n))
	private static boolean prime(int x){
		if(x<=1){
			return false;
		}
		for(int i = 2;i<=(int)Math.sqrt(x);i++){
			if(x%i==0){
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    vector<int> cnt(N);
    ll ret = 1;
    int cnt2 = 3;
    for(int i = 0;i < N;i++) {
        if(vec.at(i) == 0) {
            ret = ret * cnt2 % MOD;
            cnt2--;
        }
        else {
            ret = ret * (cnt.at(vec.at(i) - 1) - cnt.at(vec.at(i))) % MOD;
        }
        cnt.at(vec.at(i))++;
    }
    cout << ret << endl;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var text string
	if scanner.Scan() {
		text = scanner.Text()
	}
	for i := 0; i < 10; i++ {
		if strings.Count(text, strconv.Itoa(i)) > 1 && strings.Count(text, strconv.Itoa(i)) < 3 {
			fmt.Printf("Yes")
			os.Exit(0)
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 640