akhauriyash/Code-Regression huggingface dataset:
package main

import (
        "bufio"
        "fmt"
        "os"
        "sort"
        "strconv"
        "strings"
)

func solution(n int, p, q []int) int {
        i := dictionaryOrder(p)
        j := dictionaryOrder(q)
        return abs(i, j)
}

func abs(x, y int) int {
        z := x - y
        if z < 0 {
                return z * -1
        }
        return z
}

func dictionaryOrder(nums []int) int {
        var ans int
        l := len(nums)
        for i := 0; i < l; i++ {
                n := nums[i]
                arr := make([]int, len(nums)-i)
                copy(arr, nums[i:])
                a := ascNumber(arr, n) - 1
                if a == 0 {
                        ans += 0
                } else {
                        ans += a * factorical(l-i-1)
                }
        }
        ans++
        return ans
}

func ascNumber(nums []int, n int) int {
        sort.Ints(nums)
        var i int = 1
        for _, v := range nums {
                if v == n {
                        break
                }
                i++
        }
        return i
}

func factorical(n int) int {
        if n == 0 || n == 1 {
                return 1
        }
        return n * factorical(n-1)
}

func main() {

        var n int
        fmt.Scan(&n)
        reader := bufio.NewReaderSize(os.Stdin, 10240*10240)
        p := make([]int, n)
        ss := strings.Split(readLine(reader), " ")
        for i := range ss {
                p[i], _ = strconv.Atoi(ss[i])
        }
        q := make([]int, n)
        ss = strings.Split(readLine(reader), " ")
        for i := range ss {
                q[i], _ = strconv.Atoi(ss[i])
        }
        fmt.Println(solution(n, p, q))
}

func readLine(reader *bufio.Reader) string {
        str, _, _ := reader.ReadLine()
        return strings.TrimRight(string(str), "\r\n")
}

Measured memory_bytes: 3968
#define M 99999
T[M],t[M];main(i,j,m,a,b,p,q){
for(i=2;i<M;i++)if(!T[i])for(j=i*2;j<M;j+=i)T[j]=1;
for(i=2,j=1;i<M;i++)if(!T[i])t[j++]=i;
for(;scanf("%d%d%d",&m,&a,&b),m;printf("%d %d\n",p,q))for(i=1;;i++)if(t[i]*t[i]>m)i=0,m--;else if(!T[q=m/t[i]]&&(p=t[i])*q==m&&a*q<=b*p)break;
exit(0);}

Measured memory_bytes: 1024
#include <iostream>
#include <string>

int main(int argc, char const* argv[])
{
	std::string s;
	std::string p;
	int p_str_size;

	std::cin >> s >> p;
	std::string s2 = s + s;
	p_str_size = p.size();

	for (size_t i = 0; i < s2.size() - p_str_size; i++)
		if(s2.compare(i, p_str_size, p) == 0)
		{
			std::cout << "Yes" << std::endl;
			return 0;
		}

	std::cout << "No" << std::endl;
	return 0;
}

Measured memory_bytes: 1192
/**
 *  author: Behradm
 *  Created: 2020.08.02 15:53:21
 *  In The Name Of God
**/
#include <bits/stdc++.h>

using namespace std;

int main() {   
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  long long res = n - 1;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0)
      res = min(res, i + n / i - 2);
  }

  /*long long res = n - 1;
  for (int i = 0; i < (int) d.size(); i++) {
    for (int j = i + 1; j < (int) d.size(); j++) {
      res = min(res, (d[i] * d[j] == n ? d[i] + d[j] - 2 : res));
    }
  }*/

  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  char pre = s[0];
  for(int i=1;i<n;i++){
    if(pre!=s[i]){
      ans++;
      pre = s[i];
    }
  }
  ans++;
  cout << ans << endl;
}

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


int main() {

  long long n;
  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 = 1; i < n; i++) {
    int tmp = i - 1;
    if(a.at(tmp) == a.at(i)) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 1024
n = int(input())
li1 = list(range(1, n+1, 2))
li2 = list(range(1, n+1, 1))
count = 0
ans = 0
for i in li1:
    for j in li2:
        if i % j == 0:
            count += 1
    if count == 8:
        ans += 1
    count = 0
print(ans)


Measured memory_bytes: 38768
import java.util.*;
import java.util.function.*;
import java.lang.*;
import java.io.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int N = sc.nextInt();
        Set<Integer> p = new HashSet<>();
        for(int n=0; n<N; n++) p.add(sc.nextInt());
        
        for(int d=0; d<100000; d++){
            if(!p.contains(X-d)){
                System.out.println(X-d);
                break;
            }
            if(!p.contains(X+d)){
                System.out.println(X+d);
                break;
            }
        }
    }
}

Measured memory_bytes: 35860
function Main(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  var N=input.shift();
  var n=Math.max.apply(null,input);
  while(input.indexOf(n)>=0)input[input.indexOf(n)]=Infinity;
  var r=input[input.map(x=>Math.abs(x-n/2)).indexOf(Math.min.apply(null,input.map(x=>Math.abs(x-n/2))))];
  console.log(n+' '+r);
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));

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

int main() {
  string s;
  cin >> s;
  int x =0;
  for(int i = 0;i<4;i++){
    if(s.at(i) == '+'){
      x++;
    }
    else {
      x--;
    }
  }
  cout << x << endl;
}


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

