akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

int cum[200020];
int func(string s) {
	if (s.size() <= 1)return 0;
	m0(cum);
	int res = 0;
	int n = s.size();
	REP(i, n) {
		cum[i + 1] += cum[i];
		if (s[i] == 'o')cum[i + 1]++;
	}
	REP(i, n) {
		if (s[i] == 'x') {
			res += cum[i];
		}
	}
	return res;
}
signed main() {
	/*cin.tie(0);
	ios::sync_with_stdio(false);*/
	string S; cin >> S;
	vector<string>v;
	int N = S.size();
	int pos = 0;
	string str; int ans = 0;
	while (pos < N) {
		if (S[pos] == 'A') {
			str += "o";
			pos++;
		}
		else if (pos < N - 1 && S[pos] == 'B'&&S[pos + 1] == 'C') {
				str += 'x';
				pos += 2;
		}
		else {
			ans += func(str);
			str = "";
			pos++;
		}
	}
	ans += func(str);
	print(ans);
}


Measured memory_bytes: 2568
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    long long int n,k; cin >> n >> k;
    vector<long long int> divd, a(n); rep(i,n) cin >> a[i];
    vector<ll> ad(n);
    long long int sum = 0;
    rep(i,n) sum = sum + a[i];
    for(long long int i=1; i*i <= sum; i++){
        if(sum%i == 0){ divd.pb(i); divd.pb(sum/i);}
    }
    sort(all(divd), greater<ll>());
    long long int ans;
    for(auto d: divd){
        long long int ds = 0;
        for(int i=0;i<n;i++){
            ad[i] = (d - (a[i]%d))%d;
        }
       sort(all(ad));
        int r = n-1;
        int t = 0;
        for(int i=0; i<r;i++){
            //for(auto x: ad) cout << x << " ";
            //cout << endl;
            int dif = ad[i];
            t += dif;
            ad[i] = 0;
            while(dif!=0){
                if(d-ad[r] < dif){
                    dif -= d-ad[r];
                    ad[r]=0;
                    r--;
                }else{
                    ad[r] = (ad[r]+dif) % d;
                    dif = 0;
                    if(ad[r]==0) r--;
                }
            }

        }
      //  cout << d << ":" << t << endl;
        if(t <= k){ans = d; break;} 

    }
    cout << ans << endl;
}

Measured memory_bytes: 888
# -*- coding: utf-8 -*-


def is_acgt(s):
    if s=='A' or s=='C' or s=='G' or s=='T':
        return 1
    else: return 0


x = raw_input()


count = []
c = 0
for s in x:
    a = is_acgt(s)
    if a == 0:
        count.append(c)
        c = 0
        continue
    else:
        c += 1

    count.append(c)

if len(count)==0:
    print 0
    exit()
print max(count)


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int n;
vector<ll> a;

ll dp[200005][2][3];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    a.resize(n);
    for(auto &it : a) {
        cin >> it;
    }
    for(int i = 0; i < n + 1; i++) {
        for(int j = 0; j < 2; j++) {
            for(int k = 0; k < 3; k++) {
                dp[i][j][k] = -LLINF;
            }
        }
    }
    dp[0][0][0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 2; j++) {
            for(int k = 0; k < 3; k++) {
                // えらぶ
                if(j == 0) {
                    chmax(dp[i + 1][1][k], dp[i][j][k] + a[i]);
                }
                // えらばない
                if(j == 0 && k < 2) {
                    chmax(dp[i + 1][0][k + 1], dp[i][j][k]);
                } else if(j == 1) {
                    chmax(dp[i + 1][0][k], dp[i][j][k]);
                }
            }
        }
    }
    if(n % 2) {
        cout << max(dp[n][1][2], dp[n][0][1]) << endl;
    } else {
        cout << max(dp[n][0][0], dp[n][1][1]) << endl;
    }
}

Measured memory_bytes: 14268
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
#define foreach(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++ it)

inline int read() {
	int x = 0, f = 1, c = getchar();
	for (;!isdigit(c);c = getchar()) if (c == '-') f ^= 1;
	for (; isdigit(c);c = getchar()) x = x * 10 + c - '0';
	return f ? x : -x;
}

int n, m;
vi g[1005];
int vis[1005];
int stk[1005], tp;
bool has;
int cyc[1005], cnt;

