akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    string S[16]={
            "AKIHABARA",
            "AKIHABAR",
            "AKIHABRA",
            "AKIHBARA",
            "KIHABARA",
            "AKIHABR",
            "AKIHBAR",
            "KIHABAR",
            "AKIHBRA",
            "KIHABRA",
            "KIHBARA",
            "AKIHBR",
            "KIHABR",
            "KIHBAR",
            "KIHBRA",
            "KIHBR"
    };
    string s;
    cin >> s;
    rep(i,0,16){
        if(s==S[i]){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


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

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

    long long total = 0;
    for(int pairIndex=0; pairIndex<N-1; pairIndex++){
        int first = pairIndex;
        int second = pairIndex+1;
        if(a[first] > x){
            int diff = a[first] - x;
            a[first] -= diff;
            total += diff;
        }
        if(a[first] + a[second] > x){
            int diff = a[first] + a[second] - x;
            a[second] -= diff;
            total += diff;
        }
    }

    cout << total << '\n';
}


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

int n;
int a[100005];
int k;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int tmp;
        scanf("%d", &tmp);

        if (a[tmp] == 0) {
            k++;
            a[tmp] = 1;
        }
    }

    if (k & 1) {
        printf("%d\n", k);
    }
    else {
        printf("%d\n", k - 1);
    }

    return 0;
}


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

#ifdef TESTING
  #include "dump.hpp"
#else
  #define DUMP(...)
  #define DEBUG(...)
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define VS(v,n) vector<string> v(n);REP(i,n){cin>>v[i];}

int main(){
  int ans = 0;
  INT(n); VS(ss, n);
  auto check = [&](int d){
    bool rtn = true;
    REP(i, n - 1){
      REP(j, i + 1, n){
        if (ss[i][(j + d) % n] != ss[j][(i + d) % n]){
          rtn = false;
          break;
        }
      }
    }
    return rtn;
  };
  REP(i, n){
    if (check(i)){ans += n;}
  }
  printf("%d\n", ans);
  return 0;
}


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

int main(){
  char mas[51][51];
  int h,w,memo[51][51];
  cin >> h >> w;
  memset(memo,0,sizeof(memo));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) cin >> mas[i][j];
  }
  for(int i=0;i<h-1;i++) memo[i+1][0] = mas[i+1][0]-'0' + memo[i][0];
  for(int i=0;i<w-1;i++) memo[0][i+1] = mas[0][i+1]-'0' + memo[0][i];
  for(int i=1;i<h;i++){
    for(int j=1;j<w;j++){
      memo[i][j] = min(memo[i-1][j],memo[i][j-1]) + (mas[i][j]-'0');
    }
  }
  cout << memo[h-1][w-1] << endl;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()


P cnt[55];
ll sum[55];

ll dfs(int now,ll x){
	if(now==-1)return 0;
	ll ret=0;
	if(x==sum[now]){
		return cnt[now].sc;
	}
	if(x>(sum[now]+1)/2){
		ret+=cnt[now-1].sc+1;
		ret+=dfs(now-1,x-(sum[now]+1)/2);
	}
	else if(x==(sum[now]+1)/2){
		ret+=cnt[now-1].sc+1;
	}
	else{
		ret+=dfs(now-1,x-1);
	}
	return ret;
}

int n;
ll x;

void input(){
	cin>>n>>x;
	return;
}