int main() {
    
    int n, k;
    int ans = 0;
    
    cin >> n >> k;
    
    for(int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        ans += 2 * min(x, k - x);
    }
    
    cout << ans;
    
    return 0;
}

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

int main(){
	int a, b;
  	cin >> a >> b;
  	
  	int ans = (a-2*b >= 0) ? a-2*b : 0;
  	cout << ans << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h> 
using namespace std; 
#define LL long long int
struct Node
{
    LL index;
    LL val;
};
int main() 
{ 

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    LL N;
    cin>>N;
    if(N%1000==0)
        cout<<0;
    else
    cout<< (1000)-(N%1000);
}

Measured memory_bytes: 3632
N = int(input())
T, A = [int(n) for n in input().split()]
H = [int(n) for n in input().split()]

def main():
    h = list(map(lambda n: abs(A - (T - n * 0.006)), H))
    print(h.index(min(h)) + 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import math
N, D = map(int, input().split())
points = [[int(i) for i in input().split()] for _ in range(N)]


def calc_distance(p_a, p_b):
    i = 0
    for a, b in zip(p_a, p_b):
        i += (a - b) ** 2
    return math.sqrt(i)


ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if calc_distance(points[i], points[j]).is_integer():
            ans += 1
print(ans)


Measured memory_bytes: 3064
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll m = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

ll f[2000010];

ll lcm(ll a,ll b)
{
  return (a*b)/__gcd(a,b);
}
ll binpow(ll a, ll b) {
     ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
 
ll find_ncr(ll n, ll r)
{
    ll m1=max(r,n-r);
    ll i,j,s,d=1,k;
    s=1;
 
    for(i=m1+1;i<=n;i++)
    {
        s=((s%m)*(i%m))%m;
    }
 
    m1=min(r,n-r);
 
    for(i=1;i<=m1;i++)
    {
        k=binpow(i,m-2);
        d=((d%m)*(k%m))%m;
    }
 
    k=(s%m*(d%m))%m;
 
    return k;
}

int main()
{
  // int x = -1, y = 10000;
  // double z = 0.2;
  // string s2 = "beginner1010";
  // long long b = 1LL << 60;
    
  // // debug(x, y, z, s, b);
    
  // double aux = 1010.0;
  // string code = "code";
    
  // debug(code + "forces",-aux / 10 * 2.3);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  set<string>s;
  while(n--)
  {
    string k;
    cin >> k;
    s.insert(k);
  }
  cout << s.size();
  return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

int main() {
    string s;
    cin >> s;
    li yyyy = atoi(s.substr(0, 4).c_str());
    li mm = atoi(s.substr(5, 2).c_str());
    li dd = atoi(s.substr(8, 2).c_str());
    tuple<li, li, li> tmp{yyyy, mm, dd};
    tuple<li, li, li> d{2019, 4, 30};
    cout << (tmp <= d ? "Heisei" : "TBD") << endl;
    return 0;
}

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

typedef long long ll;

string A, B, C;

int main() {
    cin >> A >> B >> C;

    string tmp;
    int ans = 0;
    if (A >= B && A >= C) {
        tmp = A + B;
        ans = stoi(tmp) + stoi(C);
    } else if (B >= A && B >= C) {
        tmp = B + A;
        ans = stoi(tmp) + stoi(C);
    } else {
        tmp = C + A;
        ans = stoi(tmp) + stoi(B);
    }

    cout << ans << endl;
}

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

int main() {
    int n,m;
    cin >> n;
    vector<string> s(n), t(m);
    rep(i,n){
        cin >> s.at(i);
    }
    cin >> m;
    rep(i,m){
        cin >> t.at(i);
    }
    int ans;
    rep(i,n){
        int count = 0;
        rep(k,n){
            if (s[i]==s[k]){
                count++;
            }
        }
        rep(j,m){
            if (s[i]==t[j]){
                count--;
            }
        }
        if (i == 0){
            ans = count;
        }
        else {
            if (count > ans){
                ans = count;
            }
        }
    }
    if (ans < 0){
        ans = 0;
    }
    cout << ans << endl;
}



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

int main(){
	int n, k;
	std::cin >> n >> k;
	int len = 0;
	std::vector<int> l(n);
	for(int i = 0; i < n; ++i){
		std::cin >> l.at(i);
	}

	std::sort(std::begin(l), std::end(l), std::greater<int>());
	for(int i = 0; i < k; ++i){
		len += l.at(i);
	}

	std::cout << len << std::endl;

	return 0;
}


Measured memory_bytes: 256
inf = 2019
L, R = map(int, input().split())
ans = 0
df = R - L
if df < 2019:
    L = L % inf
    R = L + df
    ans = 2019
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            tmp = int((i * j) % inf)
            ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<cstdlib>

using namespace std;

int calcm(int n, int k) {
   int sho = n/(k-1);
   int amari = n%(k-1);
   int ans = 0;
   if (amari == 0) ans = sho;
   else ans = sho + 1;
   return ans;
}

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

   int ans = N;

   for (int k = 0; k < K; k++) {
      int current = calcm(x - k, K) + calcm(N - x - K + k, K) + 1;
      if (current < ans) ans = current;
   }

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


Measured memory_bytes: 640
#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 ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    string s;
    cin >> s;
    if(s=="ABC")cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int count1[110];
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		int c;
		cin >> c;
		for (int j = 0; j < c; j++) {
			int p;
			cin >> p;
			count1[p]++;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (!count1[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {
  ll n,k;
  	ci(n>>k);
  vll A(n);
  vll B(n);
  FOR(i,0,n){
	ci(A[i]); 
  }
  
  SORT(A);
  ll count=1;//何個あるか
  ll kind=1;//何種類あるか
  
  FOR(i,1,n){
    if(A[i-1]==A[i]){
		count++;
    }
    else{
      B[i-1]=count;
      kind++;
      count=1;
    }
  }
    B[n-1]=count;
    SORT(B);
    ll ans=0;

      FOR(i,0,n){
		if(B[i]==0){
          ans+=B[i];
        }
        else{
          ans+=B[i];
          kind--;
        }
        if(kind<=k){
          break;
        }        
    }
      co(ans)
    }

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

using namespace std;
#define ll long long
#define ld long double

int h, w;
bool grid[20][20];
int dist[20][20];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int bfs(int x, int y) {
	int res = 0;
	queue<pair<int, int> > que;
	que.push({x, y});
	while(que.size()) {
		pair<int, int> start;
		start = que.front();
		que.pop();
		int start1 = start.first, start2 = start.second;
		for(int i=0;i<4;i++) {
			int newX = start1 + dx[i];
			int newY = start2 + dy[i];
			if(newX < 0 || newX >= h || newY < 0 || newY >= w) continue;
			if(!grid[newX][newY]) continue;
			if(dist[newX][newY] != -1) continue;
			dist[newX][newY] = dist[start1][start2] + 1;
			que.push({newX, newY});
			res = max(res, dist[newX][newY]);
		}
	}
	return res;
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    cin >> h >> w;
    for(int i=0;i<h;i++) {
    	for(int j=0;j<w;j++) {
    		char c;
    		cin >> c;
    		grid[i][j] = c == '.';
    	}
    }
    int ans = 0;
    for(int i=0;i<h;i++) {
    	for(int j=0;j<w;j++) {
    		if(!grid[i][j]) continue;
    		for(int i2=0;i2<h;i2++) {
    			for(int j2=0;j2<w;j2++) {
    				dist[i2][j2] = -1;
    			}
    		}
    		dist[i][j] = 0;
    		ans = max(ans, bfs(i, j));
    	}
    }
    cout << ans << '\n';
    return 0;
}


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

int main(void)
{
    int N;
    cin >> N;
    map<string, int> S;
    int currentMax = 0;
    for (int i = 0; i < N; i++) {
        string tmp;
        cin >> tmp;
        S[tmp]++;
        if (currentMax < S[tmp]) {
            currentMax = S[tmp];
        }
    }
    // cout << currentMax << endl;
    vector<string> ans;
    for (auto it = S.begin(); it != S.end(); it++) {
        if (it->second == currentMax) {
            cout << it->first << endl;
        }
    }
}


Measured memory_bytes: 25216
// AOJ 2873 Censored String
// 2019.3.23 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//// 高速入力処理
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()  // 非負整数の入力
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int ins(char *s)  // 文字列の入力　スペース以下の文字で入力終了
{
	char *p = s;
	do *s = gc();
	while (*s++ > ' ');
	*--s = 0;
	return s - p;
}

#define MARK (1<<30)
#define MASK (MARK-1)
#define MAX  100005
#define TMAX 500005
typedef struct { signed char ch; int bro, son; } T;  // 文字、兄弟、子供
T t[TMAX + 5]; int sz = 2;
int tbl[27][27][27][27];
char str[MAX], *S;
char buf[MAX];

void setup(int w, char *s)
{
	int i, node, f[4];

	f[1] = f[2] = f[3] = 0;
	for (i = 0; i < 4 && i < w; i++) f[i] = s[i] - 'a' + 1;
	if (w <= 4) {
		tbl[f[0]][f[1]][f[2]][f[3]] |= MARK;
		return;
	}
	if (((node = tbl[f[0]][f[1]][f[2]][f[3]]) & MASK) == 0) {
		tbl[f[0]][f[1]][f[2]][f[3]] |= sz;
		node = sz++;
	}
	node &= MASK;
	s += 4; while (*s) {
		int c = t[node].ch;
		if (c < 0) return;
		if (c == *s) {
			if (t[node].son == 0) t[node].son = sz, node = sz++;
			else node = t[node].son;
			s++;
		}
		else if (c > 0) {
			if (t[node].bro == 0) t[node].bro = sz, node = sz++;
			else node = t[node].bro;
		}
		else {
			t[node].ch = *s++, t[node].son = sz, node = sz++;
		}
	}
	t[node].ch = -1;
}

int resolv()
{
	int i, node, f[4];

	f[1] = f[2] = f[3] = 0;
	for (i = 0; i < 4 && *S; i++) {
		f[i] = *S++ - 'a' + 1;
		if (tbl[f[0]][f[1]][f[2]][f[3]] & MARK) return 1;
	}
	node = tbl[f[0]][f[1]][f[2]][f[3]] & MASK;
	while (*S) {
		int c = t[node].ch;
		if (c < 0) return 1;
		if (c == *S) node = t[node].son, S++;
		else if (c > 0) node = t[node].bro;
		else break;
	}
	return 0;
}

int main()
{
	int i, N, ans;
	char *p, *min, *end;

	end = str + ins(str) + 1;
	N = in(); for (i = 0; i < N; i++) {
		int w = ins(buf);
		setup(w, buf);
	}

	ans = 0, S = str, min = end;
	while (1) {
		if (S >= min) ans++, min = end;
		if (*S == 0) break;
		p = S;
		if (resolv()) {	if (S < min) min = S; }
		S = p + 1;  
	}
	printf("%d\n", ans);
	return 0;
}


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

public class ABC
{




    public static void Main()
    {
        int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = nm[0];
        int m = nm[1];
        int[] result = new int[m+1];

        for (int i = 0; i < n; i++)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int j = 1; j < input.Length; j++)
            {
                result[input[j]]++;
            }
        }
        Console.WriteLine(result.Where(x => x == n).Count());


    }
}



Measured memory_bytes: 13396
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String A = sc.next();
    String B = sc.next();
    String C = sc.next();
    char[] a = A.toCharArray();
    char[] b = B.toCharArray();
    char[] c = C.toCharArray();
    
    int aa = 0;
    int bb = 0;
    int cc = 0;
    char next = a[0];
    while(true){
      if(next == 'a'){
        aa++;
        if(aa == a.length){
          System.out.println("A");
          return;
        }else{
          next = a[aa];
        }
      }else if(next == 'b'){
        if(bb == 0){
          if(bb == b.length){
            System.out.println("B");
            return;
          }else{
            next = b[0];
            bb++;
          }
        }else{
          if(bb == b.length){
             System.out.println("B");
             return;
          }else{
            next = b[bb];
            bb++;
        }
       }
      }else if(next == 'c'){
        if(cc == 0){
          if(cc == c.length){
            System.out.println("C");
            return;
          }else{
            next = c[0];
            cc++;
          }
        }else{
          if(cc == c.length){
             System.out.println("C");
             return;
          }else{
            next = c[cc];
            cc++;
        }
       }
      }
    }
    
  }  
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
int main(){

  char s[2000000];
  char t[2000000];
  cin >>s >>t;
int ans = 0;
int size =strlen(s);
  
for(int i=0;i<size;i++){
if(s[i] != t[i]){ans +=1;}
else {continue;}
}
cout << ans <<endl;
     return 0;
}

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

bool first[10];
bool second[10][10];
bool third[10][10][10];

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

    int N;
    string S;
    cin >> N;
    cin >> S;
    int64_t cnt = 0;
    for (int i = 0; i < S.size(); i++) {
        if (first[S[i] - '0']) continue;
        first[S[i] - '0'] = true;
        for (int j = i + 1; j < S.size(); j++) {
            if (second[S[i] - '0'][S[j] - '0']) continue;
            second[S[i] - '0'][S[j] - '0'] = true;
            for (int k = j + 1; k < S.size(); k++) {
                if (third[S[i] - '0'][S[j] - '0'][S[k] - '0']) continue;
                third[S[i] - '0'][S[j] - '0'][S[k] - '0'] = true;
                cnt++;
            } 
        }
    }
    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main
{

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = in.readLine()) != null)
		{
			line=line.trim();
			StringTokenizer st = new StringTokenizer(line);
			long a = Integer.parseInt(st.nextToken());
			long b = Integer.parseInt(st.nextToken());
			System.out.println(gcd(a,b)+" "+lcm(a,b));
		}

	}
	
	public static long gcd(long a, long b)
	{
		if (a>=b) 
		{
			while (b!=0) 
			{
				long temp = b;
				b = a % b;
				a = temp;
			}
			return a;			

		}
		else return gcd(b,a);
	}
	
	public static long lcm(long a, long b)
	{
		long multiple = Math.abs(a*b);
		return multiple/gcd(a,b);
	}

}

Measured memory_bytes: 24164
from sys import stdin

def main():
    N, A, B, C, D = map(int, input().split())
    S = input()

    sunuke = S[A-1:C]
    funuke = S[B-1:D]
    if '##' in sunuke or '##' in funuke:
        print('No')
        return

    ans = 'No'
    if C < D:
        ans = 'Yes'
    else:
        if '...' in funuke:
            ans = 'Yes'
        else:
            sunuke1 = S[A-1:B-1] + '#' + S[B:C]
            sunuke2 = S[A-1:D-1] + '#' + S[D:C]
            if '##' not in sunuke1 or '##' not in sunuke2:
                ans = 'Yes'
    print(ans)

input = lambda: stdin.readline()
main()


Measured memory_bytes: 4092
#include<iostream>
#include<cstdio>
using namespace std;
const int N=10010;
int res;
bool is_prime(int x)
{
    if(x==1)return false;
    for(int i=2;i<=x/i;i++)
        if(x%i==0)return false;
    return true;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int x;
        scanf("%d",&x);
        if(is_prime(x))res++;
    }
    printf("%d\n",res);
}


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