void dfs(int u) {
	vis[u] = -1;
	stk[tp ++] = u;
	rep(i, g[u].size()) {
		int v = g[u][i];
		if (!vis[v]) dfs(v);
		else if (vis[v] == -1) {
			has = 1;
			do cyc[cnt ++] = stk[-- tp]; while (stk[tp] != v) ;
			reverse(cyc, cyc + cnt);
		}
		if (has) return;
	}
	vis[u] = 1;
	-- tp;
}

int main() {
	n = read(), m = read();
	rep(i, m) {
		int u = read() - 1, v = read() - 1;
		g[u].pb(v);
	}
	rep(i, n) if (!has && !vis[i]) dfs(i);
	if (!has) {
		puts("-1");
		return 0;
	}
	rep(i, cnt) {
		int mx = -1;
		rep(j, g[cyc[i]].size()) {
			int id = -1;
			for (int k = 0; k < cnt; ++ k) {
				if (cyc[k] == g[cyc[i]][j]) id = k;
			}
			if (!~id) continue;
			if ((id < i ? id + cnt : id) > mx) mx = (id < i ? id + cnt : id);
		}
		if (mx < cnt) {
			for (int j = mx; j < cnt; ++ j) cyc[j - (mx - i - 1)] = cyc[j];
			continue;
		}
		for (int j = mx - cnt; j < cnt; ++ j) cyc[j - (mx - cnt)] = cyc[j];
		cnt -= (mx - cnt) + (cnt - i - 1);
	}
	printf("%d\n", cnt);
	rep(i, cnt) printf("%d\n", cyc[i] + 1);
	return 0;
}


Measured memory_bytes: 384
S = input()
T = input()
list1 = {}
list2 = {}

flag = True
for i in range(len(S)):
    if S[i] in list1.keys():
        if list1[S[i]] != T[i]:
            flag = False
    if T[i] in list2.keys():
        if list2[T[i]] != S[i]:
            flag = False
    list1[S[i]] = T[i]
    list2[T[i]] = S[i]

if flag:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
void Iswap(int *a,int *b){
  int t=*a;
  *a=*b;
  *b=t;
}
void Fswap(double *a,double *b){
  double t=*a;
  *a=*b;
  *b=t;
}
void Lswap(ll *a,ll *b){
  ll t=*a;
  *a=*b;
  *b=t;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;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;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}
ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}
int main(void){
  int a,b;
  INI(a);
  INI(b);
  char s[2][10]={"safe","unsafe"};
  PRS(s[(a<=b)]);
  return 0;
}

Measured memory_bytes: 1640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    ll foo = 1, bar = 1;
    for(int i = 0; i < n; ++i){
        int t, a;
        cin >> t >> a;
        ll hoge = foo / t, hoge2 = bar / a;
        if(foo % t != 0)    ++hoge;
        if(bar % a != 0)    ++hoge2;
        ll m = max(hoge, hoge2);
        foo = m * t, bar = m * a;
    }
    ll ans = foo + bar;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a+b+c == 5+7+5)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define MOD 1e9+7
#define sp ' '


using ll = long long;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    vector<int> x(m);
    rep(i, m){
        cin >> x[i];
    }

    sort(x.begin(), x.end());

    if(n >= m){
        ppp(0);
        return 0;
    }
    vector<int> diff(m-1);
    for(int i = 0; i < m-1; ++i){
        diff[i] = x[i+1] - x[i];
    }
    sort(diff.rbegin(), diff.rend());

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

    ppp(ans);




    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;


int main() {
	vector<string>s(3);
	cin >>s[0]>>s[1]>>s[2];
	int tmp = 0;
	while(1) {
		if (s[tmp].size() == 0) {
			if (tmp == 0) {
				cout << "A" << endl; break;
			}
			else if (tmp == 1) {
				cout << "B" << endl; break;
			}
			else if (tmp == 2) {
				cout << "C" << endl; break;
			}
		}
        if (s[tmp][0] == 'a') {
			
			s[tmp].erase(0, 1);
			//cout << s[tmp].size()<< endl;
			tmp = 0;
		}
		else if (s[tmp][0] == 'b') {
			s[tmp].erase(0, 1);
			//cout << s[tmp].size() << endl;
			tmp = 1;
		}else if (s[tmp][0] == 'c') {

			s[tmp].erase(0, 1);
			//cout << s[tmp].size() << endl;
			tmp = 2;

		}
	}
}

    

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