void solve(){
	cnt[0]=P(0,1);
	sum[0]=1;
	for(int i=1;i<=50;i++){
		cnt[i].fr=cnt[i-1].fr*2+2;
		cnt[i].sc=cnt[i-1].sc*2+1;
		sum[i]=sum[i-1]*2+3;
	}
	cout<<dfs(n,x)<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
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 getchar getchar_unlocked
#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int getint() {
	char C;
	while (!isdigit(C = getchar()));
	int x = C - '0';
	while (isdigit(C = getchar())) x = x * 10 + C - '0';
	return x;
}

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


	int N = getint();
	int X = getint();
	int S[200];
	rep(i, N) S[i] = getint();
	sort(S, S + N);

	ll mod = 1e9 + 7;

	ll dp[201][50001] = {};
	dp[N][50000] = 1;
	for (int i = N - 1; i >= 0; i--) {
		for (int k = 0; k < 50000; k++) {
			if (dp[i + 1][k]) {
				if (k >= S[i]) dp[i][k % S[i]] = (dp[i][k % S[i]] + dp[i + 1][k]) % mod;
				else dp[i][k] = dp[i + 1][k];
				dp[i][k] = (dp[i][k] + dp[i + 1][k] * i) % mod;
			}
		}
		if (dp[i + 1][50000]) {
			if (X >= S[i]) dp[i][X % S[i]] = (dp[i][X % S[i]] + dp[i + 1][50000]) % mod;
			else dp[i][50000] = dp[i + 1][50000];
			dp[i][50000] = (dp[i][50000] + dp[i + 1][50000] * i) % mod;
		}
	}

	ll kotae = dp[0][50000] * X % mod;
	for (int k = 0; k < 50000; k++) {
		kotae += dp[0][k] * k;
		kotae %= mod;
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 78720
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const double pi = acos(-1.0);

int main() {
	int n; cin >> n;
	VI a(n), b(n);
	rep(i, n)cin >> a[i] >> b[i];

	map<int, int> data;
	rep(i, n) {
		data[a[i]]++;
		data[b[i] + 1]--;
	}

	int ans = 0, now = 0;
	for (auto aa : data) {
		now += aa.second;
		ans = max(ans, now);
	}
	Cout(ans);
}


Measured memory_bytes: 12848
def bubblesort(arr_in)
  n = arr_in.length
  for i in 0..n-1
    (i+1..n-1).to_a.reverse.each do |j|
      if arr_in[j][1].to_i < arr_in[j-1][1].to_i
        tmp = arr_in[j]
        arr_in[j] = arr_in[j-1]
        arr_in[j-1] = tmp
      end
    end
  end
end

def selsort(arr_in)
  n = arr_in.length
  for i in 0..n-1
    mini = i
    for j in i..n-1
      if arr_in[j][1].to_i < arr_in[mini][1].to_i
        mini = j
      end
    end
    tmp = arr_in[mini]
    arr_in[mini] = arr_in[i]
    arr_in[i] = tmp
  end
end

if __FILE__ == $0
  num = STDIN.gets.to_i
  tokens = STDIN.gets.chomp!.split
  b_result = Marshal.load(Marshal.dump(tokens))
  bubblesort(b_result)
  puts b_result.join(" ")
  puts "Stable"
  s_result = Marshal.load(Marshal.dump(tokens))
  selsort(s_result)
  puts s_result.join(" ")
  flag = true
  for i in 0..num-1
    if b_result[i] != s_result[i]
      flag = FALSE
    end
  end
  if flag
    puts "Stable"
  else
    puts "Not stable"
  end
end

Measured memory_bytes: 8760
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;

using namespace std;
lli con = (int)pow(10,9) + 7;

vector<int> adj[2*(int)pow(10,5) + 1];
bool visited[2*(int)pow(10,5) + 1];
vector<int > cc;
int c; 
void dfs(int node){
    c+=1;
    visited[node] = true;
    
    for(ulli i=0;i<adj[node].size();i++){
        if(!visited[adj[node][i]]){
            dfs(adj[node][i]);
        }
        
    }
    
    
}


int main()
{
    int n,m;
    cin>>n>>m;
    int M = m;
    memset(visited,false,sizeof(visited));
    bool hash[n+1]={false};
    
    while(M--){
        int a,b;
        cin>>a>>b;
        hash[a] = true;
        hash[b] = true;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector<int > frds;
    for(int i=1;i<n+1;i++){
        if(hash[i]){
            frds.push_back(i);
        }
    }
    
    //int cc=0;
    for(ulli i=0;i<frds.size(); i++){
        if(!visited[frds[i]]){
            //cc+=1;
            c=0;
            dfs(frds[i]);
            cc.push_back(c);
        }
        
    }
    
    //cout<<cc<<" "<<frds.size()<<"\n";
    if(cc.size()==0){
        cout<<1<<"\n";
    }
    else{
     cout<<*max_element(cc.begin(),cc.end())<<"\n";
    }
    
    return 0;
}

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

int main(){
  ll a,b,c,d;
  cin >>a>>b>>c>>d;
  ll ans=-1000000000;
  if(a>=0 && c>=0){
    ans=b*d;
    cout << ans << endl;
    return 0;
  }
  if(a>=0 && d<=0){
    ans=a*d;
    cout << ans << endl;
    return 0;
  }
  if(b<=0 && c>=0){
    ans=b*c;
    cout << ans << endl;
    return 0;
  }
  if(b<=0 && d<=0){ 
    ans=a*c;
    cout << ans << endl;
    return 0;
  }
  ans=max(a*c,b*d);
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
class SegmentTree{
    private:
        static int calc_size(int n){
            int m = 1;
            while(m < n){
                m *= 2;
            }
            return m;
        }

        T query(int s, int t, int i, int l, int r) const {
            if(r <= s || t <= l){
                return init;
            }

            if(s <= l && r <= t){
                return node[i];
            }

            int m = l + (r - l) / 2;
            T vl = query(s, t, i * 2 + 1, l, m);
            T vr = query(s, t, i * 2 + 2, m, r);
            return f(vl, vr);
        }

    public:
        int n;
        vector<T> node;
        T init;
        function<T(T, T)> f;

        SegmentTree(int n, T init, function<T(T, T)> f)
            : n(calc_size(n)), node(calc_size(n) * 2, init), init(init), f(f){}

        void update(int i, const T& x){
            i += (n - 1);
            node[i] = x;
            while(i > 0){
                i = (i - 1) / 2;
                node[i] = f(node[2*i+1], node[2*i+2]);
            }
        }

        //[s, t)
        T query(int s, int t) const {
            return query(s, t, 0, 0, n);
        }
};

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

    int n;
    cin >> n;
    vector<int> h(n), a(n);
    rep(i, n) cin >> h[i];
    rep(i, n) cin >> a[i];

    SegmentTree<int> st(n+1, 0, [](int a, int b){return max(a, b);});
    rep(i, n){
        st.update(h[i], st.query(0, h[i]) + a[i]);
    }
    cout << st.query(0, n + 1) << endl;

    return 0;
}


Measured memory_bytes: 7424
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<cassert>
#include<sstream>
#include<numeric>
#include<iostream>
#include<algorithm>
#include<functional>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> Vi;
typedef pair<int,int> pii;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=2000+19;
const int K=10000+19;

const int p=1e9+7;

bitset<K> G[N],F[N];
string s[N],t[N];
int pw[K];
Vi ht[N],hs[N];
int n,k,nx,ny;
char str[K];

void Upd(int i,int x,int y){
	if (!F[i-1][x]) return;
	if (!nx&&!ny){
		nx=x,ny=y;
		F[i][x+y]=1;
		return;
	}
	int l=0,r=x+y;
	while (l<=r){
		int mid=(l+r>>1),las=0,cur=0;
		cur=(mid<=x?ht[i-1][mid]:(ht[i-1][x]+1ll*pw[x]*hs[i][mid-x])%p);
		las=(mid<=nx?ht[i-1][mid]:(ht[i-1][nx]+1ll*pw[nx]*hs[i][mid-nx])%p);
		if (cur==las) l=mid+1;else r=mid-1;
	}
	if (l-1==x+y){
		F[i][x+y]=1;
		return;
	}
	int ccur,clas;
	ccur=(l<=x?t[i-1][l-1]:s[i][l-x-1]);
	clas=(l<=nx?t[i-1][l-1]:s[i][l-nx-1]);
	if (ccur<clas){
		nx=x,ny=y;
		F[i][x+y]=1;
	}
	/*
	string cur=t[i-1].substr(0,x)+s[i].substr(0,y);
	string las=t[i-1].substr(0,nx)+s[i].substr(0,ny);
	if (las.substr(0,cur.length())==cur){
		F[i][x+y]=1;
		return;
	}
	if (cur<las){
		nx=x,ny=y;
		F[i][x+y]=1;
	}
	*/
}

int main(){
	pw[0]=1;
	For(i,1,K) pw[i]=23ll*pw[i-1]%p;
	n=IN(),k=IN();
	For(i,1,n+1){
		scanf("%s",str);
		s[i]=string(str);
	}
	For(i,0,n+1){
		hs[i].pb(0);
		For(j,0,s[i].length()){
			hs[i].pb((hs[i].back()+1ll*pw[j]*(s[i][j]-'a'))%p);
		}
	}
	G[n+1][0]=1;
	for (int i=n;i;i--){
		G[i]=G[i+1]|(G[i+1]<<s[i].length());
	}
	if (!G[1][k]){
		puts("QAQ");
		return 0;
	}
	F[0][0]=1;
	ht[0].pb(0);
	For(i,1,n+1){
		nx=0,ny=0;
		for (int j=k;~j;j--)
			if (G[i+1][k-j]){
				Upd(i,j,0);
				if (j>=s[i].length()){
					Upd(i,j-s[i].length(),s[i].length());
				}
			}
		For(j,0,nx) t[i]+=t[i-1][j];
		For(j,0,ny) t[i]+=s[i][j];
		ht[i].pb(0);
		For(j,0,t[i].length()){
			ht[i].pb((ht[i].back()+1ll*pw[j]*(t[i][j]-'a'))%p);
		}
		For(j,t[i].length()+1,k+1) F[i][j]=0;
	}
	puts(t[n].c_str());
}

Measured memory_bytes: 128896
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob)?EOF:*ib++;
}
inline int read(){
    char ch=gc();
    int res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int mod=998244353,G=3;
inline int add(int a,int b){return (a+=b)>=mod?(a-mod):a;}
inline int dec(int a,int b){a-=b;return a+(a>>31&mod);}
inline int mul(int a,int b){static ll r;r=1ll*a*b;return (r>=mod)?(r%mod):r;}
inline void Add(int &a,int b){(a+=b)>=mod?(a-=mod):0;}
inline void Dec(int &a,int b){a-=b,a+=a>>31&mod;}
inline void Mul(int &a,int b){static ll r;r=1ll*a*b;a=(r>=mod)?(r%mod):r;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
cs int N=32005;
int rev[N];
inline void init_rev(int lim){
	for(int i=0;i<lim;i++)rev[i]=(rev[i>>1]>>1)|((i&1)*(lim>>1));
}
inline void ntt(int *f,int lim,int kd){
	for(int i=0;i<lim;i++)if(i>rev[i])swap(f[i],f[rev[i]]);
	for(int a0,a1,mid=1;mid<lim;mid<<=1){
		int wn=ksm(G,(mod-1)/(mid<<1));
		for(int i=0;i<lim;i+=mid<<1)
		for(int j=0,w=1;j<mid;j++,Mul(w,wn))
		a0=f[i+j],a1=mul(f[i+j+mid],w),f[i+j]=add(a0,a1),f[i+j+mid]=dec(a0,a1);
	}
	if(kd==-1){
		reverse(f+1,f+lim);
		for(int i=0,iv=Inv(lim);i<lim;i++)Mul(f[i],iv);
	}
}
int fac[N],ifac[N];
inline void init_inv(cs int len=N-5){
	fac[0]=ifac[0]=1;
	for(int i=1;i<=len;i++)fac[i]=mul(fac[i-1],i);
	ifac[len]=Inv(fac[len]);
	for(int i=len-1;i;i--)ifac[i]=mul(ifac[i+1],i+1);
}
inline int C(int n,int m){return n<m?0:mul(fac[n],mul(ifac[m],ifac[n-m]));}
int lim,n,m,f[N],a[N],g[N];
int main(){
	#ifdef Stargazer
	freopen("lx.in","r",stdin);
	#endif
	n=read(),m=read();
	lim=1;init_inv();
	while(lim<=n*2)lim<<=1;
	init_rev(lim);
	for(int i=1;i<=n;i++)g[i]=ifac[i+2];
	ntt(g,lim,1);
	a[0]=1;
	for(int i=1;i<=m;i++){
		for(int j=0;j<=n;j++)f[j]=mul(a[j],ifac[j]);
		ntt(f,lim,1);
		for(int j=0;j<lim;j++)Mul(f[j],g[j]);
		ntt(f,lim,-1);
		for(int j=0;j<=n;j++)a[j]=add(mul(f[j],fac[j+2]),mul(a[j],(1+j+C(j,2))%mod));
		for(int j=0;j<lim;j++)f[j]=0;
	}
	int ret=0;
	for(int i=0;i<=n;i++)Add(ret,mul(C(n,i),a[i]));
	cout<<ret<<'\n';
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
using namespace std;
using ll = long long;
const int MAXN = 200001;

int a[MAXN];

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

	int n; cin >> n;
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);

	ll ans = a[0];
	map<int, int> spaces{{a[1], 2}};

	for (int i = 2; i < n; ++i){
		int best_space = spaces.rbegin()->first;
		ans += best_space;
		spaces[best_space]--;
		if (spaces[best_space] == 0){
			spaces.erase(best_space);
		}
		spaces[a[i]] += 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

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

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

    ll h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    set<P> st;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        st.insert(P(a, b));
    }
    vll cnt(10);
    set<P> seen;
    for (auto p : st) {
        int x = p.fi, y = p.se;
        rep(i, 9) {
            int cx = x + dx[i], cy = y + dy[i];
            if (cx-1 <= 0 || cx+1 > h || cy-1 <= 0 || cy+1 > w) continue;
            if (seen.count(P(cx, cy))) continue;
            int now = 0;
            for (int j = -1; j <= 1; j++) for (int k = -1; k <= 1; k++) if (st.count(P(cx+j, cy+k))) now++;
            cnt[now]++;
            seen.insert(P(cx, cy));
        }
    }
    cnt[0] = (h-2) * (w-2);
    for (int i = 1; i <= 9; ++i) cnt[0] -= cnt[i];
    rep(i, 10) cout << cnt[i] << endl;
    
}


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

int main(){
    int x;
    cin >> x;
    if(x >= 30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> L){
    int sum = 0;
    for(int i = 0; i < N; ++i) {
        sum += L[i];
    }
    for(int i = 0; i < N; ++i) {
        if (sum - L[i] <= L[i]) {
            cout << NO << endl;
            return;
        }
    }
    cout << YES << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int N;
  cin >> N;
  while(N--) {
    int n;
    int x,y,w,h;
    cin>>x>>y>>w>>h;
    cin >> n;
    int ans = 0;
    REP(i,n){
      int a,b;
      cin >>a>>b;
      if (x<=a&&a<=x+w&&y<=b&&b<=y+h)ans++;
    }
    cout << ans << endl;
  }

}

Measured memory_bytes: 0
#include<stdio.h>
#define MAX 100
#define INF 10000000

int main(){
    int i,n,l,j,k;
    int m[MAX][MAX];
    int p[MAX];
    int v=0;

    scanf("%d",&n);
    for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
    }

    for(i=1;i<=n;i++) m[i][i]=0;

    for(l=2;l<=n;l++){
        for(i=1;i<=n-l+1;i++){
            j=i+l-1;
            m[i][j]=INF;
            for(k=i;k<=j-1;k++){
                if(m[i][j]<m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]){
                    m[i][j]=m[i][j];
                }
                else if (m[i][j] > m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]){
                    m[i][j]=m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
                }
            }
        }
    }
    printf("%d\n",m[1][n]);

    return 0;
}


