akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define SZ(x) ((int)(x).size())
using namespace std;
typedef pair<int,int> PII;
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FOR(i,a,b) for (int i = a; i <= b; ++i)
#define M 1000000007
#define MM 998244353
#define SZ(a) int((a).size())
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define mod 1000000007
using ll = long long;

//a and b are assumed to be taken modulo p
inline ll add(ll a, ll b, ll p = mod){ ll c = a + b; if(c >= p) c -= p; return c; }
inline ll sub(ll a, ll b, ll p = mod){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll mul(ll a, ll b, ll p = mod){ return (a * 1ll * b) % p; }
 
using VI = vector<int>;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
using VLL = vector<ll>;
using ld = long double;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;     // Initialize result
  
    x = x % p; // Update x if it is more than or
                // equal to p
  
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
  
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*1ll*x) % p;
    }
    return res;
}
const int MX = 2e4+10;
const int MX2 = 1e6+5;

ll INF= 4 * (ll)1e18;
int mx = 2 * (ll)1e9 + 10;

string v[MX];
vector<vector<string> > dp(3,vector<string>(MX,"|"));
int A[MX];
int main(int argc, const char * argv[]) {

    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0); // insert code here...
    string s;
    cin >> s;
    int n = SZ(s);
    REP(i,n){
        if (i + 1 < n && s[i] == s[i+1]) {
            cout << i + 1 <<" "<< i + 2 << endl;
            return 0;
        }
        else if (i + 2 < n && s[i] == s[i + 2]) {
            cout << i + 1 <<" " << i + 3 <<" ";
            return 0;
        }
    }
    cout << -1 <<" "<<-1 << endl;
    return 0;
}


Measured memory_bytes: 1120
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
 
using namespace std;
 
#define eb emplace_back
#define pb push_back
#define MP make_pair
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define rep(i,j,n) for (int i = j; i < n; ++i)
#define repn(i,j,n) for (int i = j; i <= n; ++i)
#define revn(i,j,n) for (int i = j; i >= n; --i)
#define sz(i) i.size()
#define mem(i,v) memset(i,v,sizeof(i))
#define all(v) v.begin(), v.end()
#define endl '\n'
#define int long long
#define INF 1e18
#define ss second
#define ff first

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
const int mod=1e9+7;
//const int mod=998244353;
const int up=1e5+10;
const int MAXN=1e6+10;


