akhauriyash/Code-Regression huggingface dataset:
# Ford-Fulkerson algorithm
class FordFulkerson:
  def __init__(self, N):
    self.N = N
    self.edge = [[] for i in range(N)]

  def add_edge(self, fr, to, cap):
    forward = [to, cap, None]
    forward[2] = backward = [fr, 0, forward]
    self.edge[fr].append(forward)
    self.edge[to].append(backward)

  def add_multi_edge(self, v1, v2, cap1, cap2):
    edge1 = [v2, cap1, None]
    edge1[2] = edge2 = [v1, cap2, edge1]
    self.edge[v1].append(edge1)
    self.edge[v2].append(edge2)

  def dfs(self, v, t, f):
    if v == t:
      return f
    used = self.used
    used[v] = 1
    for e in self.edge[v]:
      w, cap, rev = e
      if cap and not used[w]:
        d = self.dfs(w, t, min(f, cap))
        if d:
          e[1] -= d
          rev[1] += d
          return d
    return 0

  def flow(self, s, t):
    flow = 0
    f = INF = 10**9 + 7
    N = self.N
    while f:
      self.used = [0]*N
      f = self.dfs(s, t, INF)
      flow += f
    return flow

import sys
readline = sys.stdin.readline

N = int(input())
R = [list(map(int, input().split())) for _ in range(N)]
B = [list(map(int, input().split())) for _ in range(N)]
ff = FordFulkerson(2*N+2)
for v in range(1,N+1):
  ff.add_edge(0,v,1)
for v in range(N):
  ff.add_edge(1+N+v,2*N+1,1)
for u,(a,b) in enumerate(R):
  for v,(c,d) in enumerate(B):
    if a<c and b<d:
      ff.add_edge(1+u,1+N+v,1)
ans = ff.flow(0,2*N+1)
print(ans)

Measured memory_bytes: 71460
#include <iostream>

using namespace std;

int solve(int n, int k)
{
    int cnt = 1;
    while(n >= k) {
        n = int((n - n%k) / k);
        cnt++;
    }

    return cnt;
}

int main()
{
    int n, k;
    cin >> n >> k;
    cout << solve(n, k) << endl;

    return 0;
}

Measured memory_bytes: 3540
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int X, Y;