Measured memory_bytes: 2052
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mll map<ll,ll>
#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(c) c.begin(),c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a),greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define isu isupper
#define isl islower

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;



int main() {
    ll N;
    cin >> N;

    ll ans = 0;
    rep1 (i, N) ans += (N/i*i + i) * (N/i) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cassert>
#include<climits>
#include<algorithm>
#include<vector>
#include<deque>
#include<map>
#include<set>
#include<sstream>
#include<cstring>

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

using namespace std;

#define MAX_V 110
#define MAX_E 1010
int V, E, fw[MAX_V][MAX_V], a[MAX_E], b[MAX_E], c[MAX_E];

int main() {
  cin >> V >> E;
  rep(i,V) rep(j,V) fw[i][j] = INT_MAX;
  rep(i,V) fw[i][i] = 0;
  rep(i,E) {
    cin >> a[i] >> b[i] >> c[i];
    --a[i], --b[i];
    fw[a[i]][b[i]] = fw[b[i]][a[i]] = c[i];
  }
  rep(k,V) rep(i,V) rep(j,V) if( fw[i][k] != INT_MAX && fw[k][j] != INT_MAX ) fw[i][j] = min(fw[i][j],fw[i][k]+fw[k][j]);
  int cnt = 0;
  rep(i,E) {
    bool found = false;
    rep(s,V) rep(t,V) {
      if( fw[s][a[i]] + c[i] + fw[b[i]][t] == fw[s][t]  ) {
	found = true;
	break;
      }
    }
    if( !found ) ++cnt;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}

int main() {
  int a;
  cin>>a;
  cout<<(a+1)/2;
}

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

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		int x[] = new int[N];
		int y[] = new int[M];

		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
		}
		for (int i = 0; i < M; i++) {
			y[i] = sc.nextInt();
		}
		Arrays.sort(x);
		Arrays.sort(y);

		if (y[0] <= X) {
			System.out.println("War");
		} else if (x[N - 1] >= Y) {
			System.out.println("War");
		} else if (x[N - 1] >= y[0]) {
			System.out.println("War");
		}else {
			System.out.println("No War");
		}

	}
}

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



