akhauriyash/Code-Regression huggingface dataset:
N=int(input())



for n in range(N):

    gx,gy =map(int,input().split())

    T=[[0 for i in range(gy+1)] for j in range(gx+1)]

    left=[[0 for i in range(gy+1)] for j in range(gx+1)]

    upper=[[0 for i in range(gy+1)] for j in range(gx+1)]

    p=int(input())

   

    for i in range(p):

        x1,y1,x2,y2=map(int,input().split())

        if x1==x2:

            upper[x1][max(y1,y2)]=1

        if y1==y2:

            left[max(x1,x2)][y1]=1



    for i in range(gx+1):



        for j in range(gy+1):

            if i==0 and j==0:

                T[i][j]=1

                continue



            if i==0 and j>=1 and upper[i][j]==0 and left[i][j]==0:

                T[i][j]=T[i][j-1]

                continue



            if i>=1 and j==0 and upper[i][j]==0 and left[i][j]==0:

                T[i][j]=T[i-1][j]

                continue

                

            if left[i][j]==1 and upper[i][j]==1:

                    T[i][j]=0

            elif left[i][j]==0 and upper[i][j]==1:

                    T[i][j]=T[i-1][j]

            elif left[i][j]==1 and upper[i][j]==0:

                    T[i][j]=T[i][j-1]

            else:

                T[i][j]=T[i-1][j]+T[i][j-1]



    if T[gx][gy]==0:

        print("Miserable Hokusai!")

    else:

        print(T[gx][gy])




Measured memory_bytes: 5624
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    map<int, int> Even;
    map<int, int> Odd;
    
    int N; cin >> N;
    for(int i=0; i<N; i++){
        int v; cin >> v;
        if(i%2 == 0) Even[v]++;
        else Odd[v]++;
    }
    
    int max_even = 0;
    int mx_e_key = 0;
    int max2_even = 0;

    
    int max_odd = 0;
    int mx_o_key = 0;
    int max2_odd = 0;
    
    for(auto m:Even){
        if(m.second > max_even){
            max_even = m.second;
            mx_e_key = m.first;
        }
    }
    for(auto m:Odd){
        if(m.second > max_odd){
            max_odd = m.second;
            mx_o_key = m.first;
        }
    }

    for(auto m:Even){
        if(m.first == mx_e_key) continue;
        if(m.second > max2_even) max2_even = m.second;
    }
    for(auto m:Odd){
        if(m.first == mx_o_key) continue;
        if(m.second > max2_odd) max2_odd = m.second;
    }
    
    
    
    if(mx_o_key != mx_e_key){
        cout << (N/2 - max_odd) + (N/2 - max_even) << endl;
        return 0;
    }
    
    bool f = false;
    if(max_even + max2_odd > max_odd + max2_even) f = true;
    if(f){
        cout << (N/2 - max_even) + (N/2 - max2_odd) << endl;
    } else {
        cout << (N/2 - max_odd) + (N/2 - max2_even) << endl;
    }

    
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define int long
main(){
  int n,m,a,r=0;
  cin>>n>>m;
  priority_queue<int> que;
  for(int i=0;i<n;++i){
    cin>>a;
    que.push(a);
  }
  for(int i=0;i<m;++i){que.push(que.top()/2); que.pop();}
  while(!que.empty()){r+=que.top();que.pop();}
  cout<<r;
}

Measured memory_bytes: 1400
a, b, c, x, y = map(int, input().split())

if a + b <= 2 * c:
    price = a * x + b * y
else:
    if x >= y:
        price = min(2 * c * y + a * (x - y), 2 * c * x)
    else:
        price = min(2 * c * x + b * (y - x), 2 * c * y)

print(price)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define f first
#define sec second
#define pb push_back
#define pf push_front
#define pbb pop_back
#define vi vector<ll>
#define vii vector< pair<ll,ll> >
#define pi pair<ll,ll>
#define map map<ll,ll>
#define set set<ll>
ll dp[100007];
bool visit[100007];
vector<long>adj[100007];
int dfs(int s){
    visit[s]=true;
    for(int k:adj[s]){
        if(visit[k]==false)
            dfs(k);
            dp[s]=max(1+dp[k],dp[s]);
        
    }
    return dp[s];
}
int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    memset(dp,0,sizeof(dp));
    memset(visit,0,sizeof(visit));
    cin>>n>>m;
    long v[m];
    for(int i=0;i<m;i++){
        ll b;
        cin>>v[i]>>b;
        //v[i]=a;
        adj[v[i]].pb(b);
    }
    for(int i=0;i<m;i++){
        if(!visit[v[i]]){
            dfs(v[i]);
        }
    }
    ll  ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}
        
        
        
      
    

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

int main() {
  int n;
  scanf("%d", &n);

  vector<int> a(n);
  map<int, int> m;
  long long s = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s += a[i];
    if (m.count(a[i]))
      m[a[i]]++;
    else
      m.insert({a[i], 1});
  }

  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int b, c;
    scanf("%d %d", &b, &c);

    if (m.count(b)) {
      s += 1LL * (c - b) * m[b];
      if (m.count(c))
        m[c] += m[b];
      else
        m.insert({c, m[b]});

      m.erase(b);
    }

    printf("%lld\n", s);
  }

  return 0;
}

Measured memory_bytes: 6748
A,B,C,K = map(int, input().split())

k = K

K = K - A
if K < 0:
  K = k
  print(1 * K)
elif K == 0:
  print(1 * A)