int a[2*up],c[2*up],dp[2*up];
void solve()
{
    int n;
    cin>>n;
    set<string>st;
    string s;
    repn(i,1,n)
    {
        cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<endl;
}





int32_t main()
{
    fast_cin();
    int t;
    // memset(prime, true, sizeof(prime)); 
    // sieve();
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    //cout<<ans<<endl;
}



Measured memory_bytes: 19284
# YouTube
def com(com_n, com_r):
    return fac[com_n] * inv[com_r] * inv[com_n - com_r] % md

p = int(input())
a = list(map(int, input().split()))

# 準備
md = p
n_max = p-1
fac = [1]
inv = [1] * (n_max + 1)
k_fac_inv = 1
for i in range(1, n_max + 1):
    k_fac_inv = k_fac_inv * i % md
    fac.append(k_fac_inv)
k_fac_inv = pow(k_fac_inv, md - 2, md)
for i in range(n_max, 1, -1):
    inv[i] = k_fac_inv
    k_fac_inv = k_fac_inv * i % md

b = [0] * p
for ai, ak in enumerate(a):
    if ak:
        b[0] = (b[0] + 1) % p
        s=1
        for bi in range(p-1,-1,-1):
            b[bi] = (b[bi] - s * com(p - 1, bi)) % p
            s=(-ai*s)%p
print(*b)


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

int main(){
  int n;
  cin >> n;
  vector<int > p(n);
  for ( int i = 0; i < n; i++ ) {
    cin >> p.at(i);
  }
  int cnt = 0;
  for ( int i = 1; i < n-1; i++ ) {
    if ( p.at(i-1) < p.at(i) && p.at(i) < p.at(i+1) ) {
      cnt++;
      // cout << i << " " << p.at(i-1) << p.at(i) << p.at(i+1) << cnt << endl;
    } else if ( p.at(i-1) > p.at(i) && p.at(i) > p.at(i+1) ){
      cnt++;
      // cout << i << " " << cnt << endl;
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans1, ans2 = 0, 0
s = 0
plus = True
for i in range(n):
    if plus:
        if s + a[i] > 0:
            s += a[i]
        else:
            ans1 += abs(1 - (s + a[i]))
            s = 1
    if not plus:
        if s + a[i] < 0:
            s += a[i]
        else:
            ans1 += abs(-1 - (s + a[i]))
            s = -1
    plus = not plus

s = 0
plus = False
for i in range(n):
    if plus:
        if s + a[i] > 0:
            s += a[i]
        else:
            ans2 += abs(1 - (s + a[i]))
            s = 1
    if not plus:
        if s + a[i] < 0:
            s += a[i]
        else:
            ans2 += abs(-1 - (s + a[i]))
            s = -1
    plus = not plus
print(min(ans1, ans2))

Measured memory_bytes: 14468
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (int)(a); v < (int)(b); ++v)
#define FORE(v, a, b) for(int v = (int)(a); v <= (int)(b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define INF (~(1 << 31))
using namespace std;

void split(string str, char chr, vector< string > *res){
	stringstream ss(str);
	string itm;
	while(getline(ss, itm, chr)){
		(*res).PB(itm);
	}
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	const int MAX = 31;
	string name;
	int n, m, d;
	vector< vector< string > > tm;
	map< string, int > chp;
	
	while(cin >> n, n){
		tm.CLR();
		tm.RS(MAX);
		
		chp.CLR();
		
		REP(i, n){
			cin >> name >> m;
			
			chp[name] = 0;
			
			REP(j, m){
				cin >> d;
				tm[d].PB(name);
			}
		}
		
		REP(i, MAX){
			for(vector< string >::iterator it = tm[i].begin(); it != tm[i].end(); ++it){
				chp[*it] += (n - (tm[i].size() - 1));
			}
		}
		
		int minimum = INF;
		string min_name = "";
		
		for(map< string, int >::iterator it = chp.begin(); it != chp.end(); ++it){
			if(it->second < minimum){
				minimum = it->second;
				min_name = it->first;
			}
			if(it->second == minimum){
				min_name = min(min_name, it->first);
			}
		}
		cout << minimum << " " << min_name << endl;
		
		REP(i, MAX) tm[i].CLR();
	}
	
	return 0;
}

Measured memory_bytes: 1248
w, h, n = map(int, input().split())
ld = [0, 0]
ru = [w, h]
xya = []
for i in range(n):
  l = list(map(int, input().split()))
  xya.append(l)  

ans = 0
f = 0
for e in xya:
  x = e[0]
  y = e[1]
  a = e[2]
  if a == 1:
    ld[0] = max(x, ld[0])
  elif a == 2:
    ru[0] = min(x, ru[0])
  elif a == 3:
    ld[1] = max(y, ld[1])
  elif a == 4:
    ru[1] = min(y, ru[1])

  if ld[0] < ru[0] and ld[1] < ru[1]:
    next
  else:
    f = 1
    break

if f == 1:
  ans = 0
else:
  ans = abs(ru[0] - ld[0]) * abs(ru[1] - ld[1])
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define MAX_N 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1

void print(vector<int> v) {
    rep(i, v.size()) {
        if(i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(b / a, c) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	char w[101];
	int wlen;
	int alphabet[26] = { 0 };
	int i, j;

	scanf("%s", w);
	wlen = strlen(w);

	for (i = 0;i < wlen;i++)
	{
		for (j = 0;j < 26;j++)
		{
			if (w[i] == 'a' + j)
			{
				alphabet[j]++;
			}
		}
	}

	for (i = 0;i < 26;i++)
	{
		if (alphabet[i] % 2 != 0)
		{
			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");

	return 0;
}

Measured memory_bytes: 128
n = int(input())
p = list(map(int, input().split()))
ans = 0

for i in range(n-1):
	if i+1 == p[i]:
		p[i],p[i+1] = p[i+1],p[i]
		ans += 1
		
if p[-1] == len(p):
	ans += 1	
print(ans)

Measured memory_bytes: 14008
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<map>
using namespace std;
typedef long long LL;

const int MOD = 1e9+7;
void solve(){
    string s;
    cin>>s;
    int n = s.size();
    for(int i=0;i<n;i++) cout<<'x';
    cout<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    // cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define fi first
#define se second
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define MOD 1000000007
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 200009
#define M 1e6 + 9
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll, ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
#define int long long
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}





void test_case()
{

    int n;
    cin>>n;
    
    string s;
    cin>>s;

    int ans =0;
    

    string temp = "ABC";

    for(int i=0; i<=n-2;i++) {
        string t = s.substr(i,3);
        if(t==temp) {
            ans++;
        }
    }

    cout<<ans<<endl;

    
    
    
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(20);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

Measured memory_bytes: 3592
N,*as=$<.read.split.map(&:to_i)

as.sort!
ret = []

if 0 < as[0] * as[-1]
  if N == 2
    plus = as[-1]
    minus = as[0]
    as = []
  else
    if as[0] < 0
      ret << [as[-1], as[0]]
      plus = as[-1] - as[0]
      minus = as[1]
    else
      ret << [as[0], as[-1]]
      plus = as[1]
      minus = as[0] - as[-1]
    end
    as = as[2..-2]
  end
else
  plus = as[-1]
  minus = as[0]
  as = as[1..-2]
end

as.each do |a|
  if a < 0
    ret << [plus, a]
    plus -= a
  else
    ret << [minus, a]
    minus -= a
  end
end

ret << [plus, minus]

p (plus-minus)
ret.each do|a,b|
  puts "#{a} #{b}"
end


Measured memory_bytes: 21480
#include <iostream>

using namespace std;
long long int X;
int main()
{
    cin>>X;
  
    for(long long int i = 1; i <= 200; i++){
        for(long long int j = -200; j < i; j++){
            if(i*i*i*i*i-j*j*j*j*j==X){cout<<i<<" "<<j<<endl;return 0;}
        }
    }
}


Measured memory_bytes: 3640
s = list(input())
t = list(input())
s_uni = sorted([ord(i) for i in s])
t_uni = sorted([ord(i) for i in t], reverse = True)
for i in range(min(len(s), len(t))):
    if s_uni[i] < t_uni[i]:
        print('Yes')
        exit()
    elif s_uni[i] == t_uni[i]:
        continue
    else:
        print('No')
        exit()
if len(s) < len(t):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[200005];
long long int n, ans = 0;

int judge(int op,int jp,long long &left)
{
	if (op)
		left^= a[op - 1];
	long long i = jp-1;
	while ((left^a[op+i]) == (left + a[op+i])&&(op+i)<n)
	{
		left ^= a[op+i];
		i++;
	}
	return i;
}

int main()
{
	int k = 0;
	long long left = 0;
	cin >> n;
	for (int i = 0;i < n;i++)
		cin >> a[i];
	for (int i = 0;i < n;i++)
	{
		k=judge(i,k,left);
		ans += k;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  long N;
  long K;
  cin>>N>>K;
  vector<long>h(N);
  for(long i=0;i<N;i++)cin>>h[i];
  sort(h.begin(),h.end());
  
  long long ans=0;
  for(long i=0;i<N-K;i++)ans+=h[i];
  cout<<ans<<endl;
}








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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N, A[111];
ll ans;
ll i, j, k;
int main(){
    scanf("%lld", &N);
    j = 0;
    fornum(i,0,N){
        scanf("%lld", &A[i]);
        j += A[i];
    }
    ans = j % 10 == 0 ? 0 : j;

    fornum(i,0,N){
        ans = max(ans, (j - A[i]) % 10 == 0 ? 0ll : j - A[i]);
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t MAX = 400010;
const int64_t MOD = 1000000007;

int64_t fac[MAX], finv[MAX], inv[MAX];

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

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

int main()
{
  COMinit();
  int64_t N, K;
  cin >> N >> K;
  if (K >= N - 1)
  {
    cout << COM(2 * N - 1, N) << endl;
  }
  else // K < N - 1 (max: ~200000)
  {
    int64_t ans = 1;
    for (int64_t i = 1; i <= K; i++)
    {
      ans = (ans + (COM(N, i) * COM(N - 1, i) % MOD)) % MOD;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 13020
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Maybe
import Data.Ord
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  x <- getInt
  p' <- getInt
  let p = fint p' / 100 :: R
  let ans = (fint $ (x+1)`div`2) / p
  print ans



type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "Yes"
yesNo False = "No"

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . unwords . map show

readLnList :: (Read a) => IO [a]
readLnList = map read . words <$> getLine


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


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


public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		boolean p[] = new boolean[1000000];
		Arrays.fill(p, true);
		p[0] = false;
		p[1] = false;
		for(int i = 0; i*i < 1000000 ; i++){
			if(p[i]){
				for(int j = i+i ; j < 1000000 ; j+=i){
					p[j] = false;
				}
			}
		}
		int s[] = new int[1000000];
		s[0] = 0;
		for(int i = 1 ;i <  1000000;i++){
			if(p[i]){
				s[i] = s[i-1]+1;
			}else{
				s[i] = s[i-1];
			}
		}
		
		for(;;){
			int n = sc.nextInt();
		      
			if(n == 0){
				break;
			}
				
			int sum = 0;
			for(int i = 0; i < n ; i++){
				int a = sc.nextInt();
				int b = sc.nextInt();
				
				int f = Math.max(a-b-1, 0);
				int g =Math.min(a+b, 1000000-1); 
				
				sum += Math.max(0,s[g]-s[f]) - 1;
			}
			System.out.println(sum);
		}
//		System.out.println(Arrays.toString(s));
	}

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

}

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

const long long INF = (long long) 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long k;
  cin >> n >> k;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> cyc = {1};
  int cur = a[1];
  map<int, int> mp;
  mp[1] = 0;
  int cnt = 0;
  while (!mp.count(cur)) {
    cyc.push_back(cur);
    mp[cur] = ++cnt;
    cur = a[cur];
  }
  if (k < mp[cur]) {
    cout << cyc[k] << '\n';
  } else {
    k -= mp[cur];
    cout << cyc[mp[cur] + k % ((int) cyc.size() - mp[cur])] << '\n';
  }
  return 0;
}

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

int main() {
int N,K;
  cin >> N >> K;
  vector<int>d(K);
  vector<int>B(N);
  int result = 0;
  vector<int>A(100);
  for(int a = 0;a < N;a++)B[a] = 0;
  for(int a = 0;a < K;a++){
   cin >> d[a];
    for(int b = 0;b < d[a];b++){
     cin >> A[b];
      B[A[b] - 1] = 1;
    }
  }
  for(int a = 0;a < N;a++){
   if(B[a] == 0)result++;
  }
  cout << result << endl;
}

Measured memory_bytes: 3636
import itertools
import numpy as np

N = int(input())
F = [0] * N
for i in range(N):
    F[i] = np.array([int(x) for x in input().split()])

P = [0] * N
for i in range(N):
    P[i] = np.array([int(x) for x in input().split()])

max_bene = -1e10
for p in itertools.product([0, 1], repeat=10):
    if sum(p) == 0:
        continue
    p = np.array(p)
    bene = 0
    for i in range(N):
        c = np.dot(F[i], p)
        bene += P[i][c]

    if bene > max_bene:
        max_bene = bene

print(max_bene)

Measured memory_bytes: 12436
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

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

    string A,B;
    cin>>A>>B;
    cout<<B<<A<<endl;

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


  
    return 0;
}

Measured memory_bytes: 256
X,N=list(map(int,input().split()))
if N>0:p=list(map(int,input().split()))
else:p=[]
memo=[False for i in range(105)]
for i in range(N):memo[p[i]]=True


riget=X+1
left=X-1
ans_r=0
ans_l=0

while(True):
    if memo[X]==False:
        ans_r=X
        break
    
    if memo[riget]==False:
        ans_r=riget
        break
    riget+=1
    
while(True):
    
    if memo[X]==False:
        ans_l=X
        break
    
    if memo[left]==False:
        ans_l=left
        break
    left-=1
    
if N==0:print(X)
elif abs(X-ans_r)>=abs(X-ans_l):print(ans_l)
else:print(ans_r)
    

Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int x,a,b;
    cin >> x >> a >> b;
    if(abs(x-a)>abs(x-b)){
        cout << 'B';
    }else{
        cout << 'A';
    }
    return 0;
}

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

using namespace std;

int main(){
  string x;
  cin >> x;
  int minus=0;
  int s_cnt=0, t_cnt=0;
  for(int i=0;i<x.length();i++){
    if(x[i]=='T'){
      while(i<x.length() && x[i]=='T'){
        t_cnt++;
        i++;
      }
      minus += 2*min(s_cnt, t_cnt);
      s_cnt=s_cnt - min(s_cnt, t_cnt)+1;t_cnt=0;
    }
    else{
      s_cnt++;
    }
  }
  cout << x.length() - minus  << endl;
}



Measured memory_bytes: 640
A, B, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(M)]
m = min(A) + min(B)
for i in X:
  x, y, c = i[0] - 1, i[1] - 1, i[2]
  if A[x] + B[y] - c < m:
    m = A[x] + B[y] - c
print(m)

Measured memory_bytes: 38488
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;


int main(void) {

    int N, M; cin>>N>>M;
    vector<int> ans(N+3,-1);


    vector<int> s(M);
    vector<int> c(M);
    for (int i = 0; i < M; ++i) {
        int S,C; cin>>S>>C;
        s[i]=S; c[i]=C;
        //左からs桁目
        if(ans[S-1]==-1 || ans[S-1]==C){
            ans[S-1] = C;
        }else{
            cout<<-1<<endl;
            return 0;
        }
    }

    for (int i = (N==1)?0:pow(10,N-1); i <= pow(10,N)-1; ++i) {
        string S = to_string(i);
        bool ok = false;
        if(M==0) ok = true;
        for (int j = 0; j < M; ++j) {
            if(S[s[j]-1]-'0'==c[j]) {
                ok = true;
            }else{
                ok = false;
                break;
            }
        }
        if(ok){
            cout<<i<<endl;
            return 0;
        }
    }

    cout<<-1<<endl;
    return 0;
}

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


int main(){
int n;
cin >> n;
ll ans, a;
set<ll>s;

for (int i = 0; i < n; i++)
{
    cin >> a;
    s.insert(a);
}
ans = *rbegin(s) - *begin(s);



cout << ans << endl;
}

Measured memory_bytes: 256
import math
def comb(n, r):
  if n-r>=0:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  else:
    return 0

n,k=map(int, input().split())
for i in range(1,k+1):
  print(comb(n-k+1,i)*comb(k-1,i-1)%(10**9+7))

Measured memory_bytes: 9324
#include<stdio.h>

int stackDeck[50], stackBufC[50], stackBufP[50];
int spDeck, spC, spP;

void DeckPush(int);
void BufCPush(int);
void BufPPush(int);
int DeckPop(void);
int BufCPop(void);
int BufPPop(void);

int main()
{
	int n, r, p, c;
	int i, j;
	
	while(1)
	{
		scanf("%d%d", &n, &r);
		
		if(n == 0 && r == 0) break;
		
		spDeck = spC = spP = -1;
		
		for(i = 0; i < n; i++)
		{
			stackDeck[i] = 0;
			stackBufC[i] = 0;
			stackBufP[i] = 0;
		}
		
		for(i = 0; i < n; i++)
		{
			DeckPush(i + 1);
		}
		
		for(i = 0; i < r; i++)
		{
			scanf("%d%d", &p, &c);
			
			for(j = 0; j < p - 1; j++)
			{
				BufPPush(DeckPop());
			}
			
			for(j = 0; j < c; j++)
			{
				BufCPush(DeckPop());
			}
			
			for(j = 0; j < p - 1; j++)
			{
				DeckPush(BufPPop());
			}
			
			for(j = 0; j < c; j++)
			{
				DeckPush(BufCPop());
			}
		}
		
		printf("%d\n", DeckPop());
	}
	
	return 0;
}

void DeckPush(int x)
{
	stackDeck[++spDeck] = x;
}

int DeckPop()
{
	return stackDeck[spDeck--];
}

void BufCPush(int x)
{
	stackBufC[++spC] = x;
}

int BufCPop()
{
	return stackBufC[spC--];
}

void BufPPush(int x)
{
	stackBufP[++spP] = x;
}

int BufPPop()
{
	return stackBufP[spP--];
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
constexpr long long MOD2 = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;



int n;

ull a[200019];

ull umin (ull a, ull b) {
    return (a < b) ? a : b;
}
ull umax (ull a, ull b) {
    return (a > b) ? a : b;
}

int main() {

    cin >> n;
    rep(i, n) cin >> a[i];


    ll i, j;
    ull res = 0;

    ull allxor = 0;
    for (i = 0; i < n; i++) {
        allxor ^= a[i];
    }
    for (i = 0; i < n; i++) {
        a[i] &= ~allxor; //interstingなbitだけ立たせる(最後に考慮)
    }

    //F2における掃き出し法
    ull rank = 0;
    for (i = 59; i >= 0; i--) {
        //i-bitが0でない最初の行j>=rankを探す　なかったら次のiへ
        for (j = rank; j < n; j++) {
            if (a[j] & (1 << i)) break;
        }
        if (j == n) continue;

        if (j > rank) a[rank] ^= a[j];  //a[rank] = a[rank] + a[j] in F2
        for (j = rank + 1; j < n; j++) {
            a[j] = min(a[j], a[j] ^ a[rank]);
        }

        rank++;
    }

    ull x = 0;
    for (i = 0; i < n; i++) { //高いbitが立ってる方からgreedyに
        x = max(x, x ^ a[i]);
    }

    res = (x * 2) + allxor;

    cout << res << endl;

}




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

int main() {
  int a[31]={};
  for(int i=0; i<31; i++) {
    if(i==0 || i==1) a[i]=1;
    else if(i==2) a[i]=2;
    else a[i]=a[i-1]+a[i-2]+a[i-3];
  }

  while(1){
    int n;
    cin >> n;
    if(n==0) break;
    cout << a[n]/10/365+1 <<endl;
  }
}


Measured memory_bytes: 1164
if __name__=='__main__':
    N = int(input())

    N_list = list(map(int, list(str(N))))
    if len(N_list) == 1:
        print(N_list[0])
    elif set(N_list[1:]) == {9}:
        print(sum(N_list))
    else:
        N_list[0] -= 1
        for i in range(1, len(N_list)):
            N_list[i] = 9
        print(sum(N_list))

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
static const int MAX=200000;

int main(){
    int R[MAX],n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>R[i];
    int maxv=-2000000000;
    int minv=R[0];
    for(int i=1;i<n;i++){
        maxv=max(maxv,R[i]-minv);
        minv=min(R[i],minv);
    }
    cout<<maxv<<endl;
    return 0;
}


Measured memory_bytes: 3892
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
using namespace std;

int main()
{
    string s;
    int K;
    cin >> s >> K;
    for(int tar = 0; tar <= s.size() - 1; tar++){
        if(s[tar] != 'a' && 'z' + 1 - s[tar] <= K){
            K -= 'z' + 1 - s[tar];
            s[tar] = 'a';
        }
    }
    K = K % 26;
    while(K > 0){
        if(s[s.size() - 1] == 'z'){
            s[s.size() - 1] = 'a';
            K--;
        }else{
            s[s.size() - 1]++;
            K--;
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 512
from math import factorial
from collections import Counter
def nCr(n,r):
    return factorial(n)//(factorial(r)*factorial(n-r))
N,P=map(int,input().split())
A=list(map(lambda x:int(x)%2,input().split()))
c=Counter(A)
z=pow(2,c.get(0,0))
res=0
for i in range(1 if P else 0,c.get(1,0)+1,2):
    res+=nCr(c.get(1,0),i)
print(z*res)

Measured memory_bytes: 3316
from functools import reduce
import fractions
import math
k=int(input())
m=0
for i in range(1,k+1):
    for j in range(i,k+1):
        for p in range(j,k+1):
            l=[i,j,p]
            if i==j==p:
                m+=reduce(math.gcd,l)
            elif (i==j and i!=p) or (i==p and i!=j) or (j==p and i!=p):
                m+=3*reduce(math.gcd,l)
            else:
                m+=6*reduce(math.gcd,l)
print(m)


Measured memory_bytes: 74292
#include<cstdio>
int main() {
	int n, i, j, minj;
	char c[36][3], d[36][3], tmp;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s", c[i]);
		for (j = 0; j < 3; j++)d[i][j] = c[i][j];
	}
	for (i = 0; i < n; i++) {
		for (j = n - 1; j > i; j--) {
			if (c[j][1] < c[j - 1][1]) {
				tmp = c[j][0];
				c[j][0] = c[j - 1][0];
				c[j - 1][0] = tmp;
				tmp = c[j][1];
				c[j][1] = c[j - 1][1];
				c[j - 1][1] = tmp;
			}
		}
	}
	printf("%s", c[0]);
	for (i = 1; i < n; i++)printf(" %s", c[i]);
	printf("\nStable\n");
	for (i = 0; i < n; i++) {
		minj = i;
		for (j = i; j < n; j++) {
			if (d[j][1] < d[minj][1])minj = j;
		}
		tmp = d[i][0];
		d[i][0] = d[minj][0];
		d[minj][0] = tmp;
		tmp = d[i][1];
		d[i][1] = d[minj][1];
		d[minj][1] = tmp;
	}
	printf("%s", d[0]);
	for (i = 1; i < n; i++)printf(" %s", d[i]);
	for (i = 0; i < n; i++) {
		for (j = 0; j < 2; j++) {
			if (c[i][j] != d[i][j]) {
				printf("\nNot stable\n");
				return 0;
			}
		}
	}
	printf("\nStable\n");
	return 0;
}


Measured memory_bytes: 2728
#include<bits/stdc++.h>
#define mp make_pair
#define fs first
#define sc second
#define pb push_back
#define mod 1000000007
using namespace std;
 
int n,k;
int match[610];
long long f[610];
long long dp[610][610];
long long dp2[610][610];
long long cnt[610][610];

long long solve(int l, int r){
	if(dp[l][r] != -1) return dp[l][r];
	if((r - l) % 2 == 0) return 0;

	long long ans = 0;
	cnt[l][r] = r - l + 1;

	for(int i = l; i <= r; i++){
		if(match[i] != -1){
			int v = match[i];
			if(v >= l && v <= r){
				cnt[l][r]--;
			} else {
				return dp[l][r] = 0;
			}
		}
	}
	// assert(cnt[l][r] % 2 == 0);
	
	ans = f[cnt[l][r]];
	return (dp[l][r] = ans);
}

long long solve2(int l, int r){
	if(dp2[l][r] != -1) return dp2[l][r];

	if((r - l) % 2 == 0) return 0;

	long long ans = solve(l, r);
	for(int i = l; i < r; i++){
		long long ini = (solve2(l, i) * solve(i + 1, r)) % mod;
		ans = (ans + mod - ini) % mod;
	}
	return (dp2[l][r] = ans);
}


int main(){
	cin >> n >> k;

	n *= 2;
	int aktif = n - 2 * k;
	memset(match, -1, sizeof(match));
	for(int i = 1; i <= k; i++){
		int u,v; cin >> u >> v;
		match[u] = v;
		match[v] = u;
	}

	memset(f, 0, sizeof(f));
	f[0] = 1;
	for(int i = 2; i <= n; i++){
		f[i] = (f[i - 2] * (i - 1)) % mod;
	}

	memset(dp, -1, sizeof(dp));
	memset(dp2, -1, sizeof(dp2));

	long long ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = i + 1; j <= n; j++){
			if((j + i) % 2 == 0) continue;

			solve(i, j);
			long long x = (solve2(i, j) * f[aktif - cnt[i][j]]) % mod;
			ans = (ans + x) % mod;
		}
	}

	cout << ans << "\n";

} 

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

using namespace std;

#define ff first
#define ss second
#define int long long
#define pii pair<int,int>
#define mp make_pair

int memo[100000],v[100000],k;

int calcpulo(int id){
	if(memo[id]==INT_MAX){
		int menor,i,calc,aux;
		for(i=0;i<k;i++){
			calc=id-k+i;
			if(calc>=0){
				menor=calcpulo(calc);
				aux=abs(v[id]-v[calc])+menor;
				if(memo[id]>aux)memo[id]=aux;
			}		
		}
	}
	return memo[id];	
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,i;
	cin>>n>>k;
	for(i=0;i<n;i++)cin>>v[i];
	memo[0]=0;
	for(i=1;i<n;i++){
		memo[i]=INT_MAX;
	}
	cout<<calcpulo(n-1)<<endl;	
}

Measured memory_bytes: 4992
using System;

class B
{
	static void Main()
	{
		var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int n = h[0], k = h[1];

		var p = 0;
		for (long x = 1; x <= n; x *= k, p++) ;
		Console.WriteLine(p);
	}
}


Measured memory_bytes: 27308
//作者：中国江苏省南京市李硕睿
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
const int MAXN=55;
long long dp[MAXN][2];
int n,p,a[MAXN];
int main(){
	cin>>n>>p;
	for (int i=1;i<=n;++i){
		cin>>a[i];
	}
	dp[0][0]=1;
	for (int i=1;i<=n;++i){
		dp[i][0]+=dp[i-1][0];
		dp[i][1]+=dp[i-1][1];
		if ((a[i]&1)==0){
			dp[i][0]+=dp[i-1][0];
			dp[i][1]+=dp[i-1][1];
		}else{
			dp[i][0]+=dp[i-1][1];
			dp[i][1]+=dp[i-1][0];
		}
	}
	cout<<dp[n][p]<<endl;
	return 0;
}

Measured memory_bytes: 256
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
   	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}

int main()
{
	fast();
	ll n,ans=0,i,j,k;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			for(k=1;k<=n;k++)
			{
				ll temp=__gcd(i,j);
				temp=__gcd(temp,k);
				ans+=temp;
			}
		}
	}
	cout<<ans;
}

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

namespace ConsoleApplication82
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            Console.WriteLine("ABC{0}", a);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int N; cin >> N;
const int n = N;
VI A(N); 
VVI x(N, VI(N)), y(N, VI(N));
rep(i, 0, N) {
    cin >> A[i];
    rep(j, 0, A[i]) cin >> x[i][j] >> y[i][j];
}
int maxi = 0;

rep(bit, 0, 1<<N){ //親切と仮定する人は1
    bool contradiction = true;
    rep(i, 0, N){
        if (bit & (1<<i)){
            rep(j, 0, A[i]){
                if ((bool)(bit & (1<<(x[i][j]-1))) != y[i][j]) {
                    contradiction = false;
                    break;
                }
            }
            if (!contradiction) break;
        }
    }
    if (contradiction) {
        maxi = max(maxi, (int)bitset<15>(bit).count());
    }
}
cout << maxi << endl;
}

// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<cstdio>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long LL;

const int mod=1e9+7;

int a[1010],num;
LL bit[1010];

bool isprime(int x){
    if(x==1) return false;
    int q=sqrt(x);
    for(int i=2;i<=q;i++)
        if(x%i==0) return false;
    return true;
}

void init(){
    num=0;
    for(int i=1;i<=1000;i++)
        if(isprime(i)) a[num++]=i;
}

void solve(int n){
    for(int i=0;i<num;i++){
        if(n%a[i]) continue;
        while(n%a[i]==0){
            bit[i]++;
            n/=a[i];
        }
    }
}

int main()
{
    int n;
    scanf("%d",&n);
    if(n==1){
        puts("1");
        return 0;
    }
    init();
    for(int i=0;i<num;i++)
        bit[i]=1;
    for(int i=2;i<=n;i++){
        solve(i);
    }
    LL ans=1;
    for(int i=0;i<num;i++){
        ans=ans*bit[i]%mod;
    }
    printf("%lld\n",ans);
    return 0;
}




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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef pair<int, int> i_i;

const int MOD = 1e9 + 7;
const ll INF = LLONG_MAX / 2;

int main() {
	ll x = 1;
	int t;
	for (t = 0; t < 12; t++) {
		cout << "? " << x << endl;
		string ans; cin >> ans;
		if (ans == "N") break;
		x = x * 10;
	}
	if (t == 12) {
		for (t = 12; t >= 1; t--) {
			cout << "? " << string(t, '9') << endl;
			string ans; cin >> ans;
			if (ans == "N") { t++; break; };
		}
		if (!t) t = 1;
	}
	string pre;
	while (t--) {
		int lb = -1, ub = 9;
		while (ub - lb > 1) {
			int mid = (lb + ub) / 2;
			string s = pre;
			s.pb('0' + mid);
			while (s.size() < 16) s.pb('9');
			if (s[0] == '0') {
				lb = mid;
				continue;
			}
			cout << "? " << s << endl;
			string ans; cin >> ans;
			if (ans == "Y") ub = mid;
			if (ans == "N") lb = mid;
		}
		pre.pb('0' + ub);
	}
	cout << "! " << pre << endl;
}


Measured memory_bytes: 652
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int page;
        
        if(N%2 == 0){
            page = N/2;
        } else {
            page = N/2+1;
        }
        System.out.println(page);
        
    }
}


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

const int MOD=1000000007;
//~ const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int dp[300000][2];
int prv[300000][2];

int main(){
	string s;cin>>s;
	memset(dp,-1,sizeof(dp));
	dp[0][1]=0;
	rep(i,s.size())rep(j,2){
		if(dp[i][j]==-1)continue;
		rep(k,2){
			if(s[i]!='?'&&((s[i]=='P'&&k==1)||(s[i]=='D'&&k==0)))continue;
			int cost=dp[i][j]+(j==0&&k==1)+(k==1);
			if(dp[i+1][k]<cost){
				dp[i+1][k]=cost;
				prv[i+1][k]=j;
			}
		}
	}
	int x=s.size(),y=(dp[s.size()][0]>dp[s.size()][1]?0:1);
	string ans;
	while(x){
		if(y==0)ans+='P';
		else ans+='D';
		y=prv[x][y];
		x--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}

Measured memory_bytes: 7700
import java.io.*;

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

      BufferedReader br =
       new BufferedReader(new InputStreamReader(System.in));

      String str1 = br.readLine();
      String str2[] = str1.split(" ");
      int a = Integer.parseInt(str2[0]);
      int b = Integer.parseInt(str2[1]);
      int c = a*b;
      int d = 2*(a+b);
      System.out.println( c + " " + d );

   }
}

Measured memory_bytes: 24000
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int N = str.length();

        if (str.substring(0,(N-1)/2).equals(str.substring(((N+3)/2)-1))) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
/*ll divr[maxn];
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
*/















int ct[100005][2];
int main()
{
    int n,k;cin>>n>>k;
    map<int,int> mp;
    int a[n];
    for(int i=0;i<n;i++){
         cin>>a[i];mp[a[i]]++;
    }
    if(mp.size()<=k)cout<<0;
    else
    {
         vector<int> vec;
         for(auto it:mp)vec.push_back(it.second);
         sort(vec.begin(),vec.end());
         int t=mp.size();
         int ans=0;
         for(int i=0;i<vec.size()&&t>k;i++)
         {
              ans+=vec[i];
              t--;
         }
         cout<<ans;
    }
}
























 

Measured memory_bytes: 11516
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef ONLINE_JUDGE
const int N = 1e6+50;
#else
const int N = 1e2+10;
#endif


ll q,h,s,d,n;
ll a[55];

int main() {
	cin>>q>>h>>s>>d>>n;
	n *= 4;
	memset(a,0x3f,sizeof a);
	a[0] = 0;
	a[1] = q;
	a[2] = h;
	a[4] = s;
	a[8] = d;
	REP(i,1,8) REP(j,1,8) {
		a[i+j] = min(a[i+j],a[i]+a[j]);
	}
	printf("%lld\n",n/8*a[8]+a[n%8]);
}








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


int main(){
	int n;
	while(cin>>n,n){
		string tmp,TMP,TMP2;
		int m,d,res,res2;
		int date[21][31]={0};
		int point[31]={0};
		int get[21]={0};
		map<string,int>name;
		
		for(int i=1;i<=n;i++){
			cin>>tmp>>m;
			name[tmp]=i;
			for(int j=0;j<m;j++){
				cin>>d;
				date[i][d]=1;
				if(point[d]==0)point[d]=n+1;
				point[d]--;
			}
		}
		
		for(int i=1;i<=20;i++)for(int j=0;j<=30;j++)if(date[i][j]==1)get[i]+=point[j];
		map<string, int>::iterator it = name.begin();
		res2=get[(*it).second ];
		TMP2=(*it).first;
		while( it != name.end() ){
			res=get[(*it).second ];
			TMP=(*it).first;
			//cout<<get[(*it).second ]<<"*"<<(*it).first<<endl;
			if(res2>res){
				res2=res;
				TMP2=TMP;
				//cout<<"#"<<res2<<" "<<TMP2<<endl;
			}
			++it;
		}
		cout<<res2<<" "<<TMP2<<endl;
		
	}
	return 0;
}


Measured memory_bytes: 1216
#include <stdio.h>

int main(){

  int i,j,n,A[100000],temp,p,par;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  p = 0;
  i = p-1;

  for(j=p;j<n-1;j++){
    if(A[j] <= A[n-1]){
      i = i+1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[n-1];
  A[n-1] = temp;

  par = i+1;

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

  if(n-1 == par){
      printf("[%d]\n",A[n-1]);
    }else{
      printf("%d\n",A[n-1]);
  }
  return 0;
}
 

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

int main(){

int n;cin>>n;
int a[n];
for(int i=0;i<n;i++)
	cin>>a[i];
int count=0;
for(int i=1;i<n-1;i++)
{
	int ar[3];
	for(int j=0;j<3;j++)
		ar[j]=a[i-1+j];
	sort(ar,ar+3);
	if(a[i]==ar[1] and a[i]>ar[0])
		count++;
}
cout<<count;


	
return 0;
}


Measured memory_bytes: 256