int main(){
  int K,N;
  cin>>K>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  
  vector<int> dis(N);
  for(int i=0;i<N-1;i++){
    dis.at(i)=vec.at(i+1)-vec.at(i);
  }
  dis.at(N-1)=K-vec.at(N-1)+vec.at(0);
  sort(dis.begin(),dis.end());
  cout<<K-dis.at(N-1)<<endl;
    
}

Measured memory_bytes: 1792
/*********************************************************************************\
*  _________  _      _  ________  _       _       __       ________               *
* |___   ___|| |    | ||  ______|| |     | |     /  \     |  ____  |              *
*     | |    | |    | || |______ | |_____| |    / /\ \    | |____| |              *
*     | |    | |    | ||______  ||  _____  |   / /__\ \   |  __  __|              *
*     | |    | |____| | ______| || |     | |  / ______ \  | |  \ \                *
*     |_|    |________||________||_|     |_| /_/      \_\ |_|   \_\               *
*                                                                                 *
*   Department of Computer Science & Engineering                                  *
*   Student ID : 18CSE035                                                         *
*   Bangabnadhu Sheikh Mujibur Rahman Science & Technology University,Gopalgonj.  *
*                                                                                 *
\*********************************************************************************/

//Now Write to Code ___________________________


#include <bits/stdc++.h>
using namespace std ;
 
 
typedef long long                ll;
typedef long double              ld;
typedef unsigned long long       ull;
typedef pair <int,int>           pii;
typedef pair <ll,ll>             pll;
typedef vector <int>             vi;
typedef vector <ll>              vll;
typedef vector <vector <int> >   vvi;
 