elif K > 0:
  K = K - B
  if K <= 0:
    print(1 * A)
  elif K > 0:
    K = K - C
    if K < 0:
      K = k - (A + B)
      print((1 * A) - (1 * K))
    else:
      print((1 * A) - (1 * C))

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

int min(int a,int b){
    return a<b?a:b;
}

int main(){
    int H,W;
    cin >> H >> W;

    int a,b,c; //a:|||,≡; b:|=; c:Π;
    if(H%3==0 || W%3==0) a=0;
    else a=min(H,W);

    int wl=W/3;
    b=min((H-H/2)*(W-wl)-wl*H,(wl+1)*H-H/2*(W-wl-1));

    int hl=H/3;
    c=min((W-W/2)*(H-hl)-hl*W,(hl+1)*W-W/2*(H-hl-1));

    cout << min(a,min(b,c)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

#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 N, M;
  cin >> N >> M;

  vector<int> a(N);
  vector<int> b(N);

  vector<int> c(M);
  vector<int> d(M);

  rep(i, N) {
    cin >> a[i] >> b[i];
  }

  rep(i, M) {
    cin >> c[i] >> d[i];
  }

  rep(i, N) {
    int check = 0;
    int mn = -1;

    rep(j, M) {
      int dist = std::abs(a[i] - c[j]) + std::abs(b[i] - d[j]);
      if (mn == -1 || mn > dist) {mn = dist; check = j + 1;}
    }

    cout << check << endl;
  }

  return 0;
}


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

using namespace std;

int main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    int cnt[N];
    for(int i=1;i<=N-1;i++){
        cnt[i] = N-i;
    }

    for(int i=1;i<=X;i++){
        for(int j=X+1;j<=N;j++){
            if(abs(j-X) > abs(j-Y)+1){
                cnt[j-i] -= 1;
                cnt[abs(j-Y)+1+X-i] += 1;
            }
        }
    }

    for(int i=X+1;i<Y;i++){
        for(int j=X+1;j<=N;j++){
            if(abs(j-i) > abs(X-i)+abs(Y-j)+1){
                cnt[abs(j-i)] -= 1;
                cnt[abs(X-i)+abs(Y-j)+1] += 1;
            }
        }
    }

    // for(int i=1;i<=X;i++){
    //     for(int j=0;j<=N-Y;j++){
    //         cnt[Y+j-i]--;
    //         cnt[j+(X-i)+1]++;
    //     }
    // }

    // for(int i=1;i<=X;i++){
    //     for(int k=1;k<=Y-X-1;k++){
    //         int d = min(k-X, Y-k+1);
    //         cnt[k-i]--;
    //         cnt[d+X-i]++;
    //     }    
    // }
    

    for(int i=1;i<=N-1;i++){
        cout << cnt[i] << endl;
    }

    return 0;
}


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

Measured memory_bytes: 1024
from itertools import product

n,m = map(int, input().split())
xyzl = []
for _ in range(n):
    x,y,z = map(int, input().split())
    xyzl.append((x,y,z))

if m==0: 
    print(0)
    exit()

ans = 0
for xs in [1, -1]:
    for ys in [1, -1]:
        for zs in [1, -1]:
            curr_sums = []
            for xyz in xyzl:
                x,y,z = xyz
                x*=xs
                y*=ys
                z*=zs
                curr_sums.append(x+y+z)
            curr_sums.sort()
            ans = max(ans, sum(curr_sums[-m:]))

print(ans)

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(long long i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double pi = acos(-1.0);
const ll mod = pow(10,9) + 7;
const ll INF = pow(2,31) - 1;

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    string s;
    cin >> s;
    int q;cin >> q;
    int st = 0;

    rep(i,q){
        int t;cin >> t;
        if(t == 1)st++;
        else if(t == 2){
            int f;
            string c;
            cin >> f >> c;
            if(st%2 == f-1)s.insert(0,c);
            else s.insert(s.end(), c[0]);
        }
    }


    int n = s.size();
    if(st%2 == 0)cout << s << endl;
    
    else {
        rep(i,n)cout << s[n-i-1];
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 900
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();

        String replaced = S
                .replaceAll("eraser", "")
                .replaceAll("erase", "")
                .replaceAll("dreamer", "")
                .replaceAll("dream", "");
        System.out.println(replaced.length()==0 ? "YES" : "NO");
    }
}


Measured memory_bytes: 28244
from math import gcd

A, B, C, D, E, F = map(int, input().split())

N = 0; max_SW = A*100; max_S = 0
f = F//100; a = f//A; b = f//B
cn = D // gcd(C, D)