int main() 
{ 
    int n, big = 0;
    cin >> n;
    string aux;
    map <string,int> freq;
    while(n--)
    {
        cin >> aux;
        if(freq.find(aux) == freq.end())
        {
            freq[aux] = 1;
        }
        else
        {
            freq[aux]++;
        }
        big = max(big,freq[aux]);        
    }
    for(map<string,int>::iterator it = freq.begin(); it != freq.end(); ++it)
    {
        if(it->second == big)
        {
            cout << it->first << endl;
        }
    }
    
    return 0;
} 

Measured memory_bytes: 25216
import collections
S_print = []
N=int(input())
S=[input() for i in range(N)]
S = collections.Counter(S)

S_common = S.most_common()

for i in range(len(S_common)):
	if S_common[0][1] == S_common[i][1]:
		S_print.append(S_common[i][0])

S_print_new = sorted(S_print)
#print(S_print_new)
for i in range(len(S_print_new)):
	print(S_print_new[i])

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

namespace ABC055B___Training_Camp
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            decimal power = 1;
            decimal result = power % (decimal)(Math.Pow(10, 9) + 7);

            for (int index = 1; index <= n; index++)
            {
                //power = power * index;
                result = result*index % (decimal)(Math.Pow(10, 9) + 7);


            }

            //decimal result = power % (decimal)(Math.Pow(10, 9) + 7);

            Console.WriteLine(result);

        }
    }
}


