akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N;
    cin >> N;
    vec<lint> a_list(N);
    range(i, 0, N) cin >> a_list.at(i);
    lint min_cost = (1LL << 55);
    lint cost;
    range(n, -100, 101) {
        cost = 0;
        for (const auto a : a_list) {
            cost += (a - n) * (a - n);
        }
        min_cost = min(min_cost, cost);
    }
    cout << min_cost << "\n";
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        //System.Console.ReadLine();
    }

    public static void hoge()
    {
        var s = System.Console.ReadLine();
            var t = System.Console.ReadLine();


        System.Console.WriteLine(s == t.Substring(0,t.Length - 1) ? "Yes":"No");

    }
}

Measured memory_bytes: 25880
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#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 = 1 << 17, 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);
	}
	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 tmp;
}

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


	int A[200000], B[200000];
	int N = getint();
	rep(i, N) {
		A[i] = getint();
		B[i] = getint();
	}

	nth_element(A, A + N / 2, A + N);
	nth_element(B, B + N / 2, B + N);
	if (N % 2) {
		printf("%d\n", B[N / 2] - A[N / 2] + 1);
	}
	else {
		int a = *max_element(A, A + N / 2);
		int b = *max_element(B, B + N / 2);
		printf("%d\n", b + B[N / 2] - a - A[N / 2] + 1);
	}

	Would you please return 0;
}

Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
int min(int a,int b)
{
    return a<=b? a:b;
}
int main()
{
    int n,i,sum=0;
    cin>>n;
    int arr[2*n];
    for(i=0 ; i<2*n ; i++)
     cin>>arr[i];
    sort(arr,arr+2*n);
    for(i=0 ; i<2*n ;)
    {
        sum=sum+min(arr[i],arr[i+1]);
        i=i+2;
    }
    cout<<sum;
    
}

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

typedef long long ll;