for j in range(b+1): #Bをj杯入れる
    for i in range(a+1): #Aをi杯入れる
        if i==0 and j==0:
            continue
        elif A*i + B*j > f:
            continue
        w = (A*i + B*j) * 100 #水の量
        e = (A*i + B*j) * E #この場合において溶ける砂糖の最大値
        S = min(e, F-w) #ビーカーも考慮した砂糖を入れられる限界
        s = 0
        for ci in range(min(S//C, cn)+1):
            s = max(s, S - (S - C*ci) % D)
        if s/(w+s) > N:
            N = s/(w+s)
            max_SW = s + w
            max_S = s

print(max_SW, max_S)


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

int main(){
	ll n; cin >> n;
	vl a(n); rep(i,n)cin >> a[i];
	sort(a.begin(), a.end());
	bool r = true;
	rep(i,n-1){
		if(a[i] == a[i+1])r = false;
	}
	if(r)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<string> vs;
Def inf = sizeof(Def) == sizeof(ll) ?2e18:1e9+10;
int main(){
  int n,a,b,c,x;
  while(cin>>n>>a>>b>>c>>x,n){
    int co=0;
    vi in(n);
    rep(i,n)cin>>in[i];
    int t=0;
    while(t!=n){
      if(x==in[t])t++;
      if(t==n)break;
      co++;
      x=(a*x+b)%c;
      if(co>10000)break;
    }
    if(co<=10000)cout<<co<<endl;
    else cout<<-1<<endl;
  }
}



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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  ll N;
  scanf("%lld",&N);
  ll X;
  scanf("%lld",&X);
  vector<ll> m(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&m[i]);
    X-=m[i];
  }
  ll ans=N;
  ll mx=0;
  for (int i=0; i<N; i++) {
    mx = max(mx, X/m[i]);
  }
  cout << ans+mx << endl;
}

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


Measured memory_bytes: 256
sa = list(input())
sb = list(input())
sc = list(input())
n = "a"
while True:
    if n == "a":
        if len(sa) == 0:
            print ("A")
            exit ()
        n = sa.pop(0)
    elif n == "b":
        if len(sb) == 0:
            print ("B")
            exit ()
        n = sb.pop(0)
    else:
        if len(sc) == 0:
            print ("C")
            exit ()
        n = sc.pop(0) 

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, X, Y; 
cin >> N >> M >> X >> Y; 
int P = X; 
int Q = Y; 
int x[110] = {}, y[110] = {}; 
for (int i = 0; i < N; ++i){
cin >> x[i];
P = max(P, x[i]); 
}
for (int j = 0; j < M; ++j){
cin >> y[j];
Q = min(Q, y[j]); 
}
if(Q > P){
cout << "No War" << endl; 
}
else{
cout << "War" << endl; 
}
}

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

int main(){
  int N, M;
  cin >> N;
  map<string, int> dict;
  for(int i=0; i<N; i++){
    string val;
    cin >> val;
    if(dict.count(val)){
      dict.at(val)++;
    }else{
      dict.emplace(val, 1);
    }
  }
  cin >> M;
  for(int i=0; i<M; i++){
    string val2;
    cin >> val2;
    if(dict.count(val2)){
      dict.at(val2)--;
    }
    else{
      dict.emplace(val2, 1);
    }
  }
  int max = 0;
  for(auto a: dict){
    max = a.second > max? a.second: max;
  }
  cout << max << endl;
}

Measured memory_bytes: 256
#include <cstdio>

char str[5];

int main() {
	scanf("%s", str + 1);
	if ((str[1] == str[2]) && (str[3] == str[4]) && (str[1] != str[3]))
		printf("Yes");
	else if ((str[1] == str[3]) && (str[2] == str[4]) && (str[1] != str[2]))
		printf("Yes");
	else if ((str[1] == str[4]) && (str[2] == str[3] && (str[1] != str[2])))
		printf("Yes");
	else
		printf("No");
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16

ll mod_pow(ll a,ll n,ll mod){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

vector<ll> newton_interpol(ll D, const vector<ll>& X, const vector<ll>& Y, ll mod){
  vector<ll> res(D, 0), C(D);
  vector<vector<ll>> dp(D + 1, vector<ll>(D + 1, 0));

  // construct C array
  for(ll i = 0; i < D; i++) {
    ll sum = 0, crt = 1;
    for(ll j = 0; j < i; j++) {
      sum += crt * C[j] % mod;
      sum %= mod;
      crt *= (X[i] - X[j] + mod);
      crt %= mod;
    }
    C[i] = (Y[i] - sum + mod) % mod;
    C[i] *= mod_pow(crt, mod - 2, mod);
    C[i] %= mod;
  }

  // calc polynomial (dp)
  dp[0][0] = 1;
  for(ll i = 0; i < D; i++) {
    for(ll j = 0; j <= i; j++) {
      res[j] += C[i] * dp[i][j] % mod;
      res[j] %= mod;
    }
    if(i == D - 1) break;
    for(ll j = 0; j <= i; j++) {
      (dp[i + 1][j] += dp[i][j] * (D - X[i] + mod)) %= mod;
      (dp[i + 1][j + 1] += dp[i][j]) %= mod;
    }
  }

  return res;
}

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

  ll p;
  vector<ll> X,Y;

  cin>>p;
  X.resize(p); Y.resize(p);

  rep(i,p){
    X[i]=i;
    cin>>Y[i];
  }

  vector<ll> b=newton_interpol(p,X,Y,p);

  rep(i,p)cout<<b[i]<<" ";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 72856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)
        scanf("%d",&a[i]);
    sort(a.begin(),a.end());

    int m;
    cin >> m;
    vector<int> b(m);
    for(int i = 0; i < m; ++i)
        scanf("%d",&b[i]);
    sort(b.begin(),b.end());
    int l = 0;
    for(int x : a)
        if(l < m && b[l] == x)
            ++l;
    if(l == m)
        puts("YES");
    else
        puts("NO");
}


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

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    if((b-a+1)%2==0){
        if(k>=(b-a+1)/2){
            for(int i=a;i<=b;i++){
                cout << i << "\n";
            }
        }else{
            for(int i=a;i<a+k;i++){
                cout << i << "\n";
            }
            for(int i=b-k+1;i<=b;i++){
                cout << i << "\n";
            }
        }
    }else{
        if(k>=((b-a+1)/2)+1){
            for(int i=a;i<=b;i++){
                cout << i << "\n";
            }
        }else{
            for(int i=a;i<a+k;i++){
                cout << i << "\n";
            }
            for(int i=b-k+1;i<=b;i++){
                cout << i << "\n";
            }
        }
    }
}

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