Measured memory_bytes: 11092
N = int(input())
if N == 1:
    print(0)
else:
    a = 1
    b = 2
    c = 1
    for _ in range(N):
        a *= 10
        b *= 9
        c *= 8
        a %= (10**9 + 7)
        b %= (10**9 + 7)
        c %= (10**9 + 7)
    print((a - b + c)%(10**9 + 7))

Measured memory_bytes: 9140
#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(){
  int k;
  cin >> k;
  queue<ll> q;
  rep2(i, 1, 10){
    q.push(i);
  }
  while(1){
    k--;
    ll now = q.front(); q.pop();
    if(k == 0){
      cout << now << endl;
      return 0;
    }
    int m = now % 10;
    now *= 10;
    if(m != 0){
      q.push(now + m - 1);
    }
    q.push(now + m);
    if(m != 9){
      q.push(now + m + 1);
    }
  }
  return 0;
}

Measured memory_bytes: 5104
N = int(input())
def sieve(n):
    num = [True]*n
    num[0]=num[1]= False
    for i in range(int(n**0.5)+1):
        if num[i]:
            for j in range(i**2,n,i):
                num[j] = False
    return ([i for i in range(2,n) if num[i]])
s = sieve(100)
fact = [[i,0] for i in s]
for i in range(2,N+1):
    j = i
    for m in range(len(s)):
        if j == 1:
            break
        while j % s[m] == 0:
            j = j // s[m]
            fact[m][1] += 1