inline int    Int(){int x; cin >> x; return x;}
inline ll     Long(){ll x; cin >> x; return x;}
inline float  Float(){float x; cin >> x; return x;}
inline double Double(){double x; cin >> x; return x;}
inline void   Yes(){cout << "Yes" << endl;}
inline void   No(){cout << "No" << endl;}
inline void   YES(){cout << "YES" << endl;}
inline void   NO(){cout << "NO" << endl;}
 
const int N             =(int)2e5 + 5;
const int maxN          =(int)1e6 + 6;
const ll  Mod           =(ll)1e9 + 7;
const int inf           =(int)2e9;
const ll  Inf           =(ll)1e18;
 
#define     T           int t,q; cin >> t; for(q=1;q<=t;q++)
#define     debug(x)    cerr << #x << " = " << x << '\n' ;
#define     rep(i,b,e)  for(__typeof(e) i=(b); i!=(e+1)-2*(b > e); i =i+1-2*(b > e))
#define     Int         Int()
#define     Long        Long()
#define     Float       Float()
#define     Double      Double()
#define     all(x)      x.begin() , x.end()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
#define     biday       return 0 
 
 
int main()
{
	int K,A,B,i,c=1;
	cin >> K >> A >> B;

	for(i = A; i <= B; i++)
	{
		if(i%K==0)
		{
			cout << "OK" << endl;
			c=0;
			break;
		}
	}
	if(c)cout << "NG" << endl;
    

    biday;
}
 
//...............BYE BYE................

Measured memory_bytes: 3556
H, W = gets.split.map(&:to_i)
S = H.times.map { gets.chomp.chars }