int main()
{

    int a,b,c;
    cin>>a>>b>>c;
    vector<int>v;
    int d = c%b;
    for(int i=a;i<=10000;i=i+a)
	{
		//cout<<"i = "<<i<<endl;
		v.push_back(i);
	}
	int x = v[v.size()-1];

	for(auto &xx:v)
	{
		v.push_back(xx+x);
	}
	v.pop_back();

	for(auto &xx :v)
	{
		if(xx%b==d)
		{
			cout<<"YES"<<endl;
			return 0;
		}
	}

	cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <string>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> h(N);
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	sort(h.begin(), h.end());
	int min_num = INT_MAX;
	for (int i = 0; i < N; i++) {
		if (i + K - 1 < N) {
			if (min_num > h[i + K - 1] - h[i])
				min_num = h[i + K - 1] - h[i];
		}
		if (min_num == 0)
			break;
	}
	cout << min_num;
	return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	int n; cin >> n;
	map<int, int> even, odd;
	for (int i = 0; i < n; ++i) {
		int v; cin >> v;
		if (i & 1) ++odd[v];
		else ++even[v];
	}
	vector<pair<int, int>> even_vec, odd_vec;
	for (auto& e : even)
		even_vec.emplace_back(e.second, e.first);
	for (auto& e : odd)
		odd_vec.emplace_back(e.second, e.first);
	sort(even_vec.begin(), even_vec.end());
	reverse(even_vec.begin(), even_vec.end());
	sort(odd_vec.begin(), odd_vec.end());
	reverse(odd_vec.begin(), odd_vec.end());
	if (even_vec[0].second != odd_vec[0].second) {
		int res = even_vec[0].first + odd_vec[0].first;
		res = n - res;
		cout << res << endl;
	}
	else {
		int res1;
		if (odd_vec.size() > 1)
			res1 = even_vec[0].first + odd_vec[1].first;
		else res1 = even_vec[0].first;
		res1 = n - res1;
		int res2;
		if (even_vec.size() > 1)
			res2 = even_vec[1].first + odd_vec[0].first;
		else res2 = odd_vec[0].first;
		res2 = n - res2;
		int res = min(res1, res2);
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 6136
#include <stdio.h>

int main(void){
	int i;
	char s[13];
	scanf("%s",s);
	for(i=0;i<4;i++){
		printf("%c",s[i]);
	}
	putchar(' ');
	for(;i<12;i++){
		printf("%c",s[i]);
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 128
#include <math.h>
#include <stdio.h>

int main() {
    double x1, y1, x2, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    printf("%lf\n", sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)));
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

ll width_way(ll num) {
	assert(0 <= num && num < 8);
	ll way[] = { 1,1,2,3,5,8,13,21,33 };
	return way[num];
}

// way[i][j] := how many way from i to j
vector<vector<ll>> get_way(ll W) {
	vector<vector<ll>> way(W, vector<ll>(W, 0));

	REP(i, W)REP(j, W)if (abs(i - j) <= 1) {
		ll l = min(i, j);
		ll r = max(i, j);
		way[i][j] = width_way(l)*width_way(W - 1 - r) % MOD;
	}
	return way;
}

void add(ll& l, ll r) {
	l += r;
	l %= MOD;
}

int main()
{
	ll H, W, K;
	cin >> H >> W >> K;
	auto way = get_way(W);

	vector<vector<ll>> dp(H + 1, vector<ll>(W, 0));
	dp[0][0] = 1;
	REP(h, H)REP(from, W)REP(to, W) {
		add(dp[h + 1][to], dp[h][from] * way[from][to] % MOD);
	}
	cout << dp.back()[K - 1] << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxx = 2e7+1314;
char s[maxx];
int aa[maxx];
int n,a,b,c,d;
int read(){int k;cin>>k;return k;}
bool chick(int a,int b){	
	for(int i=a+1;i<=b;i++){
		if(s[i]=='#'&&s[i]==s[i-1])
		return 1;
	}	
	return 0;
}	
int main(){	
	scanf("%s",s+1);
	int n=strlen(s+1);
	long long  ans=0;
long long  a=0;
	for(int i=1;i<=n-1;i++){	
		if(s[i]=='A')a++;
		else 
		if(s[i]=='B'&&s[i+1]=='C'){	
			ans+=a;
			i++;
		}	
		else if(s[i]=='B'||s[i]=='C')a=0;
	}	
	cout<<ans<<endl;
	return 0;
}	

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int d;
    cin >> d;
    vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(d, vector<ll>(2, 0)));
    rep(i, s[0]-'0'+1){
        if(i == s[0]-'0'){
            dp[0][i%d][1] = 1;
        }else{
            dp[0][i%d][0]++;
        }
    }
    ll mod = 1000000007;
    for(int i = 1; i < n; i++){
        rep(j, d){
            rep(k, 10){
                (dp[i][(j+k)%d][0] += dp[i-1][j][0]) %= mod;
            }
        }
        rep(j, d){
            rep(k, s[i]-'0'){
                (dp[i][(j+k)%d][0] += dp[i-1][j][1]) %= mod;
            }
        }
        rep(j, d){
            (dp[i][(j+(s[i]-'0'))%d][1] += dp[i-1][j][1]) %= mod;
        }
    }
    ll ans = (dp[n-1][0][0] + dp[n-1][0][1] - 1 + mod) % mod;
    cout << ans << endl;
}

Measured memory_bytes: 58448
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main(){
	ll n, a[405], dp[405][405]={0}, sum[405]={0};
	cin >> n;
	rep(i,1,n){
		cin >> a[i];
		sum[i] = sum[i-1] + a[i];
	}
	rep(i,1,n-1) dp[i][i+1] = a[i] + a[i+1];
	rep(i,3,n){
		rep(j,1,n-i+1){
			dp[j][j+i-1] = 1e17;
			rep(k,j,j+i-2) chmin(dp[j][j+i-1], sum[j+i-1]-sum[j-1]+dp[j][k]+dp[k+1][j+i-1]);
		}
	}
	cout << dp[1][n] << endl;
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int h,n;
 cin>>h>>n;
 int a[n];
 long long int s=0;
 int i=0;
 for(;i<n;i++)
 {
 	cin>>a[i];
 	s+=a[i];
 }
 if(s>=h)
 {
 	cout<<"Yes"<<endl;
 }
 else
{
	cout<<"No"<<endl;
}
 return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M (1000000007)
#define N (100010)
char s[N],t[N];
int a[30][N];
ll ans;
bool b[50];

int main(){
	scanf("%s%s",s+1,t+1);
	int sn=strlen(s+1),tn=strlen(t+1);
	for (int i=1;i<=sn;++i) b[s[i]-'a']=1,a[s[i]-'a'][++a[s[i]-'a'][0]]=i;
	int pre=0;
	for (int i=1;i<=tn;++i){
		int o=t[i]-'a';
		if (!b[o]){
			printf("-1");
			return 0;
		}
		int tt=a[o][a[o][0]]<=pre?1:upper_bound(a[o]+1,a[o]+1+a[o][0],pre)-a[o];
		tt=a[o][tt];
		if (tt<=pre) ans+=sn-pre+tt;
		else ans+=tt-pre;		
		pre=tt;
	}
	printf("%lld",ans);
}


Measured memory_bytes: 9088
import sys
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
  if A[i] % 2 == 0:
    if A[i] % 3 != 0 and A[i] % 5 != 0:
      print("DENIED")
      sys.exit()

print("APPROVED")

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v),end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
//-----------------------------------------------------------------------

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

    while(true)
    {
        int n,a,b,c,x,Y[100];
        cin>>n>>a>>b>>c>>x;
        if(n==0) break;
        REP(i,n) cin>>Y[i];

        int cur=0;
        for(int i=0;i<=10000;i++){
            if(x==Y[cur]) cur++;
            if(cur==n){
                cout<<i<<endl;
                goto g;
            }
            x=(a*x+b)%c;
        }
        cout<<-1<<endl;
    g:;
    }
}

Measured memory_bytes: 3068
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> p;
typedef vector<p> vp;

int main(int argc,char const* argv[])
{
  vector<string> cands;
  set<string> tmp;
  string s;
  int k;
  cin >> s;
  cin >> k;
  for(int i=0;i<int(s.size());i++)
    {
      for(int j=0;j<=k;j++)
	{
	  tmp.insert(s.substr(i,j));
	}
    }
  for(auto x: tmp)
    {
      cands.push_back(x);
    }
  sort(cands.begin(),cands.end());
  cout << cands[k] << endl;
  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
using namespace std;

main() {
    vector<pair<int,int>> p;
    int N; cin >> N;
    rep(i,N){
        int a; cin >> a;
        p.push_back(make_pair(a,i+1));
    }
    sort(p.begin(),p.end());
    rep(i,N){
        cout << p[i].second << (i==N-1 ? "":" ");
    }
    cout << endl;
}

Measured memory_bytes: 2544
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 1000200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
struct T { int to, nxt, v; } way[maxn << 1];
int h[maxn], num;
inline void link(int x,int y,int v) {
	way[++num] = {y, h[x], v}, h[x] = num;
	way[++num] = {x, h[y], v}, h[y] = num;
}
int n, m;
int tot;
std::map<int, int> map[maxn];
inline int get(int x,int c) {
	if(map[x].count(c)) return map[x][c];
	return map[x][c] = ++tot;
}
int dis[maxn], vis[maxn];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	tot = n;
	rep(i, 1, m) {
		int p, q, c;
		cin >> p >> q >> c;
		link(get(p, c), get(q, c), 0);
	}
	rep(i, 1, n) for(auto j : map[i]) link(j.second, i, 1);
	rep(i, 1, tot) dis[i] = 1e9;
	typedef std::pair<int, int> pr;
	std::priority_queue<pr, std::vector<pr>, std::greater<pr> > q;
	q.emplace(dis[1] = 0, 1);
	for(;!q.empty();){
		int x = q.top().second; q.pop();
		if(vis[x]) continue; vis[x] = 1;
		for(int i = h[x];i;i=way[i].nxt) if(dis[way[i].to] > dis[x] + way[i].v) {
			q.emplace(dis[way[i].to] = dis[x] + way[i].v, way[i].to);
		}
	}
	cout << (dis[n] < 1e8 ? dis[n] / 2 : -1) << '\n';
}


Measured memory_bytes: 93816
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=1;i<n;i++)
typedef long long ll;