factor_num = [i[1] for i in fact]
def multi_index(l, x): # l中のxのindexのlistを返す
    return [i for i, _x in enumerate(l) if _x >= x]
n75 = 0
if sum([1 for i in factor_num if i >= 4]) >= 2:
    over4 = multi_index(factor_num,4)
    over2 = multi_index(factor_num,2)
    for i in range(len(over4)):
        for j in range(i,len(over4)):
            for k in range(len(over2)):
                if i!=j and over4[i]!=over2[k] and over4[j]!=over2[k]:
                    n75 += 1
    try:
        over24 = multi_index(factor_num,24)
        for i in over24:
            for j in over2:
                if i!= j:
                    n75 += 1
    except:
        pass

    try:
        over14 = multi_index(factor_num,14)
        for i in over14:
            for j in over4:
                if i != j:
                    n75 += 1
    except:
        pass

    try:
        over74 = multi_index(factor_num,74)
        n75 += len(over74)
    except:
        pass
print(n75)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
            for(int k=0;i+j+k<=n;k++)
                if(i+j+k==n && i*1000+j*5000+k*10000==m)
                    return cout<<k<<" "<<j<<" "<<i<<endl,0;
    cout<<"-1 -1 -1"<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    M = (N - 1) * (N - 2) // 2
    if K > M:
        print(-1)
        return
    ans = []
    for i in range(N - 1):
        ans.append((i + 1, N))
    E = []
    for i in range(N - 1):
        for j in range(i):
            E.append((i + 1, j + 1))
    for i in range(M - K):
        ans.append(E[i])
    print(len(ans))
    for i, j in ans:
        print(i, j)


main()


Measured memory_bytes: 4020
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,trie[200001][2],a[200001],xb=1,top,L;
bool num[101];
char s[200001];
inline int read()
{
   int sum=0,x=1;
   char ch=getchar();
   while (ch<'0'||ch>'9')
   {
       if (ch=='-')
	     x=-1;
	   ch=getchar();
   }
   while (ch>='0'&&ch<='9')
   {
   	   sum=sum*10+ch-'0';
	   ch=getchar();
   }
   return sum*x;
}
inline void write(int x)
{
    if (x<0)
	{
        putchar('-');
        x=-x;
    }
    if (x>9)
      write(x/10);
    putchar(x%10+'0');
    return;
}
inline int lowbit(int x)
{
    int i=0;
    for (;!(x&1);++i,x>>=1);
      return i;
}
inline void insert(int v,int id,int d,int len)
{
    if (trie[v][s[a[id]+d-1]-'0']==0)
	  trie[v][s[a[id]+d-1]-'0']=++xb;
    if (d!=len)
	  insert(trie[v][s[a[id]+d-1]-'0'],id,d+1,len);
}
inline void dfs(int v,int d)
{
    if (trie[v][0]==0&&L-d>0)
	  num[lowbit(L-d)]^=1;
	if (trie[v][0]!=0)
      dfs(trie[v][0],d+1);
    if (trie[v][1]==0&&L-d>0)
	  num[lowbit(L-d)]^=1;
	if (trie[v][1]!=0)
      dfs(trie[v][1],d+1);
}
signed main()
{
    n=read();L=read();
    for (register int i=1;i<=n;++i)
    {
        a[i]=top+1;
        scanf("%s",s+a[i]);
        top+=strlen(s+a[i]);
        insert(1,i,1,strlen(s+a[i]));
    }
    dfs(1,0);
    for (register int i=0;i<61;++i)
	  if (num[i])
	  {
	      puts("Alice");
		  return 0;
	  }
    puts("Bob");
    return 0;
}