H.times do |h|
  W.times do |w|
    next if S[h][w] == '.'
    next if h - 1 >= 0 && S[h - 1][w] == '#'
    next if h + 1 < H  && S[h + 1][w] == '#'
    next if w - 1 >= 0 && S[h][w - 1] == '#'
    next if w + 1 < W  && S[h][w + 1] == '#'

    puts 'No'
    exit
  end
end
puts 'Yes'

Measured memory_bytes: 1916
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    f = True
    ans = 0
    L = n-1
    for i in reversed(range(n)):
        if i < a[i] or a[i] < i-L:
            f = False
            break
        if i-L < a[i]:
            ans += a[i]
            L = i - a[i]
    if f:
        print(ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 11048
#include <iostream>

using namespace std;

int main()
{
    int n, m; cin >> n >> m;
    int total = 0;
    for (int i = 0; i < m; ++i) {
        int tmp;
        cin >> tmp;
        total += tmp;
    }

    int ans;
    if (n - total < 0) ans = -1;
    else ans = n - total;

    cout << ans << endl;

    return 0;
}


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

const int MAX = 210000;
const int MOD = 998244353;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int N, M, K;
long long mp[200100] = {};

void init() {
    mp[0] = M;
    for(int i=1; i<200100; ++i) {
        mp[i] = mp[i - 1] * (M - 1) % MOD;
    }
}

int main() {
    cin >> N >> M >> K;
    init(); COMinit();

    long long res = 0;
    for(int k=0; k<=K; ++k) {
        res = (res + COM(N - 1, k) * mp[N - 1 - k] % MOD) % MOD;
    }    
    cout << res << '\n';
}

Measured memory_bytes: 10100
let l, r = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ans = ref max_int
let _ = Printf.printf "%d\n" @@ if r - l + 1 >= 2019 then 0 else
  (for i = l to r do
    for j = i + 1 to r do ans := min !ans @@ i * j mod 2019 done done;
  !ans)

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

typedef pair<int,int> P;
struct edge{
	int to, d, c;
	edge(int to_, int d_, int c_){
		to = to_; d = d_; c = c_;
	}
	edge(){}
};

const int INF = 1e+8;
const int MAX_N = 10001;
int N, M;
vector<edge> G[MAX_N];
vector<int> from[MAX_N];
map<P,int> es;
int d[MAX_N];

void add_edge(int u, int v, int d, int c){
	G[u].push_back( edge(v, d, c) );
	G[v].push_back( edge(u, d, c) );
	es[P(u,v)] = es[P(v,u)] = c;
}
 
void dijkstra(){
	fill(d, d+MAX_N, INF);
	
	priority_queue<P, vector<P>, greater<P> > q;
	q.push( P(0, 0) );
	d[0] = 0;
	while( !q.empty() ){
		int dist = q.top().first;
		int v = q.top().second;
		q.pop();
		 
		if( d[v] < dist ) continue;
		 
		for(int i=0 ; i < G[v].size() ; i++ ){
			int to = G[v][i].to;
			int next_dist = G[v][i].d + dist;
			if( next_dist < d[to] ){
				from[to].clear();
				from[to].push_back( v );
				d[to] = next_dist;
				q.push( P(next_dist, to) );
			}else if( next_dist == d[to] ){
				from[to].push_back( v );
				q.push( P(next_dist, to) );
			}
		}
	}
}
 
int solve(){
	int res = 0;
	for(int v=0 ; v < N ; v++ ){
		int cost = INF;
		for(int i=0 ; i < from[v].size() ; i++ ){
			cost = min(cost, es[P(from[v][i], v)] );
		}
		if( cost != INF ){
			res += cost;
		}
	}
	return res;
}
 
int main(){
	while( cin >> N >> M , N || M ){
		// テ・ツ按敕ヲツ慊淌・ツ個?
		es.clear();
		for(int i=0 ; i < MAX_N ; i++ ){
			G[i].clear();
			from[i].clear();
		}
		 
		for(int i=0 ; i < M ; i++ ){
			int u, v, d, c;
			cin >> u >> v >> d >> c;
			u--, v--;
			add_edge(u, v, d, c);
		}
		dijkstra();
		cout << solve() << endl;
	}
}

Measured memory_bytes: 6328
n = int(input())
s1= input()
s2= input()
ans =3
if s1[0]!=s2[0]:
  ans = 6
  k = 2
  tate_flag = False
else:
  ans = 3
  k = 1
  tate_flag = True
  
flag =False
for i in range(k,n):
  if flag:
    flag = False
  elif s1[i]!=s2[i] and tate_flag:
    ans = ans * 2
    flag = True
    tate_flag = False
  elif s1[i]!=s2[i] and not tate_flag:
    ans = ans * 3
    flag = True
    tate_flag = False
  elif s1[i]==s2[i] and tate_flag:
    ans = ans *2
    tate_flag = True
  else:
    ans =ans*1
    tate_flag = True
  ans = ans % 1000000007
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#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(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif
struct UnionFind{
	vector<int> par,rank,szv,sze;
	UnionFind(int N){
		par.assign(N,0);
		rank.assign(N,0);
		szv.assign(N,1);
		sze.assign(N,0);
		rep(i,N) par[i]=i;
	}
	int find(int x){
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
//		cerr << "unite " << x << ", " << y << endl;
		x=find(x),y=find(y);
		sze[x]++;
		if(x==y) return;
		if(rank[x]<rank[y]) swap(x,y);

		//x becomes root
		par[y]=x;
		szv[x] += szv[y];
		sze[x] += sze[y];
		if(rank[x]==rank[y]) rank[x]++;
	}
};
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N,H,W;
	cin >> N >> H >> W;

	UnionFind UF(H+W);
	VV<int> a(N);
	rep(i,N){
		int x,y,c;
		cin >> x >> y >> c;
		x--,y--;
		a[i] = {c,x,y};
	}
	sort(all(a),greater<V<int>>());
	ll ans = 0;
	rep(i,N){
		int x = a[i][1], y = a[i][2], c = a[i][0];
		show(i);
		show(c);
		y += H;
		if(UF.same(x,y)){
			int r = UF.find(x);
			if(UF.szv[r] != UF.sze[r]){
				UF.unite(x,y);
				ans += c;
			}
		}else{
			int rx = UF.find(x), ry = UF.find(y);
			if(UF.szv[rx] + UF.szv[ry] >= UF.sze[rx] + UF.sze[ry] + 1){
				UF.unite(x,y);
				ans += c;
			}
		}
		show(ans);
	}
	cout << ans << endl;
}


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

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> L(M);
	vector<int> R(M);
	for(int i = 0; i < M; ++i) cin >> L[i] >> R[i];

	int max = 0;
	int min = 1000000;
	for(int i = 0; i < M; ++i) {
		if(max < L[i]) {
			max = L[i];
		}

		if(min > R[i]) {
			min = R[i];
		}
	}

    if(min >= max) {
        cout << (min - max + 1) << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		final String consta = "red";
		boolean out = false;
		int i;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			try {
				String ppp = Integer.valueOf(br.readLine()) >= 3200 ? br.readLine():consta;
				System.out.println(ppp);
			} catch (NumberFormatException | IOException e) {
				// TODO Auto-generated catch block
				return;
			}
		}

	}

}