ll gcd(ll x, ll y){return y ? gcd(y, x%y) : x;}

vector<pair<ll, int>> factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i=2; i*i <= n; i++){
        if(n%i) continue;
        res.emplace_back(i,0);
        while(n%i==0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

int main(){
    ll a, b; cin >> a >> b;
    ll g = gcd(a, b);
    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
}

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

int main(){
  using item= pair<int, int>;
  constexpr int Wmax = 100'000;
  constexpr int Dmax = 18;
  constexpr int Dhalf= 11;

  // ios_base::sync_with_stdio(false);
  // cin.tie(0);

  int N;
  cin >> N;

  vector<item> data(N+1);
  for(int v=1; v<=N; v++){
    cin >> data.at(v).first >> data.at(v).second;
  }

  const int Vupper= min(N+1, 1<< Dhalf);
  vector<vector<int>> above_half(Vupper, vector<int>(Wmax+ 1));
  for(int v=1; v<Vupper; v++){
    above_half.at(v)= above_half.at(v/2);
    auto [val_v, wgh_v]= data.at(v);
    for(int w=Wmax; w >= wgh_v; w--){
      above_half.at(v).at(w)= max(above_half.at(v/2).at(w), val_v+ above_half.at(v/2).at(w- wgh_v));
    }
  }

  int Q;
  cin >> Q;

  vector<int> answers(Q);

  int v_query; int W_query;
  for(int q=0; q<Q; q++){
    cin >> v_query >> W_query;

    if(v_query < Vupper){
      answers.at(q)= above_half.at(v_query).at(W_query);
    }
    else{
      int D_query= (32- __builtin_clz(v_query))- Dhalf;
      int v_anc= v_query >> D_query; 
 
      int ans= 0;
      for(int tmp=0; tmp<(1<< D_query); tmp++){
        bitset<Dhalf> bs(tmp);
 
        int wgh_lower= 0;
        int val_lower= 0;
        for(int i=0; i<D_query; i++){
          if(bs.test(i)){
            wgh_lower+= data.at((v_query>> i)).second;
            val_lower+= data.at((v_query>> i)).first;
          }
        }
 
        if(wgh_lower <= W_query){
          int val_upper= above_half.at(v_anc).at(W_query- wgh_lower);
 
          ans= max(ans, val_upper+ val_lower);
        }
      }
      answers.at(q)= ans;
    }
  }

  for(auto ans:answers){
    cout << ans << endl;
  }
}

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

vector<pair<int, int>> v[15];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans = 0;
    rep(i, N) {
        int A; cin >> A;
        rep(j, A) {
            int x, y; cin >> x >> y;
            x--;
            v[i].push_back({x, y});
        }
    }
    rep(bit, (1 << N)) {
        int c[15];
        rep(i, 15) c[i] = -1;
        int one = 0;
        bool ok = true;
        rep(i, N) {
            if (bit & (1 << i)) {
                one++;
                for (auto x : v[i]) {
                    if (c[x.first] == -1 || c[x.first] == x.second) c[x.first] = x.second;
                    else ok = false;
                }
            }
        }
        rep(i, N) {
            if ((bit & (1 << i)) && c[i] == 0) ok = false;
            if (c[i] == 1 && (bit & (1 << i)) == 0) ok = false;
        }
        if (ok) ans = max(ans, one);
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
    int i, n, h, w, check=0;
    cin >> n >> h >> w;
    
    int A, B;
    
    for(i=0;i<n;i++)
    {
        cin >> A >> B;
        if(h<=A && w<= B)
        {
            check++;
        }
    }
    cout << check << endl;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int a, b; cin >> a >> b;
    if (a >= 13) cout << b << endl;
    else if (a >= 6 && 12 >= a) cout << b / 2 << endl;
    else cout << 0 << endl;
}


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

int main() {
  ll n; cin >> n;
  vector<ll> v(n);
  
  rep(i, n-1){
    ll a; cin >> a;
    v[a-1]++;
  }
  
  rep(i, n)
    cout << v[i] << endl;
}

Measured memory_bytes: 4780
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>

#define ll long long
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >
#define vs vector<string>
#define vc vector<char>
#define vvc vector< vector<char> >

#define all(a) (a).begin(),(a).end()
using namespace std;

bool check(string s, string t, ll now){
	for (int i = 0; i < s.size(); ++i){
		if (t[i] != s[(i + now) % s.size()]) return 0;
	}return 1;
}

int main(){
	string s, t; cin >> s >> t;
	for (int i = 0; i < s.size(); ++i){
		if (check(s, t, i)){
			cout << "Yes" << endl;
			return 0;
		}
	}cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
int a;
char b[100005];
for(int i=0;i<100005;i++){
b[i]=0;
}
scanf("%s",b);
a=strlen(b);
for(int i=0;i<a-2;i++){
if(b[i]==b[i+1]){
printf("%d %d",i+1,i+2);
return 0;
}
if(b[i]==b[i+2]){
printf("%d %d",i+1,i+3);
return 0;
}
}
if(b[a-2]==b[a-1]){
printf("%d %d",a-1,a);
return 0;
}
printf("%d  %d",-1,-1);
return 0;
}


Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var s string
	m := make(map[rune]int)
	fmt.Scan(&s)
	for _, c := range s {
		m[c]++
	}
	if len(m) != 2 {
		fmt.Println("No")
		return
	}
	for _, v := range m {
		if v != 2 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
N = input()
A = raw_input().split()
B = A[:]
for i in xrange(N):
    for j in xrange(N-1, i, -1):
        if B[j][1] < B[j-1][1]:
            B[j], B[j-1] = B[j-1], B[j]
print ' '.join(B)
print 'Stable'

C = A[:]
for i in xrange(N):
    minj = i
    for j in xrange(i, N):
        if A[j][1] < A[minj][1]:
            minj = j
    A[i], A[minj] = A[minj], A[i]
print ' '.join(A)
s = True
for i in xrange(N):
    for j in xrange(i+1, N):
        if A[i][1] == A[j][1] and C.index(A[i]) > C.index(A[j]):
            s = False
print 'Stable' if s else 'Not stable'

Measured memory_bytes: 6476
#include <stdio.h>

long lcm(int a,int b){
  int s,t,r,tmp;
  s = a, t = b;
  if(a < b){
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while(r != 0){
    a = b;
    b = r;
    r = a % b;
  }
  long u,v,w;
  u = (long) s;
  v = (long) t;
  w = (long) b;
  return (u * v / w);
}

int main(){
  long a,b,c,d;
  scanf("%ld%ld%ld%ld\n",&a,&b,&c,&d);
  long numc,numd,numcd;
  numc = b/c - (a-1)/c;
  numd = b/d - (a-1)/d;
  long cd = lcm((int) c, (int) d);
  numcd = b/cd - (a-1)/cd;
  long answer = (b-a+1 - numc - numd + numcd);
  printf("%ld\n",answer);
  return 0;
}

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

int main()
{
	int N;
	cin >> N;
	int ans = N;
	for (int i = 0; i <= N; ++i)
	{
		int t = i,cnt = 0;
		while(t > 0)
		{
			cnt += t % 6;
			t /= 6;
		}
		t = N-i;
		while(t > 0)
		{
			cnt += t % 9;
			t /= 9;
		}
		if (cnt <= N)
		{
			ans = min(ans,cnt);
		}
		
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int main(){
	ll x, y;
	cin >> x >> y;
	vector<ll>v;
	int ans = 0;
	ll add=x;
	while (add<=y) {
		ans++;
		add = add * 2;
	}
	cout << ans << endl;
	return 0;
}

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

#define int long long
int n;
int a[101010];
int x;

signed main()
{
  cin >> n >> x;
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }

  int ans = 0;
  for (int i = 0; i <= n; i++){
    int m = a[i] + a[i - 1];
    if (m > x){
      ans += (m - x);
      a[i] -= (m - x);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int mod = 1e9 + 7;
int main()
{
	int k, x;
	cin >> k >> x;
	if (k*500 >= x)
	{
		cout << "Yes";
	}
	else 
	{
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	int n=0,e=0,s=0,w=0;
	string x;
	cin >> x;
	rep(i,x.size()){
		if(x[i]=='N') n=1;
		if(x[i]=='W') w=1;
		if(x[i]=='S') s=1;
		if(x[i]=='E') e=1;
	}
	if(n==s && w==e) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

void solve() {
  ll n, k; cin >> n >> k;
  ll ans = pow(n/k, 3);
  if (k%2 == 0) ans += pow((n+k/2)/k, 3);
  cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> 
#define ff first 
#define endl "\n"
#define ss second 
#define li list<int>
#define vi vector<int>
#define ll long long int
#define pii pair<int,int>
#define vii vector<pair<int,int> >
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define custom  pair<int,pair<int,int> >
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; 
#define mod 1000000007
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,k;cin>>n>>k;
    ll arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    ll dp[n][k+1];
    for(int j=0;j<=k;j++){
        dp[0][j]=(j>arr[0])?0:1;
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<=k;j++){
            if(j==0)
            dp[i][j]=dp[i-1][j];
            else{
                dp[i][j]=(dp[i-1][j]+dp[i][j-1]-((j>arr[i])? dp[i-1][j-arr[i]-1]:0)+mod)%mod;
            }
        }
    }
    cout<<dp[n-1][k];
    return 0;
}

Measured memory_bytes: 81620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define Graph vector<vector<int>>
typedef pair<int, int> PII;
typedef long long ll;

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

  string ans = "";
  if(a > b){
    rep(i,a){
      ans += to_string(b);
    }
  }else if(b > a){
    rep(i,b){
      ans += to_string(a);
    }
  }else{
    rep(i,a){
      ans += to_string(a);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
s = list(input())
abc = list('abcdefghijklmnopqrstuvwxyz')
not_abc = []
cnt = 0

for i in abc:
  if i not in s:
    not_abc.append(i)
    cnt = cnt + 1
  
if cnt == 0:
  print('None')
  
elif cnt >= 1:
  print(sorted(not_abc)[0])

Measured memory_bytes: 3956
N = int(input())
big = 0
big2 = 0
for i in range(N):
    A = int(input())
    if A > big:
        memo = i
        big = A
    elif A >= big2:
        big2 = A
for i in range(N):
    if i == memo:
        print(big2)
    else:
        print(big)

Measured memory_bytes: 4540
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
int main()
{
  ll N, K;
  cin >> N >> K;
  ll wazairzan = floor((double)N / (double)K);
  rep(i,100){
    if(wazairzan!=0){
    wazairzan - 1;
    }
  }
  N -= wazairzan * K;
  ll nowN, maeN;
  maeN = N;
  nowN = abs(maeN-K);
  ll i = 0;
  for(;;){
    if(maeN<=nowN&&100<i){
      cout << maeN << endl;
      break;
    }
    i++;
    maeN = nowN;
    nowN = abs(nowN - K);
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int A1, A2, A3;

int main()
{
   cin >> A1 >> A2 >> A3;
   if (A1 + A2 + A3 >= 22) {
      cout << "bust" << endl;
   } else {
      cout << "win" << endl;
   }
   return 0;
}



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


int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	long n;cin>>n;
	string s;cin>>s;
	long f=0,r=-1,w=-1,c=0;
	for(int i=0;i<n;i++){
		if(s[i]=='R')r=i;
		if(s[i]=='W' && f==0){w=i;f++;}
		if(s[i]=='R')c++;
	}
	if(r==-1 || w==-1)cout<<"0\n";
	else{
		long x=0,y=0;
		for(long i=0;i<n;i++){
			if(s[i]=='R')x++;
			if(s[i]=='W')y++;
		}
		long z=0;
		int f1=0;
		for(long i=0;i<c;i++){
			if(s[i]=='W'){z++;f1=1;}
		}
		cout<<min(x,min(y,z))<<"\n";
	}
	return 0;
}

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

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}

bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

long long n;
long long ans = LLONG_MAX, mem;
int main(){
    cin >> n;
    for(long long i = 1; i*i <= n; i++){
        if(n % i == 0){
            mem = max(i, n/i);
            ans = min(ans, mem);
        }
    }

    int cou = 0;
    while(ans > 0){
        ans /= 10;
        ++cou;
    }
    cout << cou << endl;
}


Measured memory_bytes: 256
lst = [1 for i in range(10 ** 6 + 1)]
lst[0] = lst[1] = 0
for i in range(10 ** 6 + 1):
  if lst[i] == 1:
    for j in range(i * 2, 10 ** 6 + 1, i):
      lst[j] = 0
while 0 == 0:
  try:
    n = int(input())
    c = 0
    for i in range(n + 1):
      c += lst[i]
    print(c)
  except EOFError:
    break



Measured memory_bytes: 13512
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int N,M,X[100010],dX[100010],ans;cin>>N>>M;
    priority_queue<int> pque;
    for(int i=0;i<M;++i)cin>>X[i];
    
    if(N>=M)ans=0;
    else{
        sort(X,X+M);
        ans=X[M-1]-X[0];
        for(int i=0;i<M-1;++i){
            dX[i]=X[i+1]-X[i];
            pque.push(dX[i]);
        }
        for(int i=1;i<=N-1;++i){
            ans-=pque.top();
            pque.pop();
        }
    }
    cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 1532
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
 
    using namespace std;
    using namespace __gnu_pbds;
 
    #define endl "\n"
    #define fi first
    #define se second
    #define pb push_back
    #define int long long 
    #define ll long long
    #define ld long double
    #define pii pair<ll,ll>
 
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define For(i,n) for(ll i=0;i<n;i++)
 
    #define what(x) cerr << #x << " is " << x << endl;
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
 
    typedef tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> omultiset;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> oset;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> oset1;
 
/*.....................................................................................................................*/
 
    const ll mod=(ll)1e9+ 7;
 
    ll add(ll x,ll y) {return (x+y)%mod;}
    ll mult(ll x, ll y){return ((x%mod )* (y%mod)) % mod;}
 
    long long binpow(long long x, long long p) 
    {
        if (p == 0) {return 1;} 
    	if (p == 2 || (p & 1)) {return mult(x, binpow(x, p - 1));}
    	return binpow(binpow(x, p / 2), 2);
    }
    ll modinv(ll a) {return binpow(a,mod-2);}
 
    //A.erase(unique(A.begin(),A.end()),A.end());
    double pi=3.141592653589793238462641;
    ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    const ll  man  =   (int)200005   ,  inf   =   1e18;
 
 
/*......................................................................................................................*/



signed main()
{
    fast;
    int n,k;
    cin>>n>>k;
    vector<int>a(n),dp(n,inf);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i-j>=0)
            {
                dp[i]=min(dp[i],abs(a[i]-a[i-j])+dp[i-j]);
            }
        }
    }
    cout<<dp[n-1]<<endl;
}   

Measured memory_bytes: 4780
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define endl "\n"
#define ll long long int
using namespace std;

int main()
{
    double w, h, x, y;
    cin >> w >> h >> x >> y;

    double area = (double)(w * h) / 2;
    ll flag = 0;
    if(x == w / 2 && y == h / 2)
    	flag = 1;
    cout << fixed << setprecision(9) << area << " " << flag << endl;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int mod = 998244353;
struct modulo {
	int w;
	operator int&() { return w; }
	
	modulo() {}
	modulo(int w) { this->w = w; fix(); }
	void inline fix() { w %= mod; if (w < 0) w += mod; }
	modulo inline fix(int w) const { w %= mod; if (w < 0) w += mod; return w; }
	
	modulo& operator += (modulo b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	modulo& operator -= (modulo b) { if ((w -= b.w) < 0) w -= mod; return *this; }
	modulo& operator *= (modulo b) { w = (num) w * b.w % mod; return *this; }
	modulo& operator /= (modulo b) { w = (num) w * b.inv() % mod; return *this; }
	modulo inline operator + (modulo b) { modulo r = *this; r += b; return r; }
	modulo inline operator - (modulo b) { modulo r = *this; r -= b; return r; }
	modulo inline operator * (modulo b) { modulo r = *this; r *= b; return r; }
	modulo inline operator / (modulo b) { modulo r = *this; r /= b; return r; }
	
	modulo inline inv() const {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return fix(u);
	}
	
	modulo inline pow(int p) const {
		if (!w)  return 0;
		modulo a = *this, r = 1;
		for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a;
		return r;
	}
};
typedef modulo rem;

const int nsz = int(2e5);
rem n, m, k, inv[nsz + 5], fac[nsz + 5], ifc[nsz + 5], ans;

void inline init() {
	inv[1] = 1;
	circ (i, 2, n) {
		inv[i] = rem(-mod / i) * inv[mod % i];
	}
	fac[0] = ifc[0] = 1;
	cont (i, n) {
		fac[i] = fac[i - 1] * rem(i);
		ifc[i] = ifc[i - 1] * inv[i];
	}
}

rem inline C(int n, int m) { return fac[n] * ifc[m] * ifc[n - m]; }

rem inline f(int n, int k) { return C(n - 1, k) * m * (m - rem(1)).pow(n - k - 1); }

int main() {
	scanf("%d%d%d", &n, &m, &k);
	if (m == 1) {
		printf("%d\n", k == n - rem(1));
		return 0;
	}
	init();
	circ (i, 0, int(k)) {
		ans += f(n, i);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 6120
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,M;
    cin >> N >> M;
    vector<vector<int>>cnt(N,vector<int>(3,INF));
    vector<vector<int>>ki(N);
    for(int i = 0; i < M; i++) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        ki[u].push_back(v);
    }
    int S,T;
    cin >> S >> T;
    S--;T--;
    cnt[S][0] = 0;
    queue<P>que;
    que.push({S,0});
    while (!que.empty()) {
        P x = que.front();
        que.pop();
        for(int i = 0; i < ki[x.first].size(); i++) {
            if(cnt[ki[x.first][i]][(x.second+1)%3] > cnt[x.first][x.second]+((x.second == 0)?1:0)) {
                cnt[ki[x.first][i]][(x.second+1)%3]  = cnt[x.first][x.second]+((x.second == 0)?1:0);
                que.push({ki[x.first][i],(x.second+1)%3});
            }
        }
    }
    if(cnt[T][0] == INF) {
        cout << -1 << endl;
        return 0;
    }
    cout << cnt[T][0] << endl;
}


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

using namespace std;
#define MP(x, y) make_pair(x, y);
#define PB(v, x) v.push_back(x);
typedef pair<int, int> ii;

const int MAX = 18;

int N;
ii dp[(1 << MAX)+10][MAX+1]; // dp[i][j]: 

ii add(ii a, ii b) {
  vector<int> v;
  PB(v,a.first);
  PB(v,a.second);
  PB(v,b.first);
  PB(v,b.second);
  sort(v.begin(), v.end());
  return MP(v[2], v[3]);
}

int result(ii p) {
  return p.first + p.second;
}

int main() {

  cin >> N;
  int ans = 0;
  for (int i = 0; i < (1<<N); i++) {
    int x;
    cin >> x;
    dp[i][0] = MP(-1, x);
    for (int j = 0; j < N; j++) {
      if (i & (1<<j))
        dp[i][j+1] = add(dp[i][j], dp[i&~(1<<j)][j]);
      else
        dp[i][j+1] = dp[i][j];
    }
    if (i == 0) continue;
    ans = max(ans, result(dp[i][N]));
    cout << ans << endl;
  }
}

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

using namespace std;

int main() {
    vector<int> w(10), k(10);
    for (int i=0; i<10; ++i) cin >> w[i];
    for (int i=0; i<10; ++i) cin >> k[i];
    partial_sort(w.begin(), w.begin()+3, w.end(), greater<int>());
    partial_sort(k.begin(), k.begin()+3, k.end(), greater<int>());
    cout << w[0]+w[1]+w[2] << " " << k[0]+k[1]+k[2] << endl;
    return 0;
}

Measured memory_bytes: 3084
n, m = map(int, input().split())
r = [2**i for i in range(n+1)]

price = [0] * m
mask = [0] * m
for i in range(m):
    a, b = map(int, input().split())
    for box in map(int, input().split()):
        mask[i] += r[box-1]
    price[i] = a


inf = 10**9
dp = [[inf] * (1 << n) for _ in range(m+1)]
dp[0][0] = 0
for i in range(m):
    for j in range(1 << n):
        dp[i+1][j | mask[i]] = min(
            dp[i][j] + price[i],
            dp[i+1][j | mask[i]]
        )
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])

ans = dp[m][(1 << n) - 1]
if ans == inf:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 99852
from functools import reduce
from decimal import *
from operator import mul

def main():
    n = int(input())
    a = input_list()
    count = 0
    pre = 0
    for i in range(1, n+1):
        if a[i-1] == i:
            if i >= 2 and a[i-2] == pre:
                continue
            pre = a[i-1]
            count += 1
    print(count)


def count_tento(l, cur):
    count = 0
    for v in l:
        if v > cur:
            count += 1
    return count

def input_list():
    return list(map(int, input().split()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if __name__ == '__main__':
    main()


Measured memory_bytes: 74288
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def modfact(n):
    fact=[1]*(n+1)
    invfact=[1]*(n+1)
    for i in range(1,n+1):
        fact[i]=i*fact[i-1]%MOD
    invfact[n]=pow(fact[n],MOD-2,MOD)
    for i in range(n-1,-1,-1):
        invfact[i]=invfact[i+1]*(i+1)%MOD
    return fact,invfact

def prime_factorization(n):
    assert(n>=2)
    factor=[]
    sqrt=int(n**.5)
    for d in range(2,sqrt+1):
        while(n%d==0):
            n//=d
            factor.append(d)
    if n!=1: factor.append(n)
    return factor

def resolve():
    from collections import Counter
    n,m=map(int,input().split())
    if(m==1):
        print(1)
        return
        
    P=prime_factorization(m)
    C=Counter(P)
    C=list(C.values())

    N=max(C)
    fact,invfact=modfact(N+n)

    ans=1
    for v in C:
        ans*=fact[v+n-1]*invfact[n-1]*invfact[v]
        ans%=MOD
    print(ans)
resolve()

Measured memory_bytes: 40432
#include <iostream>
#include <vector>
#include <math.h>

int main(void){

	int N, S;
	int sq_N;

	while(true){
		std::cin >> N;
		if(N==0) break;

		S = 0;
		sq_N = (int)sqrt(N);

		for(int i=1; i<=sq_N; i++){
			if(i==N) break;
			if(N%i==0){
				S+=i;
				if(N!=N/i && i!=N/i) S+=N/i;
			}
		}

		if(N==S) std::cout << "perfect number" << std::endl;
		else if(N>S) std::cout << "deficient number" << std::endl;
		else if(N<S) std::cout << "abundant number" << std::endl;
	
	}
	return 0;
}



Measured memory_bytes: 2988
N = int(input())
A = []
C2 = [0] * N
C5 = [0] * N
# for i in range(N):
#     s = str(input())
#     A.append(s)
#     ok = False
#     cnt = 0
#     l = len(A[i])
#     for j in range(l):
#         if A[i][j] == '.':
#             ok = True
#             cnt = j
#     if ok:
#         # 11桁になるまで+0
#         if cnt == 1:
#             while len(A[i]) < 11:
#                 A[i] += "0"
#         # 12
#         elif cnt == 2:
#             while len(A[-1]) < 12:
#                 A[i] += "0"
#     else:
#         A[i] += ".000000000"
#     tmp = ""
#     for j in range(len(A[i])):
#         if A[i][j] == '.':continue
#         tmp += A[i][j]
#     B.append(int(tmp))
P = 1000000000
for i in range(N):
    tmp = input().split(".")
    if len(tmp) == 2:
        a = int(tmp[1])
        for j in range(9-len(tmp[1])):
            a *= 10
        A.append(int(tmp[0]) * P + a)
    else:
        A.append(int(tmp[0]) * P)

for i in range(N):
    tmpp = A[i]
    tmp2 = A[i]
    while tmpp > 0:
        if tmpp % 2 == 0:
            tmpp //= 2
            C2[i] += 1
        else:
            break
    while tmp2 > 0:
        if tmp2 % 5 == 0:
            tmp2 //= 5
            C5[i] += 1
        else:
            break

Cc = [[0] * 19 for _ in range(19)]

for i in range(N):
    Cc[min(18, C2[i])][min(18, C5[i])]+=1

ans = 0
for i in range(N):
    l2 = max(0, 18 - C2[i])
    l5 = max(0, 18 - C5[i])
    for j in range(l2, 19):
        for k in range(l5, 19):
            ans += Cc[j][k]

for a in A:
    if a % 1000000000 == 0:
        ans -= 1

print(ans//2)

Measured memory_bytes: 87224
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep2(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
typedef long double ld;

int main(){
    string S; int K;
    cin >> S >> K;
    int L = S.size();

    vector<vector<ll>> f(L+1, vector<ll>(K+1)), g(L+1, vector<ll>(K+1));
    g[0][0] = 1;
    rep(i, L) f[i+1][0] = 1;

    rep(i, L) rep(j, K){
        int x = S[i] - '0';
        f[i+1][j+1] += 9 * f[i][j] + f[i][j+1];
        if(x > 0) f[i+1][j+1] += (x-1) * g[i][j] + g[i][j+1];

        if((x > 0 && g[i][j] == 1) || (x == 0 && g[i][j+1] == 1)) g[i+1][j+1] = 1;
    }
    cout << f[L][K] + g[L][K] << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        try {
            int T = Integer.parseInt(r.readLine());
            while (T-- > 0) {
                BigInteger a = new BigInteger(r.readLine());
                BigInteger b = new BigInteger(r.readLine());
                BigInteger c = a.add(b);
                String s = c.toString();
                if (s.length() > 80) s = "overflow";
                System.out.println(s);
            }
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    int ans = 0;
    int h[100002];
    for(int i = 0; i < n; i++){
        cin >> h[i];
        if(h[i] >= k) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640