Measured memory_bytes: 7656
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <list>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


template <class Monoid>
class SegmentTree
{
public:
  using Func = function<Monoid(Monoid, Monoid)>;
  const Func F;
  const Monoid M1;
  int sz;
  vector<Monoid> seg;

  SegmentTree(int n,const Func fu, const Monoid &m1): F(fu) , M1(m1) {init(n);}
  void init(int n)
  {
      sz= 1;
      while (sz < n) sz *= 2;
      seg.assign(sz * 2, M1);
  }
  void update(int k,const Monoid &x)
  {
    k+=sz;
    seg[k]=x;
    while(k>>=1)
    {
      seg[k]=F(seg[k*2],seg[k*2+1]);
    }
  }
  Monoid query(int l,int r)
  {
    Monoid L=M1,R=M1;
    l+=sz;r+=sz;
    for(;l<r;l>>=1,r>>=1)
    {
      if(l&1)L=F(L,seg[l++]);
      if(r&1)R=F(seg[--r],R);
    }
    return F(L,R);
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  vector<pair<ll,ll>>b(n);
  rep(i,n)b[i]={a[i],-i};
  map<ll,ll>ma;
  sort(all(b));

  ll id=1;
  rep(i,n){
    ma[(b[i].first<<32)-b[i].second]=id++;
  }
  auto check=[&](){
    SegmentTree<ll>st(id+1,[](ll a,ll b){return max(a,b);},0);
    rep(i,n){
      ll ta=ma[(a[i]<<32)+i];
      ll tmax=st.query(0,ta);
      if(tmax==0){
        st.update(ta,ta);
      }
      else {
        st.update(tmax,0);
        st.update(ta,ta);
      }
    }
    ll res=0;
    rep(i,id+1){
      if(st.query(i,i+1))res++;
    }
    return res;
  };
  cout<<check()<<endl;


  return 0;

}


Measured memory_bytes: 10880
def main():
    N = int(input())
    ans = 0
    for i in range(1, N+1):
        if i % 15 == 0:
            pass
        elif i % 3 == 0:
            pass
        elif i % 5 == 0:
            pass
        else:
            ans += i

    print(ans)
    return 0


if __name__ == '__main__':
    main()

Measured memory_bytes: 67244
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

string S;

int main(){
    cin>>S;
    for(int i=S.length()-1;;){
        if(i==-1){
            out("YES");
            return 0;
        }
        if(i>=4&&(S.substr(i-4,5)=="dream"||S.substr(i-4,5)=="erase")){
            i-=5;
            // out("hi");
            // out(i);
            continue;
        }
        else if(i>=5&&S.substr(i-5,6)=="eraser"){
            i-=6;
            continue;
        }
        else if(i>=6&&S.substr(i-6,7)=="dreamer"){
            i-=7;
            continue;
        }
        else{
            out("NO");
            return 0;
        }
    }
}


Measured memory_bytes: 512
#include <stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
int d[101],f[101],Adj[101][101],color[101];
int time;
int n;

void DFS_Visit(int u)
{
  int i;
  color[u]=GRAY;
  d[u]=++time;
  for(i=1;i<=n;i++)
    {
      if(Adj[u][i]==1&&color[i]==WHITE)
	{
	  DFS_Visit(i);
	}
    }
  color[u]=BLACK;
  f[u]=++time;
}

void DFS(void)
{
  int i;
  for(i=1;i<=n;i++)
    {
      color[i]=WHITE;
      time=0;
    }
  for(i=1;i<=n;i++)
    {
      if(color[i]==WHITE)
	{
	  DFS_Visit(i);
	}
    }
}



main()
{
  int i,j;
  int u,k,v;

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

  for(i=1;i<=n;i++)
    {
      scanf("%d%d",&u,&k);
      for(j=1;j<=k;j++)
	{
	  scanf("%d",&v);
	  Adj[u][v]=1;
	}
    }
  DFS();
  for(i=1;i<=n;i++)
    {
      printf("%d %d %d\n",i,d[i],f[i]);
    }
  return 0;
}

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

int main(void) {
  string S, T;
  cin >> S >> T;
  int cnt = 0;
  for(int i = 0; i < S.size(); i++) {
    if(S[i] == T[i]) {
      cnt++; 
    }
  }
  cout << cnt;
  return 0; 
}

Measured memory_bytes: 256
def binary_search(arr, key, option)
    left = -1
    right = arr.size
    while (right - left).abs > 1 do
        mid = (right + left) / 2
        if arr[mid] >= key then
            right = mid
        else
            left = mid
        end
    end
    if option === "min" then
        return right
    elsif option === "max" then
        return left
    end
end

n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
dp = [0]
n.times do |i|
    dp << a[i] + dp[i]
end
rod_length = dp[-1]
tmp_1 = dp[binary_search(dp, rod_length/2, "min")]
tmp_2 = dp[binary_search(dp, rod_length/2, "max")]
mid = (tmp_1 - rod_length/2).abs > (tmp_2 - rod_length/2).abs ? tmp_2 : tmp_1

puts (rod_length - mid*2).abs

Measured memory_bytes: 31804
import numpy as np


def read():
    N = int(input().strip())  # N <= 10**5
    to = [[] for _ in range(N)]
    cost = [[] for _ in range(N)]
    for i in range(N-1):
        # u[i] < v[i] は保証されている
        u, v, w = list(map(int, input().strip().split()))
        to[u-1].append(v-1)
        to[v-1].append(u-1)
        cost[u-1].append(w % 2)
        cost[v-1].append(w % 2)
    return N, to, cost


def solve(N, to, cost):
    c = [-1] * N  # -1: unvisited, 0: white, 1: black
    q = list()
    c[0] = 0
    q.append(0)
    while len(q) > 0:
        s = q.pop()
        for t, co in zip(to[s], cost[s]):
            if c[t] == -1:
                if co:
                    c[t] = 1 - c[s]
                else:
                    c[t] = c[s]
                q.append(t)
    return c


if __name__ == '__main__':
    inputs = read()
    colors = solve(*inputs)
    for col in colors:
        print("%d" % col)


Measured memory_bytes: 47176
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	const row1 = input[0].split(" ");
	const row2 = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var n = parseInt(row1[0], 10);
	var k = parseInt(row1[1], 10);
	var a = row2;