Measured memory_bytes: 20692
n = int(input())
a = []
xy = [list() for _ in range(n)]

for i in range(n):
    a += [int(input())]
    for j in range(a[i]):
        xy[i] += [list(map(int,input().split()))]


honestnum = []

for i in range(2**n):
    flag = True
    #(if bin(i).count("1") == _:)
    #print("次のiいくよー"+"i:"+str(i)+",2進法で"+str(bin(i))[2:])
    for j in range(n):
        if (i>>j)&1 == 1:
            #print("下から"+str(j+1)+"桁目は1,つまり,index"+str(j)+"が1だね")
            for k in range(a[j]):
                if xy[j][k][1] != (i>>(xy[j][k][0]-1)&1):
                    flag = False
                    break
        
    if flag:
        #print("わーい")
        honestnum += [bin(i).count("1")]
print(max(honestnum))


Measured memory_bytes: 9176
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
void print() { cout << "\n"; }
template <class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////

using pc = pair<char, int>;
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int N = S.size();

    vector<ll> A(N+1);
    queue<int> que;
    if (S[0]=='<') que.emplace(0);
    if (S.back()=='>') que.emplace(N);
    for (int i = 1; i < N; i++) {
        if (S[i-1]=='>' and S[i]=='<') que.emplace(i);
    }
    while (!que.empty()) {
        int v = que.front(); que.pop();
        if (v and S[v-1]=='>') {
            chmax(A[v-1],A[v]+1);
            que.emplace(v-1);
        }
        if (v < N and S[v]=='<') {
            chmax(A[v+1],A[v]+1);
            que.emplace(v+1);
        }
    }
    cout << accumulate(all(A),0LL) << ln;

}