bitset<777> G[777],v,go;
vector<int> iG[777];
int c[777],d[777],w[777],z[777];

int F(int x){ return x==d[x]?x:d[x]=F(d[x]); }
void U(int x,int y){ d[F(x)]=F(y); }

void JIZZ(){ cout<<"-1"<<endl; exit(0); }

void dfs(int now,int col){
    c[now]=col;
    v[now]=1;
    for(int i:iG[now]){
        U(now,i);
        if(v[i] && c[i]==col)JIZZ();
        else if(v[i]);
        else dfs(i,!col);
    }
}

int main(){
    int n,m; cin>>n>>m;
    for(int i=0;i<m;++i){
        int u,v; cin>>u>>v;
        G[u][v]=G[v][u]=1;
    }
    int e=0;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            if(!G[i][j] && (i^j))iG[i].push_back(j),++e;
        }
    }
    e>>=1;
    for(int i=1;i<=n;++i)d[i]=i;
    for(int i=1;i<=n;++i)if(!v[i])dfs(i,1);
    for(int i=1;i<=n;++i)w[F(i)]+=c[i],++z[F(i)];
    go[0]=1;
    for(int i=1;i<=n;++i)go=(go<<w[i])|(go<<z[i]-w[i]);
    // cout<<go<<endl;
    int one=0;
    for(int i=1;i<=n;++i)if(go[i] && max(one,n-one)>max(i,n-i))one=i;
    // cout<<"one: "<<one<<endl;
    cout<<one*(one-1)/2+(n-one)*(n-one-1)/2<<endl;
}


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



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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n==0) {
            break;
        }
        int PlayerA=0;
        int PlayerB=0;
        while (n--) {
            int scoreA;
            int scoreB;
            cin >> scoreA >> scoreB;
            if (scoreA>scoreB) {
                PlayerA+=scoreA+scoreB;
            } else if (scoreA<scoreB) {
                PlayerB+=scoreA+scoreB;
            } else {
                PlayerA+=scoreA;
                PlayerB+=scoreB;
            }
        }
        printf("%d %d\n",PlayerA,PlayerB);
    }
    return 0;
    
}