int waf(int N)
{
	if (N <= 3) return (4 - N) * 100000;
	return 0;
}
int main()
{
	scanf("%d%d", &X, &Y);
	int ans = waf(X) + waf(Y);
	if (X == 1 && Y == 1) ans += 400000;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;
template<Int Mod = 1000000007> class modint{
public:
	Int val;
	constexpr modint(const Int x = 0) : val(x % Mod) {if(val < 0) val += Mod;}
	constexpr modint operator+(const modint rhs) const {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const {
		return modint(*this) /= rhs;
	}
	constexpr modint operator-() const {
		return modint(Mod - val);
	}
	constexpr modint &operator+=(const modint rhs){
		val += rhs.val;
		if(val >= Mod) val -= Mod;
		return *this;
	}
	constexpr modint &operator-=(const modint rhs){
		if(val < rhs.val) val += Mod;
		val -= rhs.val;
		return *this;
	}
	constexpr modint &operator*=(const modint rhs){
		val *= rhs.val;
		val %= Mod;
		return *this;
	}
	constexpr modint &operator/=(const modint rhs){
		return *this *= inv(rhs);
	}
	constexpr modint &operator++(){
		++val;
		if(val == Mod) val = 0;
		return *this;
	}
	constexpr modint &operator--(){
		--val;
		if(val == -1) val = Mod - 1;
		return *this;
	}
	constexpr modint operator<<(const Int rhs) const {
		return modint(*this) << rhs;
	}
	constexpr modint operator>>(const Int rhs) const {
		return modint(*this) >> rhs;
	}
	constexpr modint &operator<<=(const Int rhs){
		val <<= rhs;
		val %= Mod;
		return *this;
	}
	constexpr modint &operator>>=(const Int rhs){
		val >>= rhs;
		val %= Mod;
		return *this;
	}
	constexpr bool operator==(const modint rhs) const {
		return val == rhs.val;
	}
	constexpr bool operator!=(const modint rhs) const {
		return val != rhs.val;
	}
	constexpr bool operator<(const modint rhs) const {
		return val < rhs.val;
	}
	constexpr bool operator>(const modint rhs) const {
		return val > rhs.val;
	}
	constexpr bool operator<=(const modint rhs) const {
		return val <= rhs.val;
	}
	constexpr bool operator>=(const modint rhs) const {
		return val >= rhs.val;
	}
	friend ostream& operator<<(ostream& os, const modint<Mod>& m){
		return os << m.val;
	}
	friend istream& operator>>(istream& is, modint<Mod>& m){
		return is >> m.val;
	}
	static constexpr modint inv(modint m){
		Int a = m.val, b = Mod, u = 1, v = 0;
		while(b){
			Int t = a / b;
			a -= t * b;
			swap(a, b);
			u -= t * v;
			swap(u, v);
		}
		u %= Mod;
		if(u < 0) u += Mod;
		return modint(u);
	}
	constexpr operator Int() const {
		return val;
	}
};
using mint = modint<>;
vector<mint> fact(1, 1);
mint comb(Int n, Int r){
	if(n < 0 || r < 0 || n - r < 0) return 0;
	while(Int(fact.size()) <= n)
		fact.push_back(fact.back() * mint(fact.size()));
	return fact[n] / fact[r] / fact[n-r];
}

mint f(mint r, mint c){
	return comb((r+c+mint(2)).val, (c+mint(1)).val) - mint(1);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	mint r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
	cout << f(r2, c2) - f(r2, c1-mint(1)) - f(r1-mint(1), c2) + f(r1-mint(1), c1-mint(1)) << "\n";
}

Measured memory_bytes: 18280
N, A, B, C, D = map(int, input().split())
A, B, C, D = A-1, B-1, C-1, D-1
S = input()

if C > D:
    print('Yes' if '...' in S[B-1:D+2] and '##' not in S[A:C] else 'No')
else:
    print('Yes' if '##' not in S[A:D] else 'No')


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

int main()
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in("a.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    string s;
    map<char, int> m;
    cin >> s;

    for (char& c : s)
    {
        m[c] += 1;
    }

    bool b = true;
    if (m.size() == 2)
    {
        for (auto elem : m)
        {
            if (elem.second == 2)
            {
            }
            else
            {
                b = false;
            }
        }
        if (b) cout << "Yes";
    }
    else {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    a.append(a[i]+1)
    if a[i]!=0:
        a.append(a[i]-1)
b=[0]*(1+max(a))
for ai in a:
    b[ai]+=1
print(max(b))

Measured memory_bytes: 15740
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define rep(i, a, b) for(int i = a; i <= b; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 3e2+10;
const int M = 1e6+10;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}
inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}
inline ll C(ll y, ll x) { ll ans = 1; if(y < 0 || x < 0 || y < x) return 0; y %= mod; if(!y || !x) return 1; rep(i, 0, x-1) ans = ans * (y-i) % mod; rep(i, 1, x) ans = ans * Pow(i, mod-2) % mod; return ans; }
//==================================================================================================================================================================//

int n, c[5];
db ans, dp[N][N][N];

int main() {
   scanf("%d", &n);
   rep(i, 1, n) {
      int x; scanf("%d", &x);
      c[x]++;
   }
   rep(k, 0, n) rep(j, 0, n) rep(i, 0, n) {
      if(i || j || k) {
         if(i) dp[i][j][k] += dp[i-1][j][k] * i / (i+j+k);
         if(j) dp[i][j][k] += dp[i+1][j-1][k] * j / (i+j+k);
         if(k) dp[i][j][k] += dp[i][j+1][k-1] * k / (i+j+k);
         dp[i][j][k] += (db)n / (i+j+k);
      }
   }
   ans = dp[c[1]][c[2]][c[3]];
   printf("%.9lf\n", ans);
   return 0;
}

Measured memory_bytes: 224400
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
#define ll long long
#define mod 1000000007;


int main() {
	int n, k, q, a[100010], b[100010] = { 0 };
	bool ans[100010] = { true };
	cin >> n >> k >> q;
	for (int i = 0; i < q; i++)cin >> a[i];
	for (int i = 0; i < q; i++) {
		b[a[i] - 1]++;
	}
	for (int i = 0; i < n; i++) {
		b[i] -= q;
		b[i] += k;
		if (b[i] <= 0)cout << "No" << endl;
		else cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    ll N;
    cin>>N;
    vector<LP> hen(N-1);
    rep(i,N-1){
        ll u,v;
        cin>>u>>v;
        if(u>v)swap(u,v);
        hen.at(i).first=u;
        hen.at(i).second=v;
    }
    ll ans=0;
    for(ll i=1;i<=N;i++){
        ans+=(N-i+1)*(N-i+2)/2;
    }
    for(ll i=0;i<N-1;i++){
        ans-=hen.at(i).first*(N-hen.at(i).second+1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6312
N, M = map(int, input().split())
A = list(sorted([list(map(int, input().split())) + [i, 0] for i in range(M)]))
cur = 0
o = 1
for i, a in enumerate(A):
  if cur != a[0]:
    o = 1
    A[i][3] = o
    cur = a[0]
  else:
    o += 1
    A[i][3] = o

for a in sorted(A, key=lambda x: x[2]):
  print('{0:06d}{1:06d}'.format(a[0], a[3]))

Measured memory_bytes: 35948
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int T = 0;
  for (int i = 1; i <= 999; i++){
    for (int j = 1; j <= 10; j++){
      if (i % 3 != 0 && j % 2 == 0){
        T += 19;
      } else {
        T += 20;
      }
    }
  }
  for (int i = 0; i < n; i++){
    int Y, M, D;
    cin >> Y >> M >> D;
    int days = 0;
    for (int j = 1; j <= Y; j++){
      for (int k = 1; k <= 10; k++){
        if (j == Y && k == M){
          break;
        }
        if (j % 3 != 0 && k % 2 == 0){
          days += 19;
        } else {
          days += 20;
        }
      }
    }
    days += D;
    cout << T - days + 1 << endl;
  }
}


Measured memory_bytes: 3076
n, m = gets.strip.split.map(&:to_i)
a = []
n.times do
    a << gets.strip
end

b = []
m.times do
    b << gets.strip
end

def match?(a, b, m, i, j)
    m.times do |k|
        m.times do |l|
            if a[i + k][j + l] != b[k][l]
                return false
            end
        end
    end
    return true
end

(n - m + 1).times do |i|
    (n - m + 1).times do |j|
        if match?(a, b, m, i, j)
            puts 'Yes'
            exit
        end
    end
end

puts 'No'

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

using static Input;
using static Util;
class Program
{
    static int[] N;
    static List<KeyValuePair<int,int>> key = new List<KeyValuePair<int,int>>();
    static void INPUT()
    {
        N = LineInt();
        for (var i = 0; i < N[1]; i++)
        {
            var A = LineInt();
            var C = LineInt();
            var b = 0;
            foreach (var c in C)
            {
                b |= 1 << (c-1);
            }

            key.Add(new KeyValuePair<int, int>( A[0], b));
        }
    }
    static void OUT()
    {
        var dp = new int[1<<N[0]];
        for (var i = 0; i < dp.Length; i++)
            dp[i] = INF;

        dp[0] = 0;
        for(var b = 0; b < 1 << N[0]; b++)
        {
            if (dp[b] == INF) continue;
            foreach (var k in key)
            {
                var tb = b | k.Value;
                dp[tb] = Math.Min(dp[tb] , dp[b] + k.Key);
            }
        }

        if (dp.Last() == INF)
        {
            Console.WriteLine(-1);
            return;
        }
        Console.WriteLine(dp.Last());
    }
    static void Main(string[] args)
    {
#if DEBUG  
        TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
        //M = new long[] { 101 ,202 };
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 13524
/*2019/08/25 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
void swapc(char *x,char *y){char tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
int llasc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
int lldesc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
/*
int asc_t(const void *a,const void *b){return ((struct_t*)a)->member - ((struct_t*)b)->member;}
int desc_t(const void *a,const void *b){return ((struct_t*)b)->member - ((struct_t*)a)->member;}
*/

int main(){
    char str[10];
    char asc[10],desc[10];
    int asc_n,desc_n;
    int cnt=0;
    int flg=0;
    while(1){
        cnt=0;
        flg=0;
        scanf("%s",str);
        if(!strcmp(str,"0000")){
            break;
        }
        flg=0;
        for(int i=0;i<3;i++){
            if(str[i]!=str[i+1]){
                flg=1;
                break;
            }
        }
        
        if(!flg){
            printf("NA\n");
            continue;
        }

        while(1){
            //printf("%s\n",str);
            if(!strcmp(str,"6174")){
                break;
            }

            cnt++;
            strcpy(asc,str);
            strcpy(desc,str);
            for(int i=0;i<3;i++){
                for(int j=i+1;j<4;j++){
                    if(asc[i]>asc[j]){
                        swapc(&asc[i],&asc[j]);
                    }
                }
            }
            for(int i=0;i<3;i++){
                for(int j=i+1;j<4;j++){
                    if(desc[i]<desc[j]){
                        swapc(&desc[i],&desc[j]);
                    }
                }
            }
            //printf("%s %s\n",asc,desc);
            asc[4]=desc[4]='\0';
            asc_n=atoi(asc);
            desc_n=atoi(desc);
            //printf(">%d %d\n",asc_n,desc_n);
            sprintf(str,"%04d",desc_n-asc_n);
            str[4]='\0';
        }
        printf("%d\n",cnt);
    }
    return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)

using LL  = long long;

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

int main() {
    std::ios::sync_with_stdio(false);
    char x, y;cin >> x >> y;
    char ans = '=';
    if(x < y) ans = '<';
    if(x > y) ans = '>';
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import Data.List
import Debug.Trace

main = do
  [n, k] <- map read . words <$> getLine :: IO [Int]
  as <- map read . words <$> getLine :: IO [Int]
  print $ solve n k as

solve n k as =
  traceShow (l,r) $
  traceShow (lenl,lenr) $
  traceShow next $
  traceShow (ansl,ansr) $
  ans
  where
    (l,r) = span (>1) as
    lenl = --if length l >= k then length l + 1 else
      length l
    lenr = length r
    (ansl,next) = if lenl==0 then (0,0) else solve_ (lenl+1) k (0,0) 
    (ansr,_) =
      if lenr==1 then (0,0)
      else if lenr<=next+1 then (0,0)
           else solve_ (lenr-next) k (0,0)
    ans = ansl + ansr
    solve_ len k (ans,next) =
      if len <= k then (ans+1,k-len)
      else solve_ (len - (k-1)) k (ans+1,0) 


Measured memory_bytes: 51580
const main = stdin => {
  const input = stdin.trim().split('\n')
  const [a, b, c] = input[0].split(' ').map(x => parseInt(x))
  if (a === b && b === c || a !== b && a !== c && b !== c) {
    console.log('No')
  } else {
    console.log('Yes')
  }
}

// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr int INF = 1001001001;

int N;
int B[200100];
int Q;
std::vector<int> query[200100];

struct LazySegmentTree{ // 区間加算 + 区間最小値 + 点更新
    int numLeaves;
    std::vector<int> data, lazy;

    LazySegmentTree(int n){
        numLeaves = 1;
        while(numLeaves < n){
            numLeaves *= 2;
        }

        data.assign(numLeaves * 2, INF);
        lazy.assign(numLeaves * 2, 0);
    }

    void propagate(int k){
        if(lazy[k] == 0){
            return;
        }

        if(data[k] < INF){
            data[k] += lazy[k];
        }

        if(k < numLeaves){
            lazy[k*2] += lazy[k];
            lazy[k*2+1] += lazy[k];
        }

        lazy[k] = 0;
    }
    
    void add(int l, int r, int v){
        add(l, r, v, 1, 0, numLeaves);
    }

    void add(int l, int r, int v, int k, int a, int b){
        propagate(k);

        if(b <= l || r <= a){
            return;
        }

        if(l <= a && b <= r){
            lazy[k] = v;
            propagate(k);
        }else{
            int m = (a + b) / 2;
            add(l, r, v, k * 2, a, m);
            add(l, r, v, k * 2 + 1, m, b);
            data[k] = std::min(data[k*2], data[k*2+1]);
        }
    }

    void set(int k, int v){
        k += numLeaves;

        std::stack<int> s;

        int l = k;
        while(l > 1){
            s.emplace(l ^ 1); // l のお隣を追加
            l /= 2;
        }

        until(s.empty()){
            propagate(s.top() / 2);
            propagate(s.top());
            s.pop();
        }

        data[k] = v;
        lazy[k] = 0;

        while(k > 1){
            k /= 2;
            data[k] = std::min(data[k*2], data[k*2+1]);
        }
    }

    int minimum(int l, int r){
        return minimum(l, r, 1, 0, numLeaves);
    }

    int minimum(int l, int r, int k, int a, int b){
        if(b <= l || r <= a){
            return INF;
        }

        propagate(k);

        if(l <= a && b <= r){
            return data[k];
        }

        int m = (a + b) / 2;
        int ml = minimum(l, r, k * 2, a, m),
            mr = minimum(l, r, k * 2 + 1, m, b);
        return std::min(ml, mr);
    }
};

// 0, b から 1, b に変えたときのハミング距離の変化量
int f(int b){
    return b == 0 ? +1 : -1;
}

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

    std::cin >> N;

    for(int i=1;i<=N;++i){
        std::cin >> B[i];
    }

    std::cin >> Q;

    for(int i=0;i<Q;++i){
        int l, r;
        std::cin >> l >> r;

        query[l].emplace_back(r);
    }

    int d = std::count(B + 1, B + 1 + N, 1);

    LazySegmentTree seg(N + 1);
    seg.set(0, 0);

    for(int i=1;i<=N;++i){
        std::sort(query[i].rbegin(), query[i].rend());

        for(int r : query[i]){
            seg.set(r, seg.minimum(0, r + 1));
        }

        seg.add(i, N + 1, f(B[i]));
    }

    int min_d = d + seg.minimum(0, N + 1);
    std::cout << min_d << std::endl;
}

Measured memory_bytes: 15744
n = int(input())
arr = list(map(int, input().split()))
arr.sort()

dp = [0] * (10**7)

cnt = 0
for i in range(n):
    if dp[arr[i]] == 0:
        for j in range(1, (10**6 + 10) // arr[i] + 1):
            dp[arr[i] * j] += 1
        if i < n - 1:
            if arr[i] == arr[i + 1]:
                continue
        cnt += 1
    else:
        continue

print(cnt)

Measured memory_bytes: 97908
#include <stdio.h>

int main(void) {
    int n, m, k, i, j;
    scanf("%d%d%d", &n, &m, &k);
    for (i = 0; i <= n; i++) {
        for (j = 0; j <= m; j++) {
            if (m * i + n * j - 2 * i * j == k) {
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}


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


int main(void) {
  int x, y, z;
  cin >> x >> y >> z;

  int ans = 0;

  x -= y + 2 * z;
  ans++;

  while (x >= y + z) {
    x -= y + z;
    ans++;
  }

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll N; cin >> N;
    vector<llll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i].first;
        A[i].second = i;
    }

    sort(ALL(A));

    ll cnt = 0;
    for (int i = 0; i < N; i++) {
        if(abs(A[i].second - i)%2 == 1){
            cnt++;
        }
    }
    printf("%lld\n", cnt/2);


    

}


Measured memory_bytes: 4824
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>

using std::cin;
using std::cout;
using std::endl;

using std::vector;
using std::set;

using std::min;

int main(void) {
    int A, B, C, D;
    int E, F;
    cin >> A >> B >> C >> D >> E >> F;

    set<int> water_set;
    for (int a = 0; a <= F; a += 100 * A) {
        for (int b = 0; a + b <= F; b += 100 * B) {
            water_set.insert(a + b);
        }
    }

    int opt_water = 0;
    int opt_sugar = 0;
    for (int water : water_set) {
        const int limit = min(F - water, E * (water / 100));
        for (int c = 0; c <= limit; c += C) {
            for (int d = 0; c + d <= limit; d += D) {
                int sugar = c + d;
                if(sugar * (opt_sugar + opt_water) >= opt_sugar * (sugar + water)){
                    opt_sugar = sugar;
                    opt_water = water;
                }
            }
        }
    }

    cout << (opt_sugar + opt_water) << " " << opt_sugar << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

[A,B] = inpl()
print(max([A+B, A-B, A*B]))

Measured memory_bytes: 12540
def main():
    a = [[int(i) for i in input().split()] for _ in range(3)]
    n = int(input())
    ans = 'No'
    for i in range(n):
        b = int(input())
        for index, j in enumerate(a):
            if j[0] == b:
                a[index][0] = 0
            elif j[1] == b:
                a[index][1] = 0
            elif j[2] == b:
                a[index][2] = 0

    for i in a:
        if not any(i):
            ans = 'Yes'

    for i in zip(*a):
        if not any(i):
            ans = 'Yes'

    if not a[0][0] and not a[1][1] and not a[2][2]:
        ans = 'Yes'
    elif not a[0][2] and not a[1][1] and not a[2][0]:
        ans = 'Yes'

    print(ans)


if __name__ == "__main__":
    main()


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

vector<int> pr(100001);
vector<int> sz(100001);

// 初期化
void init(int n)
{
  for (int i = 0; i < n; i++)
  {
    pr[i] = i;
    sz[i] = 1;
  }
}

// 木の根を求める
int root(int x)
{
  if (pr[x] == x)
    return x;
  else
    return pr[x] = root(pr[x]);
}

// xとyが同じ集合に属するか否か
bool same(int x, int y)
{
  return root(x) == root(y);
}

// xとyの属する集合を併合
void unite(int x, int y)
{
  x = root(x);
  y = root(y);
  if (x == y)
    return;
  if (sz[x] > sz[y])
  {
    pr[y] = x;
    sz[x] += sz[y];
  }
  else
  {
    pr[x] = y;
    sz[y] += sz[x];
  }
}

int size(int x)
{
  return sz[root(x)];
}

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  for (int i = 0; i < M; i++)
  {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }
  init(N);
  vector<long> ans;
  long val = (long)N * (N - 1) / 2;
  for (int i = M - 1; i >= 0; i--)
  {
    ans.push_back(val);
    if (same(A[i], B[i]))
      continue;
    val -= (long)size(A[i]) * size(B[i]);
    unite(A[i], B[i]);
  }
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i] << endl;
  return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  in(string, s, t);
  rep(i, n) cout << s[i] << t[i];
  cout << endl;
}


Measured memory_bytes: 256
"""import sys
input = sys.stdin.readline"""
n=int(input())
a=list(map(int,input().split()))
cnt2=0
cnt4=0
for i in a:
    if i%4==0:
        cnt4+=1
    elif i%2==0:
        cnt2+=1
if cnt2>1:
    ans=n-cnt4*2-cnt2
if cnt2<=1:
    ans=n-cnt4*2-1
print("Yes" if ans<=0 else "No")


Measured memory_bytes: 62576
#include <stdio.h>
typedef long long ll;
int main() {
	int n, d;
	scanf("%d%d", &n, &d);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		if ((ll)x * x + (ll)y * y <= (ll)d * d) {
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1732
import numpy as numpy

N, A, B, C = map(int, input().split())
l=[]
for i in range(N):
  l.append(input())
l = [int(i) for i in l]
INF=10**9
n = 0

def dfs(n,a,b,c):
  if n == N:
    return INF if min(a, b, c) == 0 else abs(a - A) + abs(b - B) + abs(c - C) - 30
  res0 = dfs(n + 1, a, b, c)
  res1 = dfs(n + 1, l[n] + a, b, c) + 10
  res2 = dfs(n + 1, a, l[n] + b, c) + 10
  res3 = dfs(n + 1, a, b, l[n] + c) + 10
  return min(res0, res1, res2, res3)

print(dfs(0,0,0,0))

Measured memory_bytes: 14440
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define p (int)(1e9 + 7)

int MOD(ll a){
	return (int)((a %= p) >= 0 ? a : a + p);
}

int power(int a, int N){
	if(N == 0){
		return 1;
	}
	else if(N % 2 == 0){
		return power(MOD((ll)a * a), N / 2);
	}
	else{
		return MOD((ll)a * power(a, N - 1));
	}
}

int f(int k, int l){
	if(k < l || (k - l) % 2 == 1){
		return 0;
	}
	else{
		return power(2, (k - l) / 2);
	}
}

signed main(){
	int N, i, j;
	scanf("%d", &N);
	string s;
	cin >> s;
	vector<vector<int>> dp(N + 1, vector<int>(N + 2, 0)), dp2(N + 1, vector<int>(N + 2, 0));
	dp[0][0] = 1;
	for(i = 1; i <= N; i++){
		for(j = 0; j <= N; j++){
			if(j > 0){
				dp[i][j] = MOD((ll)dp[i - 1][j - 1] + dp[i - 1][j + 1]);
			}
			else{
				dp[i][j] = dp[i - 1][j + 1];
			}
		}
	}
	dp2[0][0] = 1;
	for(i = 1; i <= N; i++){
		for(j = 0; j <= N; j++){
			if(j > 0){
				dp2[i][j] = MOD(2 * (ll)dp2[i - 1][j - 1] + dp2[i - 1][j + 1]);
			}
			else{
				dp2[i][j] = MOD((ll)dp2[i - 1][j] + dp2[i - 1][j + 1]);
			}
		}
	}
	int ans = 0;
	for(i = 1; i <= N; i++){
		ans = MOD(ans + (ll)MOD((ll)dp2[i - 1][0] * dp[N - i][s.size() - 1]) * f(N - i, s.size() - 1));
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 195968
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll x;
  cin >> x;
  vector<ll> p;
  rep(i, 201){
    p.push_back(pow(i, 5));
  }
  rep(i, p.size()){
    rep(j, p.size()){
      ll ni = p.at(i), nj = p.at(j);
      if(ni - nj == x){
        cout << i << " " << j << endl;
        return 0;
      }
      if(ni + nj == x){
        cout << i << " " << -j << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3964
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

dp = [0] * N
dp[0] = 1000

for i in range(N - 1):
    dp[i + 1] = max(dp[i], (dp[i] // A[i]) * A[i + 1] + dp[i] % A[i])

print(dp[N - 1])


Measured memory_bytes: 9172
from collections import deque
import numpy as np
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

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


def bfs(sy, sx):
    if s[sy][sx] == '#':
        return -1
    # 未探索ステータス-1で初期化しておく
    dist = [[-1] * w for _ in range(h)]
    dist[sy][sx] = 0
    dq = deque()
    dq.append((sy, sx))
    while dq:
        y, x = dq.popleft()
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if 0 <= ny < h and 0 <= nx < w:
                if s[ny][nx] == '#' or dist[ny][nx] != -1:
                    continue
                dist[ny][nx] = dist[y][x] + 1
                dq.append((ny, nx))
    return np.array(dist).max()


ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, bfs(i, j))
print(ans)

Measured memory_bytes: 12452
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int bad[10];

bool good(int n) {
    while (n) {
        if (bad[n % 10]) return false;
        n /= 10;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n, k;
    cin >> n >> k;
    forn(i, k) {
        int x;
        cin >> x;
        bad[x] = 1;
    }
    while (!good(n)) ++n;
    cout << n << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	solve(){}
	ll operator()() {
		return 0;
	}
};

int main(void)
{
	char s[20+2];

	while(scanf("%20[a-z]\n", s)==1)
	{
		printf("%.*s\n", 3, s);
	}
	return 0;
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int a, b; cin >> a >> b;
	if(a + b < 0) cout << -1 << endl;
	else if(a + b == 0) cout << 0 << endl;
	else cout << 1 << endl;
	return 0;
}


Measured memory_bytes: 3124
n,k=map(int,input().split())
h=[]
for i in range(n):
  h.append(int(input()))

h.sort()
S=10000000000000
for i in range(n-k+1):
  if S>h[i+k-1]-h[i]:
    S=h[i+k-1]-h[i]
print(S)

Measured memory_bytes: 7384
s = input()
s = s.replace('BC', 'D')
ans = 0
cntA = 0
for i in range(len(s)):
    if s[i] == 'A':
        cntA += 1
    elif s[i] == 'D':
        ans += cntA
    else:
        cntA = 0

print(ans)

Measured memory_bytes: 9340
a,b,c = list(map(int,input().split()))
k = int(input())
sum = 0
in_list = [a,b,c]
sorted_in_list = sorted(in_list,reverse=True)
for i in range(k):sorted_in_list[0] *= 2

sum = sorted_in_list[0] + sorted_in_list[1] + sorted_in_list[2]

print(sum)

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

int main() {
  int N, count = 0;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i) == A.at(i + 1)) {
        count++;
    }
    else {
        continue;
    }
  }
  
  if (count == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }

}


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

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

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

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

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

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

ll mod = 1e9 + 7;
int N,M,T,K,tc;

char p[1050][1050];
bool inbound(int y, int x){
	return x >= 1 && y >= 1 && x <= M && y <= N;
}

int xx[4] = {1,-1,0,0}, yy[4] = {0,0,1,-1};

int cnt[1050][1050];
bool inq[1050][1050];
int main(){
	geti(N,M);
	repp(i,N) scanf("%s",p[i]+1);

	if( p[1][1] == '#' || p[N][M] == '#' ){
		printf("-1\n");
		return 0;
	}
	repp(i,N) repp(j,M) cnt[i][j] = INF;
	repp(i,N) repp(j,M) inq[i][j] = false;
	cnt[1][1] = 0; inq[1][1] = 1;
	queue<Pi> q; q.push({1,1});

	int bcnt = 0;
	while( !q.empty() ){
		int x = q.front().Se, y = q.front().Fi;
		q.pop();
		rep(d,4){
			int nx = x + xx[d], ny = y + yy[d];
			if( !inbound(ny,nx) ) continue;
			if( inq[ny][nx] ) continue;
			if( p[ny][nx] == '#' ) continue;

			q.push({ny,nx});
			inq[ny][nx] = true;
			cnt[ny][nx] = cnt[y][x] + 1;
		}
	}



	repp(i,N) repp(j,M) if( p[i][j] == '#' ) bcnt++;

	if( cnt[N][M] == INF ){
		printf("-1\n");
		return 0;
	}

	printf("%d\n",N*M - cnt[N][M] - bcnt - 1);

}


Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n,k;
  scanf("%d%d",&n,&k);
  int *x=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++) scanf("%d",x+i);
  int min=100000000*3;
  for(i=0;i+k-1<n;i++){
    int d=MIN(ABS(x[i])+ABS(x[i+k-1]-x[i]),ABS(x[i+k-1])+ABS(x[i+k-1]-x[i]));
    min=MIN(min,d);
  }
  printf("%d\n",min);
}

int main(void){
  run();
  return 0;
}


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

int main()
{
	while(true){
		string r,a;
		cin >> r >> a;
		if(r=="0" && a=="0")
			break;

		int hit=0,blow=0;

		for(int i=0 ;i<4 ;i++){
			for(int j=0 ;j<4 ;j++){
				if(r[i] == a[j]){
					if(i==j)
						hit++;
					else
						blow++;
				}
			}
		}
		cout << hit << ' ' << blow << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include<stdio.h>
#include<string.h>

using namespace std;

int main(){
char s[11];
string s2;
int p=0;

for(int i=0;i<10;i++){
s[i]=-1;
}

	
scanf("%s",s);

while(s[p]!=-1){
if(s[p]!='B'){
	s2+=s[p];
}
else if(s2.length()>0&&s[p]=='B'){
	s2.erase(s2.end()-1,s2.end());
}
p++;
}

printf("%s\n",s2.c_str());
return 0;
}

Measured memory_bytes: 256
import math
import itertools

# -1 no ans
# 1 syoziki
# 0 hu sinsetu

N = int(input())
ans = [[-1] * N for i in range(N)]


for person in range(N):
    A = int(input())
    for _ in range(A):
        x, y = map(int, input().split())
        x -= 1
        ans[person][x] = y


def is_ok(num):
    # -1 not decided
    # 1 syoziki
    # 0 husinsetu
    people = [-1] * N
    for i in range(N):
        # i is syoziki
        if((num >> i) & 1):
            if(people[i] == 0):
                return False
            people[i] = 1
            for j in range(N):
                if(ans[i][j] == 1):
                    if(people[j] == 0):
                        return False
                    people[j] = 1
                if(ans[i][j] == 0):
                    if(people[j] == 1):
                        return False
                    people[j] = 0
        else:
            if(people[i] == 1):
                return False
            people[i] = 0

    return True


def countBit(num):
    ori = num
    count = 0
    while(num > 0):
        if(num & 1):
            count += 1
        num = num >> 1
    return count


out = 0

for i in range(1 << N):
    if(is_ok(i)):
        out = max(out, countBit(i))

print(out)

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

import sys
sys.setrecursionlimit(300000)


def solve(X: int, N: int, p: "List[int]"):
    for i in range(1000):
        if not X - i in p:
            ret = X - i
            break
        if not X + i in p: 
            ret = X + i
            break
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()


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

#ifdef LOCAL
	#define D(a) cerr << #a << " = " << a << endl
#else
	#define D(a)
	#define cerr false && cerr
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

const int N = 1e5, K = 2;

int n;
vi adj[N];

int color[N], n_color[K]; 
int s, t;
void paint(int u = 0, int p = -1, int cur_color = 1) {
    color[u] = cur_color;
    n_color[cur_color==1]++;

    int next_color = -1 * cur_color;
    for (int v : adj[u]) if (v != p) {
        if (!color[v]) paint(v, u, next_color);
        else s = u, t = v;
    }
}

int need[N];
int calc_needs(int u = 0, int p = -1) {
    need[u] = color[u];

    for (int v : adj[u]) if (v != p) {
        if ((u == s && v == t) || (u == t && v == s)) continue;

        need[u] += calc_needs(v, u);
    } 

    return need[u];
}

bool in_cycle[N];
bool find_cycle(int u = s, int p = -1) {
    if (u == t) in_cycle[u] = true;

    for (int v : adj[u]) if (v != p) {
        if ((u == s && v == t) || (u == t && v == s)) continue;
        
        if (find_cycle(v, u)) in_cycle[u] = true;
    }

    return in_cycle[u];
}

ll calc_cost() {
    ll cost = 0;
    forn(u, n) cost += abs(need[u]);
    return cost;
}

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

int main() {
	fastio;

    int m; cin >> n >> m;
    forn(_, m) {
        int u, v; cin >> u >> v; u--, v--; 
        adj[u].pb(v), adj[v].pb(u); 
    }

    paint();
    int dif_colors = n_color[1] - n_color[0];

    ll ans;
    if (m == n - 1) { // árbol
        if (dif_colors != 0) no();

        calc_needs();

        ans = calc_cost();
    }
    else if (color[s] == color[t]) { // ciclo impar
        if (abs(dif_colors) % 2 == 1) no();

        int need_add = dif_colors / 2;
        color[s] -= need_add, color[t] -= need_add;
        calc_needs();

        ans = abs(need_add) + calc_cost();
    }
    else { // ciclo par
        if (dif_colors != 0) no();

        calc_needs();

        find_cycle();
        vi sorted_needs; sorted_needs.pb(0);
        forn(u, n) if (in_cycle[u] && u != s) sorted_needs.pb(need[u]);
        sorted_needs.pb(0);

        sort(all(sorted_needs)); 
        int opt_move = sorted_needs[si(sorted_needs) / 2];

        color[s] += opt_move, color[t] -= opt_move;
        calc_needs();

        ans = abs(opt_move) + calc_cost();
    }

    cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 16388
#include <stdio.h>

int main(void){
	int a, b;
	scanf("%d %d", &a, &b);
	if (a < b){
		printf("a < b\n");
	}
	else if (a > b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}
	return 0;
}

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

int main() {
	long long n,i,mod=1000000007LL;
	cin >> n;
	long long a[n+1],p[n+1],ans=0LL;
	p[0]=0;
	for(i=1;i<=n;i++)
	{
		cin >> a[i];
		p[i]=a[i]+p[i-1];
		p[i]%=mod;
	}
	for(i=1;i<=n;i++)
	{
		ans+=((p[n]-p[i])*a[i]);
		ans+=mod;
		ans%=mod;
	}
	cout << ans%mod;
	return 0;
}

Measured memory_bytes: 6668
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <vector>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll a,b,c;
    cin >>a>>b>>c;

    if (a<=c && c<=b)
        cout << "Yes" << endl; 
    else
        cout << "No" << endl; 

    return 0;
}


Measured memory_bytes: 256
h, w, k = gets.split.map(&:to_i)
c = Array.new(h) { gets.chomp }
count = 0

(2**h).times do |b1|
  tmp = []

  format("%0#{h}d", b1.to_s(2)).each_char.with_index do |e, idx|
    tmp << c[idx] if e == '1'
  end

  dump = Marshal.dump(tmp)

  (2**w).times do |b2|
    m = Marshal.load(dump)

    format("%0#{w}d", b2.to_s(2)).each_char.with_index do |e, idx|
      m.each { |l| l[idx] = 'r' } if e == '1'
    end

    count += 1 if m.map { |e| e.count('#') }.sum == k
  end
end

puts count

Measured memory_bytes: 14368
n, m = [int(_) for _ in input().split()]
ps_dict = {}
for i in range(m):
    p_, s = input().split()
    p = int(p_)
    if not p in ps_dict.keys():
        ps_dict[p] = [s]
    else:
        ps_dict[p].append(s)

res_ac = 0
res_wa = 0
for k, v in ps_dict.items():
    for i, vi in enumerate(v):
        if vi == 'AC':
            res_ac += 1
            res_wa += i
            break
print(res_ac, res_wa)

Measured memory_bytes: 28120