int resmin(int a,int b){return a>b?b:a;}
int resmax(int a,int b){return a>b?a:b;}

int main(int argc,char *argv[]){
    int n;
    cin>>n;
    vector<vector<int>> a(n,vector<int>(3));
    vector<vector<int>> dp(n+1,vector<int>(3,0));

    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    for(int i=0;i<3;i++)dp[0][i]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k)continue;
                int temp=dp[i][j]+a[i][k];
                int temp2=dp[i+1][k];

                if(temp>temp2){
                    dp[i+1][k]=temp;
                }
            }
        }
    }
    int max=dp[n][0];
    if(max<dp[n][1]){
        max=dp[n][1];
    }
    if(max<dp[n][2]){
        max=dp[n][2];
    }
    cout<<max<<endl;
}

Measured memory_bytes: 11136
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> cnt(n,0);
    vector<vector<ll>> edge(n);
    for(int i=1;i<m+n;i++){
        ll A,B;
        cin>>A>>B;
        A--; B--;
        edge[B].push_back(A);
        cnt[A]++;
    }
    queue<ll> Q;
    for(int i=0;i<n;i++){
        if(cnt[i]==0){Q.push(i);}
    }
    vector<ll> A;
    vector<ll> where(n,-1);
    while(!Q.empty()){
        ll w=Q.front(); Q.pop();
        where[w]=A.size();
        A.push_back(w);
        for(auto &I:edge[w]){
            cnt[I]--;
            if(cnt[I]==0){
                Q.push(I);
            }
        }
    }
    vector<ll> p(n,E);
    for(int i=0;i<n;i++){
        for(auto &I:edge[i]){
            p[i]=min(p[i],where[I]);
        }
    }
    for(int i=0;i<n;i++){
        if(p[i]==E){cout<<0<<endl;}
        else{
            cout<<A[p[i]]+1<<endl;
        }
    }
    
    
    
    
    return 0;
}


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


int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int minus=0;
  rep(i,n) {
    int x;
    cin >> x;
    if(x<0) {
      minus++;  x=-x;
    }
    a[i]=x;
  }
  sort(rng(a));
  ll sum=0;
  rep(i,n) sum+=a[i];
  if(minus%2==1) sum-=2*a[0];
  cout << sum << endl;
  return 0;
}

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

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