Measured memory_bytes: 3164
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
vector<ll>path[101010];
ll cnt[101010];
ll dp[101010];
int main(){
    ll N, M;
    cin >> N >> M;
    for(ll i = 0; i < M; i++){
        ll x, y;
        cin >> x >> y;
        path[x].push_back(y);
        cnt[y]++;
    }
    ll ans = 0;
    queue<ll>Q;
    for(ll i = 1; i <= N; i++){
        if(cnt[i]==0)Q.push(i);
        dp[i] = 0;
    }
    while(!Q.empty()){
        ll idx = Q.front();
        Q.pop();
        ans = max(ans, dp[idx]);
        for(ll i = 0; i < path[idx].size(); i++){
            ll nxt = path[idx][i];
            cnt[nxt]--;
            dp[nxt] = max(dp[nxt], dp[idx] + 1);
            if(cnt[nxt] == 0)Q.push(nxt);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

int main(){
    int N;
    cin >> N;
    int A[N+1], x[N+1][N+1], y[N+1][N+1];
    rep2(i, 1, N){
        cin >> A[i];
        rep(j, A[i]) cin >> x[i][j] >> y[i][j];
    }
    int e[N+1];
    e[0] = 1;
    rep(i, N){
        e[i+1] = 2*e[i];
    }
    int ans = 0;
    rep(i, e[N]){
        int s[N];
        int sum = 0;
        int t = i;
        bool able = true;
        rep2(j, 1, N){
            s[j] = t%2;
            t /= 2;
            sum += s[j];
        }
        rep2(i, 1, N){
            rep(j, A[i]){
                if(s[i] == 1){
                    if(y[i][j] == 0 && s[x[i][j]] == 1) able = false;
                    elif(y[i][j] == 1 && s[x[i][j]] == 0) able = false;
                }
            }
        }
        if(able) ans = max(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//Double Linked List 

#include<cstdio>
#include<list>
#include<algorithm>
using namespace std;


int main(void){
    int q, x;
    char com[20];
    //?¨?????????????????????????list????????????
    list<int> v;
    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        scanf("%s", com);
        if(com[0] == 'i'){  //insert
            scanf("%d", &x);
            v.push_front(x);
        } else if(com[6] == 'F'){ //deleteFirst
            v.pop_front();
        } else if(com[6] == 'L'){ //deleteLast
            v.pop_back();
        } else if(com[0] == 'd'){   //delete x
            scanf("%d", &x);
            for( list<int>::iterator it = v.begin(); it != v.end(); it++){
                if(*it == x){
                    v.erase(it);
                    break;
                }
            }
        }
    }
    int i = 0;
    for(list<int>::iterator it = v.begin(); it != v.end(); it++){
        if(i++) printf(" ");
        printf("%d", *it);
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 32220
#include<stdio.h>
#define MAX 2000000

 int n,A[MAX+1];

void maxHeapify(int i){

  int l,r,largest,a;
  l = 2 * i;
  r = 2 * i +1;

  if(l<=n && A[l] > A[i]) largest = l;
  else largest = i;

  if(r<=n && A[r] > A[largest]) largest = r;

  if(largest != i){
    a=A[i];
    A[i]=A[largest];
    A[largest]=a;
      maxHeapify(largest);
  }
}

int main(){

  int i;
  
  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d",&A[i]);

  for(i=n/2;i>=1;i--) maxHeapify(i);

  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }

  printf("\n");

  return 0;
}
/*
#include<stdio.h>
#define MAX 2000000
 
 int n,A[MAX+1];
 
void maxHeapify(int i){
 
  int l,r,largest,a;
  l = 2 * i;
  r = 2 * i +1;
 
  if(l<=n && A[l] > A[i]) largest = l;
  else largest = i;
 
  if(r<=n && A[r] > A[largest]) largest = r;
 
  if(largest != i){
    a=A[i];
    A[i]=A[largest];
    A[largest]=a;
      maxHeapify(largest);
  }
}
 
int main(){
 
  int i;
   
  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d",&A[i]);
 
  for(i=n/2;i>=1;i--) maxHeapify(i);
 
  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
 
  printf("\n");
 
  return 0;
}
*/



Measured memory_bytes: 3684
W,H,N=map(int,input().split())
S=[0]*N; p=0
for i in range(N):
  x,y,a=map(int,input().split())
  S[i]=[x,y,a]
#print("x,y,a",S)
e=101;w=-1;n=101;s=-1
for i in range(N):
  if S[i][2]==1:
    w=max(w,S[i][0])
  elif S[i][2]==2:
    e=min(e,S[i][0])
  elif S[i][2]==3:
    s=max(s,S[i][1])
  elif S[i][2]==4:
    n=min(n,S[i][1])

#print("w,e,s,n",w,e,s,n)
for i in range(1,H+1):
  for j in range(1,W+1):
    if (j<=w and w>0) or (j>e and e<101) or (i>n and n<101) or (i<=s and s>0):
      p=p+1

print(W*H-p)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

template<class T>
T gcd(T a, T b)
{
    while (a > 0)
    {
        T t = a;
        a = b%a;
        b = t;
    }
    return b;
}

template<typename T>
class SegmentTree
{
    int n;
    function<T(T,T)> op;
    vector<T> V;

    T q(int l, int r)
    {
        if (l >= r)
            return V[0];
        T a = q((l+1)/2, r/2);
        if (l%2 != 0)
            a = op(a, V[l]);
        if (r%2 != 0)
            a = op(a, V[r-1]);
        return a;
    }

public:
    SegmentTree(int n_, function<T(T,T)> op, vector<T> a):
        op(op)
    {
        n = 1;
        while (n < n_)
            n *= 2;
        V = vector<T>(2*n);
        for (int i=0; i<n_; i++)
            V[i+n] = a[i];
        for (int i=n-1; i>0; i--)
            V[i] = op(V[i*2], V[i*2+1]);
    }

    T get(int p) const
    {
        return V[p+n];
    }

    void set(int p, T v)
    {
        p += n;
        V[p] = v;
        for (p/=2; p>0; p/=2)
            V[p] = op(V[p*2], V[p*2+1]);
    }

    //  init OP v[l] OP v[l+1] OP ... OP v[r-1]
    T query(int l, int r)
    {
        return q(l+n, r+n);
    }
};

int main()
{
    int N;
    cin>>N;
    vector<int> A(N);
    for (int &a: A)
        cin>>a;

    SegmentTree<int> T(N, [](int a, int b){return gcd(a,b);}, A);
    int ans = 0;
    for (int i=0; i<N; i++)
        ans = max(ans, gcd(T.query(0,i), T.query(i+1,N)));
    cout<<ans<<endl;
}


Measured memory_bytes: 2048
s = input()
i = len(s) - 1
flag = False
while i > 0:
    flag = False
    if s[i] == "m" and s[i - 4:i + 1] == "dream":
        flag = True
        i -= 5
    elif s[i] == "e" and s[i - 4: i + 1] == "erase":
        i -= 5
        flag = True
    elif s[i] == "r":
        if s[i - 5: i + 1] == "eraser":
            flag = True
            i -= 6
        elif s[i - 6: i + 1] == "dreamer":
            flag = True
            i -= 7
    if flag == False:
        break
print("YES" if flag else "NO")

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

int main() {
    int N, M;
    while (cin >> N >> M, N || M)
        if (N % 2 == 0 || M % 2 == 0) cout << "yes" << endl;
        else cout << "no" << endl;

    return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int H,W;
    cin>>H>>W;
    char arr[H][W];
    for(int i=0;i<H;i++)
    {
        for(int j=0;j<W;j++)
        {
            cin>>arr[i][j];
        }
    }
    long long int dp[H][W];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<W;i++)
    {
        if(arr[0][i]=='.')
        {
            dp[0][i]=1;
        }
        else
        {
            break;
        }
    }
     for(int i=0;i<H;i++)
    {
        if(arr[i][0]=='.')
        {
            dp[i][0]=1;
        }
        else
        {
            break;
        }
    }
    for(int i=1;i<H;i++)
    {
        for(int j=1;j<W;j++)
        {
            if(arr[i][j]=='.')
            {
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%(long long int)(1e9+7);
                dp[i][j]%=(long long int)(1e9+7);
            }
            else
            {
                dp[i][j]=0;
            }
        }
    }
    cout<<dp[H-1][W-1];
    return 0;
}

Measured memory_bytes: 12320
#include<stdio.h>
 
void spin_w(int x[]){
  int sai1[6],i;
 
  for(i=0;i<6;i++){
    sai1[i]=x[i];
  }
 
  sai1[0]=x[2];
  sai1[2]=x[5];
  sai1[3]=x[0];
  sai1[5]=x[3];
 
  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }
 
}
 
void spin_side(int x[]){
int sai1[6],i;
 
for(i=0;i<6;i++){
  sai1[i]=x[i];
 }
 
sai1[1]=x[2];
sai1[2]=x[4];
sai1[3]=x[1];
sai1[4]=x[3];
 
for(i=0;i<6;i++){
  x[i]=sai1[i];
 }
}
 
 
void spin_s(int x[]){
    int sai1[6],i;
     
  for(i=0;i<6;i++){
    sai1[i]=x[i];
  }
  sai1[0]=x[4];
  sai1[1]=x[0];
  sai1[4]=x[5];
    sai1[5]=x[1];
     
  for(i=0;i<6;i++){
    x[i]=sai1[i];
  }
}
 
int main(){
  int i,j,sai1[6],sai2[6],count=0,count2=0;
 
  for(i=0;i<6;i++){
    scanf("%d",&sai1[i]);
  }
  for(i=0;i<6;i++){
    scanf("%d",&sai2[i]);
  }
 
  for(i=0;i<6;i++){
    if(sai1[i]==sai2[i]){
      count++;
    }
  }
  if(count!=6){
        for(i=0;i<=3;i++){
            spin_w(sai1);
            count2++;
        if(sai1[0]==sai2[0])break;
        }
        if(count2==4){
            for(i=0;i<=3;i++){
            spin_s(sai1);
        if(sai1[0]==sai2[0])break;
            }
        }
             
    for(i=0;i<=3;i++){
      spin_side(sai1);
      if(sai1[1]==sai2[1])break;
        }
  }
 
  count=0;
 
 
  for(i=0;i<6;i++){
    if(sai1[i]==sai2[i]){
      count++;
        }
  }
     
  if(count==6){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

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

int main(){
	int h,m,s,c;
	while(1){
		cin >> h >> m >> s;
		if((h==-1)&&(m==-1)&&(s==-1)){
			return 0;
		}
		s = 2*60*60 - h*60*60 - m*60 - s;
		c = 3*s;
		h=0;
		m=0;
		for(int i=0;s>=3600;i++){
			s-=3600;
			h++;
		}
		cout << "0" << h << ":";
		for(int i=0;s>=60;i++){
			s-=60;
			m++;
		}
		if(m>9){
			cout << m << ":";
		}
		else{
			cout << "0" << m << ":";
		}
		if(s>9){
			cout << s << "\n";
		}
		else{
			cout << "0" << s << "\n";
		}
		s=c;
		h=0;
		m=0;
		for(int i=0;s>=3600;i++){
			s-=3600;
			h++;
		}
		cout << "0" << h << ":";
		for(int i=0;s>=60;i++){
			s-=60;
			m++;
		}
		if(m>9){
			cout << m << ":";
		}
		else{
			cout << "0" << m << ":";
		}
		if(s>9){
			cout << s << "\n";
		}
		else{
			cout << "0" << s << "\n";
		}
	}
return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void){
        
        double l,n,x,t,o;
        
        
    //    scanf
        scanf("%lf%lf%lf",&n,&x,&t);

    //    処理1 nがxより少ない時はt分かかる
        if(n < x){
            printf("%d\n",(int)t);
            
    //    処理2　nがxよりも大きい時は何回作れば納品できるかを求める。
        }else{
            l = n / x - 0.001;
            o = (int)(l + 1);
            
            printf("%d\n",(int)(o * t));
            }
            
    return 0;
}


Measured memory_bytes: 1744
import math
def count_divisor(n):
    divisor = []
    for i in range(1, int(math.sqrt(n)) + 2):
        if n % i == 0:
            j = n // i
            if i != j:
                divisor.append(j)
            divisor.append(i)
    return len(divisor)

n = int(input())
ans = 0
for i in range(1, n+1, 2):
    if count_divisor(i) == 8:
        ans += 1
print(ans)


Measured memory_bytes: 38384
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF=100000000;
int dp[20][20];
int main(){
  for(int i=0;i<20;i++){
    for(int j=0;j<20;j++){
      if(i!=j) dp[i][j]=INF;
    }
  }
  int n,m,s,g,V,P;
  scanf("%d",&n);
  scanf("%d",&m);
  int a,b,c,d;
  while(m--){
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    a--;b--;
    dp[a][b]=c;
    dp[b][a]=d;
  }
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
      }
    }
  }
  scanf("%d,%d,%d,%d",&s,&g,&V,&P);
  s--;g--;
  int ans=V-P-dp[s][g]-dp[g][s];
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 2712
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{
  ll n,a[100010];
  cin>>n;
  rep(i,n)cin>>a[i];
  ll num=0;
  ll tmp=0;
  ll ans=1;
  if(a[0]==2){
    cout<<1<<endl;
    return 0;
  }
  while(1){
    ans++;
    num=a[num]-1;
    tmp=a[num];
    if(tmp==2){
      cout<<ans<<endl;
      return 0;
    }
    if(ans>=n){
      cout<<-1<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 4396
n, m = map(int, input().split())
h = list(map(int, input().split()))

max_height_around = [0] * n
for _ in range(m):
    a, b = map(int, input().split())
    max_height_around[a - 1] = max(max_height_around[a - 1], h[b - 1])
    max_height_around[b - 1] = max(max_height_around[b - 1], h[a - 1])

print(sum(h[x] > max_height_around[x] for x in range(n)))

Measured memory_bytes: 20116
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
   ll dp[2000000];
 int gcd(int a, int b)
{
  if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b,a%b));
}
}
int main(){
  ll a;cin>>a;
  ll b=a/200;

  cout<<10-b;
}



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

int main() {
  vector<pair<long long int,long long int>> prices;
  long long int n, m, a, b, result = 0;
  cin >> n >> m;
  for (long long int i=0; i<n; i++) {
    cin >> a >> b;
    prices.push_back(make_pair(a,b));
  }
  sort(prices.begin(), prices.end());
  for (auto i : prices) {
    if (i.second<m) {
      result+=i.first*i.second;
      m-=i.second;
    }
    else {
      result+=i.first*m;
      break;
    }
  }
  
  cout << result;
  return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if(a == b) cout << "Draw" << endl;
    else if(a < b && a != 1) cout << "Bob" << endl;
    else if(a > b && b != 1) cout << "Alice" << endl;
    else if(a < b && a == 1) cout << "Alice" << endl;
    else cout << "Bob" << endl;
}


Measured memory_bytes: 256
import scala.io.StdIn.readInt

object Main extends App {

  val n = readInt
  val p1 = new Point(0d, 0d)
  val p2 = new Point(100d, 0d)
  p1.printPoint
  kochCurve(n, 0, p1, p2)
  p2.printPoint

  class Point(val x: Double, val y: Double) {
    def printPoint(): Unit = {
      println(f"${x} ${y}")
    }
  }

  def kochCurve(n: Int, i: Int, p1: Point, p2: Point): Unit = {
    if (n == i) {
      return
    }
    val s = getPointOnLine(p1, p2, portion = 1.0 / 3.0)
    val t = getPointOnLine(p1, p2, portion = 2.0 / 3.0)
    val u = getEdge(s, t)
    kochCurve(n, i + 1, p1, s)
    s.printPoint
    kochCurve(n, i + 1, s, u)
    u.printPoint
    kochCurve(n, i + 1, u, t)
    t.printPoint
    kochCurve(n, i + 1, t, p2)
  }

  def getEdge(s: Point, t: Point): Point = {
    var edgePoint: Point = null
    val len = getLen(s, t)
    if (s.y == t.y) {
      val base = len * Math.cos(Math.toRadians(60))
      val height = len * Math.sin(Math.toRadians(60))
      if (s.x < t.x) {
        edgePoint = new Point(s.x + base, s.y + height)
      } else {
        edgePoint = new Point(s.x - base, s.y - height)
      }
    } else {
      if (isLeftBottomToRightTop(s, t)) {
        edgePoint = new Point(t.x - len, t.y)
      } else if (isLeftTopToRightBottom(s, t)) {
        edgePoint = new Point(s.x + len, s.y)
      } else if (isRightTopToLeftBottom(s, t)) {
        edgePoint = new Point(t.x + len, t.y)
      } else {
        edgePoint = new Point(s.x - len, s.y)
      }
    }
    edgePoint
  }

  def isLeftTopToRightBottom(p1: Point, p2: Point): Boolean = {
    p1.x < p2.x && p1.y > p2.y
  }

  def isLeftBottomToRightTop(p1: Point, p2: Point): Boolean = {
    p1.x < p2.x && p1.y < p2.y
  }

  def isRightTopToLeftBottom(p1: Point, p2: Point): Boolean = {
    p1.x > p2.x && p1.y > p2.y
  }

  def getLen(p1: Point, p2: Point, portion: Double = 1d): Double = {
    val base = p1.x - p2.x
    val height = p1.y - p2.y
    val len = Math.sqrt(Math.pow(base, 2) + Math.pow(height, 2))
    len * portion
  }

  def getPointOnLine(p1: Point, p2: Point, portion: Double): Point = {
    val xDelta = (p2.x - p1.x) * portion
    val yDelta = (p2.y - p1.y) * portion
    val x = p1.x + xDelta
    val y = p1.y + yDelta
    new Point(x, y)
  }

}



Measured memory_bytes: 57160
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;

const LL INF=1<<30;
const LL MOD=1000000007;


    bool path[50][50];
    int n,m;
    int a[50],b[50];
    bool visit[59];

    void dfs(int x){
        visit[x]=true;
        for(int i=0;i<m;++i){
            if(path[x][i]){
                if(!visit[i]){
                    dfs(i);
                }
            }
        }
        
    }



int main(){
    cin>>n>>m;
    int ans=0;
    for(int i=0;i<m;++i){
       cin>>a[i]>>b[i];
        a[i]--;b[i]--;

        path[a[i]][b[i]]=path[b[i]][a[i]]=true;
    }
        
    for(int i=0;i<m;++i){
        path[a[i]][b[i]]=path[b[i]][a[i]]=false;
    
    for(int j=0;j<n;++j){
        visit[j]=false;
    }
    dfs(0);
    bool vo=false;
    for(int j=0;j<n;++j){
        if(!visit[j]){
            vo=true;
        }
    }
    if(vo)ans++;

    path[a[i]][b[i]]=path[b[i]][a[i]]=true;


    }

    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  vector<int> a(5);
  REP(i, 5) cin >> a[i];
  sort(ALL(a));
  int ans = INF;
  do{
    int  t = 0;
    REP(i, 4){
      t += (a[i]+9)/10*10;
    }
    t += a[4];
    chmin(ans, t);
  }while(next_permutation(ALL(a)));
  cout << ans << endl;
  return 0;
}

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

int main()
{
	long long x, a;
	cin >> x;
	while (1)
	{
		a = x;
		for (int i = 2; i <= sqrt(x); i++)
		{
			if (x % i == 0)
			{
				x++;
				break;
			}
		}
		if (a == x)
		{
			cout << a << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc147/tasks/abc147_c

#include "algorithm"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  struct Statement {
    ll person;
    bool is_true;
  };

  V<V<Statement>> st(N, V<Statement>(0));

  rep(i, N) {
    ll a;
    cin >> a;

    rep(j, a) {
      ll x;
      bool y;
      cin >> x >> y;
      x--;

      st[i].push_back({x, y});
    }
  }

  ll res = 0;

  auto satisfied = [st, N](ll digit) -> bool {
    VL is_trues(N, -1);  // 0: 嘘, 1: 本当

    rep(i, N) {
      auto is_true = (digit >> i) & 1;

      if (is_trues[i] != -1 && is_trues[i] != is_true) return false;

      is_trues[i] = is_true;

      if (!is_true) continue;

      for (auto s : st[i]) {
        if (is_trues[s.person] != -1 && is_trues[s.person] != s.is_true)
          return false;

        is_trues[s.person] = s.is_true;
      }
    }

    return true;
  };

  rep(digit, 1 << N) {
    if (satisfied(digit)) {
      ll ct = 0;

      for (ll mask = 1; mask != 0; mask <<= 1) {
        if ((digit & mask) != 0) ct++;
      }

      chmax(res, ct);
    }
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
n = int(input())
p = [int(i) for i in input().split()]
l = len(p)
number = [i+1 for i in range(l)]
d = [bool(p[i]-number[i]) for i in range(l)]
d.append(True)
cnt = 0
i = 0
while i < l:
    if d[i] == False:
        cnt += 1
        if d[i+1] == False:
            i += 1
    i += 1

print(cnt)

Measured memory_bytes: 13880
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=100;

ll x,a,b;

int main(){
  cin>>x>>a>>b;
  ll ans=(x-a)%b;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long H,W;cin>>H>>W;
  vector<long>C(26,0);
  for(long i=0;i<H;i++){
    string s;cin>>s;
    for(char c:s)C[c-97]++;
  }
  long x=0,y=0;
  for(long c:C){
    if(c%2)x++;
    else if(c%4==2)y++;
  }
  if(H%2 && W%2)cout<<(x==1&&y*2<=H+W-2?"Yes":"No");
  else if(H%2)cout<<(x==0&&y*2<=W?"Yes":"No");
  else if(W%2)cout<<(x==0&&y*2<=H?"Yes":"No");
  else cout<<(x==0&&y==0?"Yes":"No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

map<char, int> mp;
map<char, function<ll(ll, ll)> > func;

template<typename T> class Parser
{
private:
    string eq;
    int pos;
    T expr(){
        T res = mid();
        while(mp[eq[pos]] == 1){
            char c = eq[pos++];
            res = func[c](res, mid());
        }
        return res;
    }
    T mid(){
        T res = term();
        while(mp[eq[pos]] == 2){
            char c = eq[pos++];
            res = func[c](res, term());
        }
        return res;
    }
    T term(){
        T res = factor();
        while(mp[eq[pos]] == 3){
            char c = eq[pos++];
            res = func[c](res, factor());
        }
        return res;
    }
    T factor(){
        if(isdigit(eq[pos])) return number();
        pos++; // '('をとばす
        T res = expr();
        pos++; // ')'をとばす
        return res;
    }
    T number(){
        T res = 0;
        do{
            res *= 10;
            res += (eq[pos++] - '0');
        }while(isdigit(eq[pos]));
        return res;
    }

public:
    Parser(string& s) : eq(s){}
    T solve(){
        pos = 0;
        return expr();
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    Parser<ll> ps(s);
    ll mx = numeric_limits<ll>::min();
    func['+'] = [&](ll x, ll y){ return x + y; };
    func['-'] = [&](ll x, ll y){ return x - y; };
    func['*'] = [&](ll x, ll y){ return x * y; };
    srep(i, 1, 4){
        srep(j, 1, 4){
            srep(k, 1, 4){
                mp['+'] = i, mp['-'] = j, mp['*'] = k;
                cmx(mx, ps.solve());
            }
        }
    }
    cout << mx << "\n";
    return 0;
}



Measured memory_bytes: 3244
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, a, v;
vector<P> vp;

bool flag(P a, P b){
	if (a.se == b.se)return a.first < b.first;
	return a.second > b.second;
}
int main(){
	cin >> n;
	int max = -1, pa = 20;
	REP(i, n){
		cin >> a >> v;
		vp.push_back(P(a, v));
	}
	sort(ALL(vp), flag);
	cout << vp[0].first << " " << vp[0].second << endl;
}

Measured memory_bytes: 1200
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#define maxn 300005
#define lson (now<<1)
#define rson ((now<<1)|1)
#define mid ((nl+nr)>>1)
using namespace std;
typedef long long ll;
int n,k;
int a[maxn];
int dat[maxn<<2];
void pushup(int now)
{
	dat[now]=max(dat[lson],dat[rson]);
}
void add(int ql,int val,int nl,int nr,int now)
{
	if(nl==nr)
	{
		dat[now]=max(dat[now],val);
		return;
	}
	if(ql<=mid)
		add(ql,val,nl,mid,lson);
	else
		add(ql,val,mid+1,nr,rson);
	pushup(now);
}
int query(int ql,int qr,int nl,int nr,int now)
{
	if(ql<=nl && nr<=qr)	
		return dat[now];
	int ans=0;
	if(ql<=mid)
		ans=max(ans,query(ql,qr,nl,mid,lson));
	if(mid<qr)
		ans=max(ans,query(ql,qr,mid+1,nr,rson));
	return ans;
}

int dp[maxn];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int qr=min(300000,a[i]+k);
		int ql=max(0,a[i]-k);
		int res=query(ql,qr,0,300000,1);
		add(a[i],res+1,0,300000,1);
		ans=max(ans,res+1);
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 9028