Measured memory_bytes: 5660
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    long double d;
    map<pair<int, int>, int> m;
    long long int ans = 0;
    int max2 = 0, max5 = 0;
    for(int i=0; i<n; i++){
        cin >> d;
        long long int a = llround(d*1e9);
        int pow2 = 0, pow5 = 0;
        while(a%2==0){
            pow2++;
            a /= 2;
        }
        while(a%5==0){
            pow5++;
            a /= 5;
        }
        max2 = max(max2, pow2);
        max5 = max(max5, pow5);
        ++m[{pow2,pow5}];
    }
    for(int i=0; i<=max2; i++){
        for(int j=0; j<=max5; j++){
            for(int k=i; k<=max2; k++){
                for(int l=0; l<=max5; l++){
                    if(i==k && l<j)
                        continue;
                    if(i+k>=18 && j+l>=18){
                        if(i==k && j==l){
                            ans += (long long int)m[{i,j}]*(m[{i,j}]-1)/2;
                        }else
                        ans += (long long int)m[{i,j}]*m[{k,l}];
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3752
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL n, m, x[112345], y[112345];
LL prev, res_x, res_y;

int main()
{
	in >> n >> m;
	rep(i, n) { in >> x[i]; }
	rep(i, m) { in >> y[i]; }

	for (LL i = 1; i < n; ++i)
	{
		LL bef = x[i] - x[i - 1];
		res_x += (prev + bef*i);
		prev += bef*i;
		res_x %= MOD, prev %= MOD;
	}
	prev = 0;
	for (LL i = 1; i < m; ++i)
	{
		LL bef = y[i] - y[i - 1];
		res_y += (prev + bef*i);
		prev += bef*i;
		res_y %= MOD, prev %= MOD;
	}
	
	out << (res_x*res_y) % MOD << std::endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int D;
  cin >> D;
  vector<int> c(26);
  rep(i, 26) cin >> c[i];

  vector<vector<int>> s(D);
  rep(d, D)
  {
    s[d].resize(26);
    rep(i, 26)
    {
      cin >> s[d][i];
    }
  }

  vector<int> last(26, 0);

  long long score = 0;
  rep(i, D)
  {
    long long mx = score;
    vector<int> mx_last;
    long long mx_a = 1;
    rep(a, 26)
    {
      long long bak_score = score;
      vector<int> bak = last;

      score += s[i][a];
      last[a] = i + 1;
      rep(j, 26)
      {
        score -= c[j] * (i + 1 - last[j]);
      }
      if (mx < score)
      {
        mx = score;
        mx_last = last;
        mx_a = a + 1;
      }
      last = bak;
      score = bak_score;
    }
    last = mx_last;
    score = mx;
    cout << mx_a << endl;
  }

  return 0;
}


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

int main() {
	int W,H,N;
	cin >> W >> H >> N;
	int x,y,a, l=0,r=W,t=H,b=0;
	for(int i=0; i<N; i++){
		cin >> x >> y >>a;
		
		if(a==1&&x>l){l=x;}
		else if(a==2&&x<r){r=x;}
		else if(a==4&&t>y){t=y;}
		else if(a==3&&b<y){b=y;}
		
	}
	
	if(r<l||t<b){cout << 0 << endl;}
	else{cout << (r-l)*(t-b) << endl;}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main()
{
	cin >> n >> m;
	vi v(m);
	REP(i, m) cin >> v[i];
	while (1) {
		s = to_string(n);
		bool  flag = 0;
		REP(i, s.size())
		{
			REP(j, m)
			{
				if (s[i] - '0' == v[j]) {
					flag = 1;
					break;
				}
			}
		}
		if (flag == 0) {
			cout << s << endl;
			return 0;
		}
		n++;
	}
}

Measured memory_bytes: 256
num = [ 0 for i in range(10**6)]

for i in range(1,150):
    for j in range(1,150):
        for k in range(1,150):
            tmp = i**2+j**2+k**2+i*j+j*k+k*i
            #num[tmp].append((i,j,k))
            num[tmp] += 1
N = int(input())

for i in range(1,N+1):
    print(num[i])

Measured memory_bytes: 141992
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();

        if(A % 3 == 0 || B % 3 ==0 || (A + B) % 3 == 0){
            System.out.println("Possible");
        }else{
            System.out.println("Impossible");
        }
    }
}


Measured memory_bytes: 23892
#include<stdio.h>

int abs(int n){
    if(n>=0) return n;
    else return -n;
}

int min(int a,int b){
    if(a>=b) return b;
    else return a;
}

int mini(int N,int *u,int A,int B,int C){
    int m=10000;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                if(i!=j && j!=k && k!=i)
                m=min(m,abs(A-u[i])+abs(B-u[j])+abs(C-u[k]));
            }
        }
    }
    return m;
}

void keta(int *k,int n){
    int l=n;
    for(int i=1;i<=8;i++){
        k[(i-1)]=l%2;
        l=l/2;
    }
}

int ketasouwa(int *k,int N){
    int c=0;
    for(int i=0;i<N;i++){
        c+=k[i];
    }
    return c;
}

int part(int N,int *u,int A,int B,int C){
    int k[8],n[8],e=10000;
    if(N>3){
        for(int i=0;i<N;i++){
            for(int x=0;x<i;x++){
                int y=0;
                int s=0;
                for(int j=0;j<N;j++){
                    if(j!=i && j!=x){
                        n[y]=u[j];
                        y++;
                    }else{
                        s+=u[j];
                    }
                }
                n[y]=s;
                e=min(e,10+part(N-1,n,A,B,C));
            }  
        }
    }
    e=min(e,mini(N,u,A,B,C));
    return e;
}

int main(void){
    int N,A,B,C,l[8],minMP;
    scanf("%d %d %d %d",&N,&A,&B,&C);
    for(int i=0;i<N;i++){
        scanf("%d",&(l[i]));
    }

    minMP=part(N,l,A,B,C);
    printf("%d",minMP);

    return 0;
}
/*test
1.
5 100 90 80
98
40
30
21
80
->23
2.
8 100 90 80
100
100
90
90
90
80
80
80
->0
3.
8 1000 800 100
300
333
400
444
500
555
600
666
->243
*/

Measured memory_bytes: 128