int main() {
    ll a,b,v,w,t;
    cin>>a>>v>>b>>w>>t;
    
    ll tmp;
    
        tmp = abs(a - b) -(v-w)*t;
        if(tmp <= 0)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define eb emplace_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define cinarr(A,len) for(int i=0;i<len;i++){cin>>A[i];}
#define coutarr(A,len) for(int i=0;i<len;i++){cout<<A[i]<<' ';}cout<<endl
#define coutin(V) for(auto& i : V){cout << i << ' ';}cout<<endl // for vect and set
#define coutmap(U) for(auto& i : U){cout << i.first << "->" << i.second << ", ";}cout<<endl // for map
#define deb(x) cerr << #x << '\t' << x << endl
const int imax = numeric_limits<int>::max(), imin = numeric_limits<int>::min();
const long long	lmax = numeric_limits<long long>::max(), lmin = numeric_limits<long long>::min();
/*========================================================================*/
/* strategi/note:



/================================*/



bool Svd=0;
void solve(){Svd=1;
    int n;
    cin >> n;
    bool same[n];
    int d1,d2;
    for(int i = 0; i<n; i++){
        cin >> d1 >> d2;
        same[i] = d1==d2;
    }
    int running = 0;
    for(int i = 0; i<n; i++){
        if(same[i]){
            running ++;
            if(running == 3){
                cout << "Yes" << endl;
                return;
            }
        }
        else{
            if(running == 3){
                cout << "Yes" << endl;
                break;
            }
            running = 0;
        }
    }
    if(running == 3){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


/*========================================================================*/

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
//cout<<fixed<<setprecision( ); // iomanip **

 solve();
 //int t;cin>>t;while(t--){solve();}

if(!Svd)cout<<"solve() function blm dipanggil!"<<endl;
//cout.flush(); cin.get();
return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    string s[n];
    set<string>ss;
    map<string,int>mm;
    for(int i=0;i<n;i++){
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
        ss.insert(s[i]);
        mm[s[i]]++;
    }

    long ans = 0;
    
    for(string sss:ss){
        long tmp = mm[sss];
        ans += tmp * (tmp-1)/2;
    }
    cout << ans << endl;
    
    
    

}

Measured memory_bytes: 27648
#!/usr/bin/env python3

S = list(input())
count = {}
count['a'] = S.count('a')
count['b'] = S.count('b')
count['c'] = S.count('c')

if abs(count['a']-count['b']) < 2 and abs(count['a']-count['c']) < 2 and abs(count['b']-count['c']) < 2:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3956
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
total_vote = sum(a)
ischoose = True

for i in range(m):
    if(a[i]< total_vote*(1/(4*m))):
        ischoose = False
    

if(ischoose == False):
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<pll> vll; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL);
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.length();i++){
        sum+=s[i]-'0';
    }
    if(sum%9==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;

int main()
{
    ll h, w, ans = 0;
    cin >> h >> w;
    if (h == 1 || w == 1)
    {
        ans = 1;
    }
    else
    {
        ans = (h * w + 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n%2==1){
        cout<<"No";
        return 0;
    }
    string s1=s.substr(n/2,n/2);
    string s2=s.substr(0,n/2);
    if(s1==s2) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, m;
	cin >> n >> m;
	
	priority_queue<ll> q;
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		q.push(a);
	}
	
	ll ans = 0;
	while( !q.empty() ) {
		ll tmp = q.top();
		q.pop();
		
		if( m > 0 ) {
			q.push(tmp / 2);
			m--;
		} else {
			ans += tmp;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1400
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++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>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
// for (int bit = (1<<k)-1; bit < (1<<n); bit = next_combination(bit))

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

    int n, k;
    cin >> n >> k;
    for (int bit = (1<<k)-1; bit < (1<<n); bit = next_combination(bit)) {
        cout << bit << ":";
        rep(i, n) if (bit >> i & 1) cout << " " << i;
        cout << endl;
    }
}



Measured memory_bytes: 3212
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000



int main(void) {
	int n; cin >> n;
	rep(i, 3) {
		if (n % 10 == 7) {
			cout << "Yes" << endl;
			return 0;
		}
		n /= 10;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int main()
{
    long long a,b,k,d=0,m=0;
    cin>>a>>b>>k;
    if(a>=k)
    {
        d=a-k;
        cout<<d<<" "<<b<<endl;
    }
    else if(k>a)
    {
        d=k-a;
        m=b-d;
        if(d>b)
        {
            cout<<0<<" "<<0<<endl;
        }
        else if(b>=d)
        {
            cout<<0<<" "<<m<<endl;
        }
    }
    return 0;

}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

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




int main(){
    int n; cin >> n;
    // info[i][j]: i人目が正直の時 j人目は (-1:不明 1:正直 0:不親切)
    vector<VI> info(n, VI(n, -1));
    REP(i, n){
        info[i][i] = 1;
        int a; cin >> a;
        REP(j, a){
            int x, y; cin >> x >> y;
            --x;
            info[i][x] = y;
        }
    }

    int ans = 0;
    REP(i, 1<<n){
        VI fact(n); int ii = i;
        int honest = 0;
        REP(j, n){
            fact[j] = (ii & 1);
            if(fact[j]) ++honest;
            ii /= 2;
        }
        
        bool okay = true;
        REP(j, n){
            if(!fact[j]) continue;
            REP(k, n){
                if(info[j][k] == -1) continue;
                
                if(info[j][k] != fact[k]) okay = false;
            }
        }
        if(okay) chmax(ans, honest);
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
ans = ""
for i in range(0,len(S)):
  tmp = alphabet.index(S[i])
  tmp = (tmp + N) % 26
  #print(tmp)
  #print(alphabet[tmp])
  ans = ans + alphabet[tmp]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;

int main() {
  ll h, w;
  cin >> h >> w;
  
  ll tmp = 0;
  ll ans = 0;
  if(h == 1 || w == 1) {
    cout << 1 << endl;
    return 0;
  }
  if(w % 2 == 1) {
    tmp = w / 2 + 1;
  } else {
    tmp = w / 2;
  }
  ans = (w * (h-1)) / 2 ;
  if(h % 2 == 1) {
    cout << ans + tmp << endl;
  } else {
    ans = (w * h) / 2;
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int[] b = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {
            b[i] = in.nextInt();
        }
        int result = 0;
        for (int i = 1; i < n - 1; i++) {
            result += Math.min(b[i], b[i - 1]);
        }
        result += b[0];
        result += b[n-2];
        System.out.println(result);
    }
}


Measured memory_bytes: 24404
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int a,b;
	while(1){
		cin >> a >> b;
		if(a==0&&b==0) break;
		if(a>b) swap(a,b);
		cout << a <<" " <<  b << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

Vec pn;

bool isPrime(ll n){
	if(n == 1) return false;
	for(ll i : pn){
		if(i * i > n) return true;
		if(n % i == 0) return false;
	}
	return true;
}

void init(ll n = 2e5){
	pn.pb(2);
	REP(num, 3, n) if(isPrime(num)) pn.pb(num);
}

VecP primeFactorization(ll n){
	VecP res;

	for(ll i : pn){
		ll cnt = 0;
		while(n % i == 0){
			n /= i;
			cnt++;
		}
		if(cnt) res.pb({i, cnt});
		if(n < i * i) break;
	}
	if(n != 1) res.pb({n, 1});

	return res;
}

Vec divisorEnumeration(ll n){
	auto v = primeFactorization(n);

	Vec res, a, b, cp;
	res.pb(1);
	for(auto p : v){
		cp.resize(res.size());
		copy(all(res), cp.begin());
		a.resize(res.size());
		repn(k, p.sc){
			ll t = pow(p.fs, k);
			rep(i, a.size()) a[i] = cp[i] * t;
			res.insert(res.end(), all(a));
		}
	}

	return res;
}

int main(void){
	init();
	ll n;
	cin >> n;
	Vec a(n);
	rep(i, n) cin >> a[i];

	multiset<ll> st;
	rep(i, n) st.insert(a[i]);

	ll ans = 0;
	rep(i, n){
		st.erase(st.find(a[i]));
		auto v = divisorEnumeration(a[i]);
		bool flg = true;
		for (ll j : v){
			if(st.find(j) != st.end()){
				flg = false;
				break;
			}
		}
		if (flg) ans++;
		st.insert(a[i]);
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 14480
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int n;
vector<double> t, v;
int idx;
double pos, sp;

bool speedUp(){
	range(i,idx,n){
		if((sp + 0.5) - (t[i] - pos - 0.5) > v[i + 1]){
			return false;
		}
	}
	return true;
}

bool keep(){
	range(i,idx,n){
		if(sp - (t[i] - pos - 0.5) > v[i + 1]){
			return false;
		}
	}
	return true;
}

int main(){
	cin >> n;

	t = vector<double>(n);
	v = vector<double>(n);
	cin >> t >> v;
	range(i,1,n) t[i] += t[i - 1];
	v.emplace_back(0);

	double ans = 0;
	while(idx < n){
		if(speedUp()){
			sp = min(v[idx], sp + 0.5);
		}else if(keep()){
			;
		}else{
			sp -= 0.5;
		}
		pos += 0.5;
		ans += sp;
		//cout << sp << ' ' << pos << endl;
		if(t[idx] <= pos) idx++;
	}
	cout << fixed << setprecision(10) << ans / 2 << endl;
}


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

using namespace std;

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

int main(){
  double a, b, x;
  cin >> a >> b >> x;
  x /= a;
  if(x > a * b / 2){
    x = (a * b - x) / a * 2 / a;
  }else{
    x = b / (x / b * 2);
  }
  printf("%.10f\n", atan(x) * 180 / M_PI);
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	fast;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	if(d==1)cout<<1<<endl;
	else cout<<0<<endl;
	return 0;
}/*『你强归你强，我永不示弱』*/





Measured memory_bytes: 256
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    n,k = map(int,input().strip().split())      # 1 <= k <= n <= 2*10^5
    p = list(map(lambda n: Fraction( int(n)+1,2 ), input().strip().split())) # p[i] <= 10^3

    xsum=sum(p[0:k]) # 0 <= i < k
    ans=xsum
    for i in range(k,n):    # k <= i < n
        xsum = xsum + p[i] - p[i-k]
        ans = max(ans,xsum)
    print(float(ans))


if __name__ == '__main__':
    main()

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


int test(int current,int max_day,int p_up,int price1,int price2){
  if(current==max_day and current>p_up){
    return price2;
  }
  else if(current==max_day and current<=p_up){
    return price1;
  }
  
  else if(current<=p_up){
    return test(current+1,max_day,p_up,price1,price2)+price1;
  }
  else if(current>p_up){
    return test(current+1,max_day,p_up,price1,price2)+price2;
  }
}

int main(){
  int n,k,x,y;
  cin>>n;
  cin>>k;
  cin>>x;
  cin>>y;
  
  cout<<test(1,n,k,x,y);
}

Measured memory_bytes: 256
# 2020/01/23
# AtCoder Beginner Contest 144 - C

# Input
n = int(input())

nsq = int(n ** (1/2)) + 1

x = nsq
y = nsq

while x >= 1:
    if n % x == 0:
        ans = (x - 1) + int( (n / x) - 1)
        break
    else:
        x = x - 1

# Output
print(ans)


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

const int MAX = 1000000007;
 
 


 
signed main(){
    int n,m,p;
    cin>>n>>m>>p;
    int used[n]={};
    int a,b,c;
  pair<int,int> hen[m];
  int cost[m];
    for(int i=0;i<m;i++){
        cin>>a>>b>>cost[i];
        hen[i]=make_pair(a-1,b-1);
    }
    int ans[n];
    for(int i=0;i<n;i++)ans[i]=-1*MAX*MAX;
    ans[0]=0;
    for(int j=0;j<n;j++){
        
        for(int i=0;i<m;i++){
            if(ans[hen[i].first]!= -1*MAX*MAX && ans[hen[i].second]<ans[hen[i].first] + cost[i]-p){
                ans[hen[i].second]=ans[hen[i].first] + cost[i]-p;
                
            }
        }
    
    }
    int ans1=ans[n-1];
    for(int j=0;j<n;j++){
        
        for(int i=0;i<m;i++){
            if(ans[hen[i].first]!= -1*MAX*MAX && ans[hen[i].second]<ans[hen[i].first] + cost[i]-p){
                ans[hen[i].second]=ans[hen[i].first] + cost[i]-p;
                
            }
        }
    
    }
    int o=0;
    if(ans1!=ans[n-1])cout<<-1;
    else cout<<max(o,ans1);

   
    
    return 0;
}

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

int main() {
    ll N; cin >> N;
    vector<ll> H(N, 0);
    for(ll i=0; i<N; i++) cin >> H.at(i);

    ll cnt = 0;
    ll tmp = 0;
    for(ll i=0; i<N-1; i++){
        if(H.at(i)>=H.at(i+1)) {
            cnt++;
            tmp = max(cnt, tmp);
        }
        else{
            tmp = max(cnt, tmp);
            cnt = 0;
        }
        //cout << tmp << " " << cnt << endl;
    }

    cout << tmp << endl;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"math"
	"os"
	"strconv"
)

func main() {
	n := readInt()
	m := make([][]byte, n)
	for i := range m {
		m[i] = make([]byte, n)
	}

	for i := 0; i < n; i++ {
		a := readInt()
		for j := 0; j < a; j++ {
			x, y := readInt()-1, readInt()
			if y == 1 {
				m[i][x] = '1'
			} else {
				m[i][x] = '0'
			}
		}
	}

	all := int(math.Pow(2, float64(n)))
	format := "%0" + strconv.Itoa(n) + "b"
	ans := 0
	for i := 0; i < all; i++ {
		b := []byte(fmt.Sprintf(format, i))
		contradiction := false

		for k := range m {
			if b[k] == '0' {
				continue
			}
			for l := range m[k] {
				if m[k][l] == 0 {
					continue
				}
				if m[k][l] != b[l] {
					// log.Println(k, l, m[k][l], b[l])
					contradiction = true
					break
				}

			}
			if contradiction {
				break
			}
		}

		if !contradiction {
			t := 0
			for ii := range b {
				if b[ii] == '1' {
					t++
				}
			}
			ans = max(ans, t)
		}
	}

	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main(){
  int n;cin >> n;
  char c1[n];
  cin >> c1;
  int count = 1;
  for(int i = 1; i < n; i++){
    if(c1[i] != c1[i-1])count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 384
/*########  IN THE NAME OF ALLAH   ##########*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 999999999999999999
#define nl printf("\n")
#define  r0 return 0
#define  r1 return 1
#define sf1(x)  scanf("%lld",&x)
#define sf2(x,y)  scanf("%lld %lld",&x,&y)
#define sf3(x,y,z)  scanf("%lld %lld %lld",&x,&y,&z)
#define pf1(x)  printf("%lld\n",x)
#define pf2(x,y)  printf("%lld %lld\n",x,y)
#define pf3(x,y,z)  printf("%lld %lld %lld\n",x,y,z)
#define yes  printf("YES\n")
#define no  printf("NO\n")
#define pc(x)  printf("Case %lld :",x)
#define pb push_back
#define mp make_pair
#define pa pair<ll,ll>
#define mem(a,b) memset(a,b,sizeof(a))
#define MIN  -99999999999999999
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define pi 2.0*acos(0.0)
#define sp printf(" ")
#define vs(v) (v.begin(),v.end())
ll max(ll a,ll b) {if(a>b) return a; else return b;} ll min(ll a,ll b) {if(a<b) return a; else return b;}
ll power(ll B,ll P){ if(P==0) return 1; ll X=power(B,P/2); if(P%2==0) return X*X; else return B*X*X;}
ll fx[]={1,-1,0,0}; ll fy[]={0,0,1,-1};

ll A[3000005],B[3000005],C[3000005],visited[3000005],level[3000005];
char CH[1000][1000];
vector<ll>V,G;

int main()
{
   ll T,N,E,u,Q,v,i,j,k,sum=0,ck=0,x,y,cs=0;

   string S="ACL",S1;
   cin>>N;
   for(i=1;i<=N;i++)
   {
       cout<<S;
   }
   nl;

   double d1,d2,d3;



 /************ALEYA YOUSUF ************/


 /************ALLAH IS ALMIGHTY ************/
return 0;

}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n);
    ffor(i,n) cin >> a[i];
    int ans = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            ans += (a[i]*a[j]);
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N;
    cin >> N;
    if (N == 0) {
        cout << 0 << endl;
        return 0;
    }

    ll base = 1;
    string S;
    while (N != 0) {
      if (N % (base * 2) == 0) S.push_back('0');
      else { 
          S.push_back('1');
          N -= base;
      }
      base *= -2;
    }
    reverse(S.begin(), S.end());
    cout << S << endl;
}


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

struct shop{
    long long A;
    long long B;
};

bool cmp(const shop &s1, const shop &s2){
    return s1.A < s2.A;
}

int main(){
    long long N, M;
    cin >> N >> M;
    long long A, B;
    shop shop_list[114514];
    for(int i=0; i<N; i++){
        cin >> A >> B;
        shop_list[i].A = A;
        shop_list[i].B = B;
    }
    sort(shop_list, shop_list+N, cmp);
    long long cost = 0;
    for(int i=0; i<N; i++){
        if(M - shop_list[i].B >= 0){
            M -= shop_list[i].B;
            cost += shop_list[i].A*shop_list[i].B;
        }else{
            cost += shop_list[i].A*M;
            break;
        }
    }
    cout << cost;
    return EXIT_SUCCESS;
}

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

int main(){
  
  string S;
  cin >> S;
  int count_A=0;
  int count_B=0;
  
  for(int i=0;i<3;i++){
    if(S.at(i)=='A'){
      count_A++;
    }
  }

  for(int i=0;i<3;i++){
    if(S.at(i)=='B'){
      count_B++;
    }
  }
  
  if(count_A==0 || count_B==0){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}
  
  

Measured memory_bytes: 256
//2018-03-11
//LZYeah
//
#include<bits/stdc++.h>
#define ll long long
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define Forr(i,a,b) for(register int i=a;i>=b;i--)
using namespace std;
inline void File()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
inline void read(int &x)
{
	int p=1;
	x=0;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+(c^'0');c=getchar();}
	x*=p;
}

int n,m;
ll ans=0;
int main()
{
//	File();
	read(n),read(m);
	if(n>m)swap(n,m);
	if(n==1&&m==1){puts("1");return 0;}
	if(n==1&&m!=1){printf("%d\n",m-2);return 0;}
	ans=1ll*(n-2)*(m-2);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256