	var first, last;

	for (let i = k; i < n; i++) {
		first = parseInt(a[i - k]);
		last = parseInt(a[i]);
		if (first < last) {
			console.log('Yes');
		} else {
			console.log('No');
		}
	}
}

// 実行 ファイル名により本番かどうか判断
if (__filename.match("Main.js$")) {
	Main(require("fs").readFileSync("/dev/stdin", "utf8"));
} else {
//	Main("3\n4 5\nhello\n");
	Main(require("fs").readFileSync("q3.txt", "utf8"));
}


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

int main(){
	while(1){
		int n, m, p;
		int x[100];
		long sum=0;
		
		scanf(" %d %d %d", &n, &m, &p);
		if(n==0) break;
		for(int i=0; i<n; ++i){
			scanf(" %d", &x[i]);
			sum += x[i];
		}
		sum*=(100-p);
		if(x[m-1]==0)sum=0;	
		else sum/=x[m-1];
		printf("%ld\n", sum);
	}	
	
	return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
//#include <bits/stdc++.h>

using namespace std;

typedef long long li;

int main() {
    li n, m;
    cin >> n >> m;

    li ans = ((n - m) * 100 + m * 1900) * (1LL << m);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Point = pair<int,int>;
int W,H;
//int point[5001][5001] = {0};

vector<vector<bool>> used(90,vector<bool>(90,false));
vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};
int ans = 0;


int main()
{
    int N,M;
    cin >> N >>M;
    
    vector<vector<int>> data(N);
    for(int i=0;i<M;i++)
    {
        int a;
        cin >> a;
        for(int j=0;j<a;j++)
        {
            int b;
            cin >> b;
            b--;
            data[b].push_back(i);
        }
    }
    
    vector<int> p(M);
    for(int i=0;i<M;i++)
    {
        cin >> p[i];
    }
    
    int ans = 0;
    
    for(int bit = 0;bit < (1<<N);bit++)
    {
        vector<int> q(M,0);
        for(int i = 0;i<N;i++)
        {
            if(bit & (1<<i))
            {
                for(int j=0;j<data[i].size();j++)
                {
                    q[data[i][j]]++;
                }
            }
        }
        bool check = true;
        for(int i = 0;i<M;i++)
        {
            if(p[i] != q[i] %2)
            {
                check = false;
                break;
            }
        }
        if(check)
        {
            ans ++;
        }
    }
    
    
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

N = int(input())
MOD = 10**9+7
G = [set() for _ in range(N)]
for i in range(N-1):
    x, y = map(lambda x: int(x)-1, input().split())
    G[x].add(y)
    G[y].add(x)

def dfs(v, r):
    w, b = 1, 1
    for u in G[v]:
        if u == r: continue
        c_w, c_b = dfs(u, v)
        w *= c_w + c_b
        b *= c_w
    w %= MOD
    b %= MOD
    return w, b

print(sum(dfs(0, None))%MOD)

Measured memory_bytes: 118924
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int main(){
	
	int b, r, g, c, s, t;
	
	while(true){
		
		cin >> b >> r >> g >> c >> s >> t;
		
		if(t == 0){
			break;
		}
		
		int ans = 100;
		
		ans += b * (15 + 16 * 5);
		ans += r * (15 + 16 * 3);
		ans += g * 7;
		ans += c * 2;
		
		t -= s;
		
		ans -= t * 3;
		
		cout << ans << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 2976
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  string A, B;
  cin >> A >> B;

  int lenA = A.length();
  int lenB = B.length();

  rep(i, 100 - lenA) {
    A = "0" + A;
  }

  rep(i, 100 - lenB) {
    B = "0" + B;
  }

  if (A == B) {
    cout << "EQUAL" << endl;
  } else if (A > B) {
    cout << "GREATER" << endl;
  } else {
    cout << "LESS" << endl;
  }

}


Measured memory_bytes: 256
#include <stdio.h>
#define ll long long int

int main(void) {
    ll l, r;
    int k, a = 2020;
    scanf("%lld%lld", &l, &r);
    if((r - l) >= 2019) {
        a = 0;
        printf("%d\n", a);
        return 0;
    }
    for(ll i = l; i < r  &&  i <= l+2019; i++) {
        for(ll j = i+1; j <= r  &&  j <= l+2019; j++) {
            if(i < j) {
                k = (i * j) % 2019;
                if(a > k) a = k;
            }
        }
    }
    printf("%d\n", a);
    return 0;
}


Measured memory_bytes: 128
import numpy as np

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

a_max = max(a)
a_max_index = np.argmax(a)

del a[a_max_index]

center = a_max / 2

a_x_index = np.argmin(np.absolute(np.array(a) - center))
a_x = a[a_x_index]

print(str(a_max) + ' ' + str(a_x))


Measured memory_bytes: 23664
#include <iostream>
#include <set>
using namespace std;
const long long MAXN=(1e5)*3;
long long a[MAXN],p[MAXN],l,r,n;
long long i;
unsigned long long sums=0;
set <long long > mset;
	set <long long> :: iterator it;
int main() {
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		p[a[i]]=i;
	}
	mset.clear();
	for(i=1;i<=n;i++)
	{
		mset.insert(p[i]);
			it=mset.find(p[i]);
		if(mset.size()>1 && *it!=*mset.begin())
		{
			*it--;
			l=*mset.find(*it);l++;
		}
		else l=0;
		it=mset.find(p[i]);
		if(mset.size()>1 && it!=--mset.end())
		{
			*it++;
			r=*mset.find(*it);r--;
		}
		else r=n-1;
		sums+=((p[i]-l+1)*(r-p[i]+1)*i);
	}
	cout<<sums;
	return 0;
}

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

#define lli long long int
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define true 1
#define false 0

typedef struct node {
	struct node* below;
	struct node* side;
	int isParent;
	int id;
} node;

void add(node *a,node *b){
	node *swap;
	swap = a->below;
	a->below = b;
	b->side = swap;
}

int dfs(node *a,lli k){
	static int counter;
	int height = 0;
	int c=0;
	node* b = a;
	a = a->below;
	while(a){
		counter = 0;
		c += dfs(a,k);
		a = a->side;
		height = max(counter,height);
	}
	counter = height + 1;
	if(height == k-1 && !b->isParent){
		b->isParent = true;
		c++;
		counter = 0;
	}

	return c;
}


int main(void){
	int i;
	int n;
	int x;
	int ans;
	lli k;
	node *a;
	scanf("%d%lld",&n,&k);
	a = calloc(sizeof(node),n);
	scanf("%d",&x);
	if(x==1){
		ans = 0;
	}else{
		ans = 1;
	}
	a[0].isParent = true;
	for(i=1;i<n;i++){
		scanf("%d",&x);
		add(&a[x-1],&a[i]);
		if(x==1){
			a[i].isParent = true;
		}
		a[i].id = i;
	}
	printf("%d\n",ans + dfs(a,k));

	return 0;
}

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

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

    ll n;
    cin >> n;
    vector<string> s(n);
    for (ll i = 0;i < n;i++){
        cin >> s[i];
    }
    ll m = 0,a = 0,r = 0,c = 0,h = 0;

    for (ll i = 0; i < n; i++){
        if (s[i][0] == 'M'){
            m++;
            continue;
        }
        if (s[i][0] == 'A'){
            a++;
            continue;
        }
        if (s[i][0] == 'R'){
            r++;
            continue;
        }
        if (s[i][0] == 'C'){
            c++;
            continue;
        }
        if (s[i][0] == 'H'){
            h++;
            continue;
        }
    }

    ll ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h;
    cout << ans << endl;
    
}

Measured memory_bytes: 6240
#include <iostream>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

const int DEPTH = 17;
const int INF = 1e+16;
struct SegTree {
	int SegSumMax[1 << (DEPTH + 1)];
	int SegSumMaxL[1 << (DEPTH + 1)];
	int SegSumMaxR[1 << (DEPTH + 1)];
	int Sum[1 << (DEPTH + 1)];
	
	SegTree() {
		int i;
		rep(i, (1 << (DEPTH + 1))) {
			SegSumMax[i] = -INF;
			SegSumMaxL[i] = -INF;
			SegSumMaxR[i] = -INF;
			Sum[i] = 0;
		}
	}
	
	void update(int pos, int x) {
		pos += (1 << DEPTH) - 1;
		SegSumMax[pos] = x;
		SegSumMaxL[pos] = x;
		SegSumMaxR[pos] = x;
		Sum[pos] = x;
		while (pos > 0) {
			pos = (pos - 1) / 2;
			SegSumMax[pos] = max({	SegSumMax[pos * 2 + 1],
									SegSumMax[pos * 2 + 2],
									SegSumMaxR[pos * 2 + 1] + SegSumMaxL[pos * 2 + 2]});
			SegSumMaxL[pos] = max(SegSumMaxL[pos * 2 + 1], Sum[pos * 2 + 1] + SegSumMaxL[pos * 2 + 2]);
			SegSumMaxR[pos] = max(SegSumMaxR[pos * 2 + 2], Sum[pos * 2 + 2] + SegSumMaxR[pos * 2 + 1]);
			Sum[pos] = Sum[pos * 2 + 1] + Sum[pos * 2 + 2];
		}
	}
	
	int query() {
		return max(0LL, SegSumMax[0]);
	}
};

int n, q;
int a[100000];
int k, x;
SegTree seg;

signed main() {
	int i;
	
	cin >> n >> q;
	rep(i, n) cin >> a[i];
	rep(i, n) seg.update(i, a[i]);
	cout << seg.query() << endl;
	
	rep(i, q) {
		cin >> k >> x;
		k--;
		seg.update(k, x);
		cout << seg.query() << endl;
	}
	return 0;
}


Measured memory_bytes: 12076