akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i, 0, n) cin >> h[i];
    ll ans = 0;
    bool flag = true;
    if (*max_element(all(h)) == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    while (flag)
    {
        ll start = 0;
        rep(i, 0, n)
        {
            if (h[i] != 0)
            {
                start = i;
                break;
            }
        }
        ll end = n;
        rep(i, start, n)
        {
            if (h[i] == 0)
            {
                end = i;
                break;
            }
        }

        rep(i, start, end)
            h[i]--;
        ++ans;
        if (*max_element(all(h)) == 0)
            flag = false;
    }
    cout << ans << endl;
}


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

int main() {
    int s, w;
    cin >> s >> w;
    cout << ((s <= w) ? "unsafe" : "safe") << endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int A[300000];
int B[300000];
int visit[300000];
int main(){
    CIN(N);
    CIN(M);
    SCIN(str);
    V<V<Edge>> vec(300000);
    for(int a = 0; a < M;a++){
        CIN(b);CIN(c);
        Edge e(b-1,c-1);
        Edge w(c-1,b-1);
        vec.at(b-1).push_back(e);
        vec.at(c-1).push_back(w);
    }

    queue<int> Q;
    int count = 0;
    for(int i = 1;i <= N;i++){
        for(int j = 0;j <vec.at(i-1).size();j++){
            if(str.at(vec.at(i-1).at(j).to) == 'A')A[i-1]++;
            if(str.at(vec.at(i-1).at(j).to) == 'B')B[i-1]++;
        }
        if(A[i-1] == 0||B[i-1] == 0){
            Q.push(i-1);
            visit[i-1]=1;
            count++;
        }
    }

    while(!Q.empty()){
        int t = Q.front();
        Q.pop();
        for(int i = 0;i < vec.at(t).size();i++){
            if(str.at(t) == 'A')A[vec.at(t).at(i).to]--;
            if(str.at(t) == 'B')B[vec.at(t).at(i).to]--;
            if((A[vec.at(t).at(i).to] == 0 || B[vec.at(t).at(i).to] == 0 )&& visit[vec.at(t).at(i).to] == 0){
                Q.push(vec.at(t).at(i).to);
                count++;
                visit[vec.at(t).at(i).to]=1;
            }

        }
    }
    Yes(count<N);
    return 0;
}



Measured memory_bytes: 23172
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> test(n);
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        for (int j = 0; j < a; ++j) {
            int x, y;
            cin >> x >> y;
            test[i].emplace_back(x-1, y);
        }
    }

    int ans = 0;
    for (int i = 0; i < (1 << n); ++i) {
        bool f = true;
        for (int j = 0; j < n; ++j) {
            if (((i >> j) & 1) == 0) continue;
            for (auto &e: test[j]) {
                if (((i >> e.first) & 1) != e.second) {
                    f = false;
                    break;
                }
            }
        }
        if (f) ans = max(ans, (int)bitset<32>(i).count());
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

const int maxn = 1e5 + 100;
int a[maxn];

int main (){
    string s;
    cin >> s;
    int n = s.size();
    int cnt = 0, k = maxn;
    for (int i = 0; i < n; i++){
        int dig = s[i] - '0';
        if (cnt + dig % 2 == 1){
            cnt ^= 1;
            k = min (k, max (i, n - i));
        }
    }
    cout << min (k, n) << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int a[2010][2010],b[2010][2010];

int main() {
    int h,w;
    cin>>h>>w;
    char fi[h][w];
    rep(i,h){
        rep(j,w){
            cin>>fi[i][j];
        }
    }
    
    rep(i,h){
        int cnt=0;
        rep(j,w){
            if(fi[i][j]=='#'){
                cnt=0;
                a[i][j]=0;
            }
            else{
                cnt++;
                a[i][j]=cnt;
            }
        }
    }
    
    rep(i,h){
        int cnt=0;
        for(int j=w-1;j>=0;j--){
            if(fi[i][j]=='#'){
                cnt=0;
            }
            else if(cnt==0){
                cnt=a[i][j];
            }
            else a[i][j]=cnt;
        }
    }

    rep(j,w){
        int cnt=0;
        rep(i,h){
            if(fi[i][j]=='#'){
                cnt=0;
                b[i][j]=0;
            }
            else{
                cnt++;
                b[i][j]=cnt;
            }
        }
    }
    
    rep(j,w){
        int cnt=0;
        for(int i=h-1;i>=0;i--){
            if(fi[i][j]=='#'){
                cnt=0;
            }
            else if(cnt==0){
                cnt=b[i][j];
            }
            else b[i][j]=cnt;
        }
    }

    int ans=0;

    rep(i,h){
        rep(j,w){
            ans=max(ans,a[i][j]+b[i][j]);
        }
    }

    cout<<ans-1<<endl;
}




Measured memory_bytes: 35584
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
int num[105];

int main()
{
    string s;
    int ca=0,cb=0;
    cin >> s;
    int len=s.length();
    for(int i=0;i<len;i++){
        if(i%2==0&&s[i]=='0') ca++;
        if(i%2==1&&s[i]=='1') ca++;
    }
    for(int i=0;i<len;i++){
        if(i%2==1&&s[i]=='0') cb++;
        if(i%2==0&&s[i]=='1') cb++;
    }
    cout << min(ca,cb) << endl;
}


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

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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - b) <= d && abs(b - c) <= d || abs(a - c) <= d) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 764
n,k=gets.split.map(&:to_i)
if k==0
  puts n**2
  exit
end
c=0
(k+1).upto(n) do |i|
  c+=(n+1)/i*(i-k)
  if (n+1)%i>k
    c+=(n+1)%i-k
  end
end
puts c


Measured memory_bytes: 14240
#include"bits/stdc++.h"
using namespace std;

int n;
#define MAX 200002
char buf[MAX];
string s;
int q;

vector<pair<char, int> > ope;

bool ok(int z) {
	if (z == -1)return true;
	int pos = z;
	for (int i = 0; i < ope.size(); i++) {
		if (s[pos] == ope[i].first) {
			pos += ope[i].second;
		}
		if (pos >= n)return false;
		if (pos < 0)return true;
	}
	return false;
}
bool ok2(int z) {
	if (z ==  n)return true;
	int pos = z;
	for (int i = 0; i < ope.size(); i++) {
		if (s[pos] == ope[i].first) {
			pos += ope[i].second;
		}
		if (pos >= n)return true;
		if (pos < 0)return false;
	}
	return false;
}
char dum[4];

int main() {
	cin >> n>> q;
	scanf("%s", buf);
	s = buf;
	for (int i = 0; i <q; i++) {
		scanf("%s", buf);
		scanf("%s", dum);
		int d;
		if (dum[0] == 'L') {
			d = -1;
		}
		else {
			d = 1;
		}
		ope.push_back(make_pair(buf[0], d));
	}
	int mint = -1;
	int maxt = n-1;
	while (mint + 1 < maxt) {
		int mid = (mint + maxt)/2;
		if (ok(mid)) {
			mint = mid;
		}
		else {
			maxt = mid;
		}
	}
	int ans = 0;
	if (ok(maxt)) {
		ans += maxt + 1;
	}
	else {
		ok(mint);
		ans += mint + 1;
	}
	mint = 0;
	maxt = n;
	while (mint + 1 < maxt) {
		int mid = (mint + maxt) / 2;
		if (ok2(mid)) {
			maxt = mid;
		}
		else {
			mint = mid;
		}
	}
	if (ok2(mint)) {
		ans += n - mint;
	}
	else {
		ans += n - maxt;
	}
	ans = n - ans;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2804
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#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>
using namespace std;

const long long INF = LLONG_MAX / 4;

int main()
{
    int n, e, t;
    cin >> n >> e >> t;

    vector<int> x(n+1);
    for(int i=0; i<n; ++i)
        cin >> x[i];
    x[n] = e;

    vector<long long> dp(n+1, INF);
    dp[0] = x[0];
    int j = 0;
    long long tmp = INF;
    for(int i=0; i<n; ++i){
        while(j <= i && (x[i] - x[j]) * 2LL > t){
            tmp = min(tmp, dp[j] - x[j] * 3LL);
            ++ j;
        }
        dp[i+1] = min(tmp + x[i] * 3LL, dp[j] + (x[i] - x[j]) + t) + (x[i+1] - x[i]);
    }
    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    int d = 8 * n + 1;
    int rd;
    for (rd = 0; rd * rd < d; rd++)
        ;
    if (rd * rd != d)
    {
        cout << "No" << endl;
        return 0;
    }
    if ((rd + 1) % 2 != 0)
    {
        cout << "No" << endl;
        return 0;
    }

    int k = (rd + 1) / 2;

    vector<vector<int>> s(k, vector<int>());
    int v = 1;
    for (int i = 0; i < k - 1; i++)
    {
        for (int j = i + 1; j < k; j++)
        {
            s[i].push_back(v);
            s[j].push_back(v);
            v++;
        }
    }

    cout << "Yes" << endl;
    cout << k << endl;
    rep(i, k)
    {
        cout << s[i].size();
        rep(j, s[i].size())
        {
            cout << " " << s[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    bool flag = false;
    rep(i, n) {
        char c;
        cin >> c;
        if (c == 'Y') flag = true;
    }
    cout << (flag?"Four":"Three") << endl; 
}

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

namespace ConsoleApp15
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[5];
            for(int b=0;b<a.Length;b++)
            {
                a[b] = Convert.ToInt32(Console.ReadLine());
            }

            int k = Convert.ToInt32(Console.ReadLine());

            int c = 0;
            for(int i=0;i<a.Length;i++)
            {
                for(int d=i+1;d<a.Length;d++)
                {
                    if(a[d]-a[i]>k)
                    {
                        c++;
                    }

                } 
            }
            if (c == 0)
            {
                 Console.Write("Yay!");
            }
            else
            {
                Console.Write(":(");
            }
           
            Console.Read();
        }
    }
}


Measured memory_bytes: 11348
/**/
#include<bits/stdc++.h>
using namespace std;
char a[100001];
int main(){
	ios::sync_with_stdio(false);
	gets(a);
	int len=strlen(a),i=0,flag=0;
	while(i<len){
		if(a[i]=='C'){
			while(i<len){
				if(a[i]=='F'){
					flag=1;
					break;
				}
				i++;
			}
		}
		i++;
		if(flag==1){
			break;
		}
	}
	if(flag==1){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


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

using namespace std;

#define vt          vector
#define sz(x)       int((x).size())
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

using ll = long long;
using pii = pair<int, int>;

bool is_prime(int n) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

void solve() {
    int n;
    cin >> n;
    
    int num = 11;
    while (n--) {
        while (!is_prime(num)) num += 5;
        cout << num << ' ';
        num += 5;
    }
}

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

    int tcs = 1;
    for (int tc = 1; tc <= tcs; tc++) {
        // cout << "Case " << tc << ": ";
        solve();
    }
}



Measured memory_bytes: 3508
program crane

 implicit none
 integer::x,y,jj,i,ans

 jj=0

 read*,x,y
 
 

 do i=0,x
  ans=2*i+4*(x-i)
  if(x-i>=0) then
   if(ans==y) jj=jj+1
  end if
 end do

 if(jj==0) print*,'No'
 if(jj/=0) print*,'Yes'

end program crane

Measured memory_bytes: 2812
use strict;
use warnings;
use v5.18;

package Vector {

    sub new {
        my $class = shift;
        my ( $size, $value ) = @_;

        my $data;
        if ( defined $size ) {
            $value = 0 unless defined $value;
            $data = [ map { $value } 1 .. $size ];
        }
        else {
            $data = [];
        }

        my $self = bless { _data => $data }, $class;
        return $self;
    }

    sub push_back {
        my ( $self, $x ) = @_;
        my $data = $self->{_data};
        push @$data => $x;
    }

    sub size {
        my $self = shift;
        my $data = $self->{_data};
        scalar(@$data);
    }

    sub at {
        my ( $self, $i, $x ) = @_;

        my $data = $self->{_data};
        my $len  = $self->size;
        die "invalid index: $i (size = $len)\n"
          unless 0 <= $i && $i < $self->size;

        if ( defined $x ) {
            $data->[$i] = $x;
        }
        else {
            $data->[$i];
        }
    }

    sub front {
        my $self = shift;
        $self->at(0);
    }

    sub back {
        my $self = shift;
        $self->at( $self->size - 1 );
    }
};

chomp( my $n = <> );

my $cnt = Vector->new;

for my $i ( 0 .. $n - 1 ) {
    chomp( my $s = <> );
    my @s = split( //, $s );
    $cnt->push_back( Vector->new( 26, 0 ) );
    for my $j ( 0 .. $#s ) {
        my $k = ord( $s[$j] ) - ord('a');
        my $t = $cnt->at($i)->at($k);
        $cnt->at($i)->at( $k, $t + 1 );
    }
}

for my $i ( 0 .. 25 ) {
    my $min = 100;
    for my $j ( 0 .. $n - 1 ) {
        my $t = $cnt->at($j)->at($i);
        $min = $t if ( $t < $min );
    }

    # print "min = $min\n";
    my $c = chr( $i + ord('a') );
    print $c for 1 .. $min;
}
print "\n";


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

int gcd(int a,int b){
  if(b==0)return a;
  return gcd(b,a%b);
}

int main(){
  int a,b;
  while(cin >> a >> b){
    int g = gcd(a,b);
    //lcm == a*b/gcd(a,b)で求まる
    //cout << g << " " << a*b/g << endl;  <-オーバーフローする
    cout << g << " " << a/g*b << endl; // <-オーバーフローしない
  }
}

Measured memory_bytes: 1160
#include<cstdio>
using namespace std;
int main(){
    int a[3],k;
    int maxa=0,maxi=0;
    for(int i=0;i<3;i++)
    {
        scanf("%d",&a[i]);
        if(maxa<=a[i])
        {
            maxa=a[i];
            maxi=i;
        }
    }
    scanf("%d",&k);
    for(int i=0;i<k;i++)
        a[maxi]*=2;
    printf("%d\n",a[0]+a[1]+a[2]);
    return 0;
}


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

typedef long long ll;

int n, ans;
int a, b;
bool check(int x) {
    int sum = 0;
    while (x) {
        sum += x % 10;
        x /= 10;
    }
    return sum >= a && sum <= b;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> a >> b;
    for (int i = 1; i <= n; ++i) {
        if (check(i))
            ans += i;
    }
    cout << ans << endl;

    return 0;
}



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

int main() {
    int N, X;
    int m;
    int m_min = 1100;
    cin >> N >> X;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> m;
        m_min = min(m, m_min);
        X -= m;
        ans++;
    }

    ans += X / m_min;

    cout << ans << endl;
}

Measured memory_bytes: 3624
n,m = map(int,input().split())
ls = []

for i in range(m):
    l = int(input())
    ll = list(map(int,input().split()))

    for ii in range(l):
        ls.append(ll[ii])

ls = set(ls)

c = 0
for i in range(1,n+1):
    if not i in ls:
        c+=1

print(c)

Measured memory_bytes: 9200
package main

import "fmt"

func solve(N int, X int, a []int, p []int) int {
	if N == 0 {
		if X <= 0 {
			return 0
		} else {
			return 1
		}
	} else if X <= 1+a[N-1] {
		return solve(N-1, X-1, a, p)
	} else {
		return p[N-1] + 1 + solve(N-1, X-2-a[N-1], a, p)
	}
}

func main() {
	// Code for D - Christmas
	var N, X int
	fmt.Scan(&N, &X)

	a := make([]int, N)
	p := make([]int, N)
	a[0] = 1
	p[0] = 1
	for i := 1; i < N; i++ {
		a[i] = 2*a[i-1] + 3
		p[i] = 2*p[i-1] + 1
	}

	fmt.Println(solve(N, X, a, p))
}


Measured memory_bytes: 1800
import java.awt.geom.Point2D;
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = 0;
		double x, y, xp, yp, xq, yq;
		double a, b, c, z;
		double sum = 0;
		String[] s = new String[2];
		
		s = sc.next().split(",");
		x = Double.valueOf(s[0]);
		y = Double.valueOf(s[1]);
		s = sc.next().split(",");
		xp = Double.valueOf(s[0]);
		yp = Double.valueOf(s[1]);
		b = Point2D.Double.distance(x, y, xp, yp);
		
		while(sc.hasNext()){
			s = sc.next().split(",");
			xq = xp;
			yq = yp;
			xp = Double.valueOf(s[0]);
			yp = Double.valueOf(s[1]);
			
			a = b;
			b = Point2D.Double.distance(x, y, xp, yp);
			c = Point2D.Double.distance(xp, yp, xq, yq);
			
			z = (a+b+c)/2;
			sum += Math.sqrt(z*(z-a)*(z-b)*(z-c));
		}
		System.out.println(sum);
		
	}	
}

Measured memory_bytes: 17152
($A,$B,$H,$M)=glob<>;
$pi=atan2 0,-1;
$t=$H*60+$M;
$x=abs$t/720-$M/60;
$x=1-$x if$x>0.5;
$x*=2*$pi;
print sqrt($A**2+$B**2-2*$A*$B*cos$x)


Measured memory_bytes: 5784
#include <iostream>

using namespace std;

int main()
{
    int r, D, x2000;
    cin >> r >> D >> x2000;
    for(int i = 0; i < 10; i++){
        x2000 = r*x2000 - D;
        cout << x2000 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n, x = list(map(int, input().split()))

a = [0, 1]
b = [0, 1]
for i in range(n):
    a.append(a[i + 1] * 2 + 1)
    b.append(b[i + 1] * 2 + 3)

if b[-1] == x:
    print(a[-1])
    exit()

ans = 0
left = 0
mid = int(b[-1] / 2)
right = b[-1] - 1
i = len(b) - 1
while i > 0:
    if mid + 1 == x:
        ans += a[i - 1] + 1
        break
    elif mid < x:
        ans += a[i - 1] + 1
        left = mid + 1
        mid = mid + int((right - mid) / 2)
        right = right - 1
    else:
        right = mid - 1
        mid = mid - int((mid - left) / 2)
        left = left + 1
    i = i - 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    ll n;
    cin >> n;
    for (ll h = 1; h < 3500; h++) for (ll m = 1; m < 3500; m++) {
        if (4 * h * m - n * h - n * m <= 0 or (n * h * m) % (4 * h * m - n * h - n * m) != 0) continue;
        ll w = (n * h * m) / (4 * h * m - n * h - n * m);
        if (4 * h * m * w == n * (m * w + h * w + h * m)) {
            cout << h << " " << m << " " << w << endl;
            return;
        }
    }
}


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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    set<string> kei;
    int N;
    cin >> N;
    REP(i, N) {
        string s;
        cin >> s;
        kei.insert(s);
    }
    printf("%zu\n", kei.size());

    return 0;
}


Measured memory_bytes: 19240
#include <iostream>

using namespace std;

int main() {

    int i = 0,j,k = 0,n,grage[100],box[100];
    
    while(cin >> n){
        box[i] = n;
        i++;
    }
    
    for(j = 0;j < i;j++){
        if(box[j] != 0){
            grage[k] = box[j];
            k++;
        }
        else {
            cout << grage[k - 1] << endl;
            k--;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <utility>
#include <tuple>
#include <map>
#include <algorithm>
using Int = long long;
using namespace std;

// http://www.prefield.com/algorithm/container/union_find.html
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main()
{
    int N; cin >> N;
    vector<pair<int, int>> cities(N);
    for (int i = 0; i < N; i++) {
        int x, y; cin >> x >> y;
        cities[i] = {x, y};
    }
    map<int, vector<int>> xs, ys;
    for (int i = 0; i < N; i++) {
        int x, y;
        tie(x, y) = cities[i];
        xs[x].emplace_back(i);
        ys[y].emplace_back(i);
    }
    vector<tuple<int, int, int>> edges;
    #define EDGE(i, j) do { \
        int a, b, c, d; \
        tie(a, b) = cities[i]; \
        tie(c, d) = cities[j]; \
        edges.emplace_back(min(abs(a-c), abs(b-d)), i, j); \
    } while (0)
    for (auto it = xs.begin(); it != xs.end(); ++it) {
        for (int i = 0; i < it->second.size() - 1; i++) {
            EDGE(it->second[i], it->second[i + 1]);
        }
        if (next(it) != xs.end()) {
            EDGE(it->second[0], next(it)->second[0]);
        }
    }
    for (auto it = ys.begin(); it != ys.end(); ++it) {
        for (int i = 0; i < it->second.size() - 1; i++) {
            EDGE(it->second[i], it->second[i + 1]);
        }
        if (next(it) != ys.end()) {
            EDGE(it->second[0], next(it)->second[0]);
        }
    }
    sort(edges.begin(), edges.end());
    edges.erase(unique(edges.begin(), edges.end()), edges.end());

    UnionFind uf(N);
    int first = get<1>(edges[0]);
    int cost = 0;
    for (int i = 0; i < edges.size() && uf.size(first) < N; i++) {
        int c, x, y;
        tie(c, x, y) = edges[i];
        if (uf.findSet(x, y)) continue;
        uf.unionSet(x, y);
        cost += c;
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 27636
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
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=(a);i>(ll)(b);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 co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  vll A={1,3,1,2,1,2,1,1,2,1,2,1};
  ll a,b;
  	ci(a>>b)
      if(A[a-1]==A[b-1]) co("Yes")
        else co("No")
        }

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

using namespace std;
using ll = long long;

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

  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  ll ans = 0;
  ll prev = 1;
  for (auto x : a) {
    if (prev > x) {
      ans += prev - x;
    }
    prev = max(prev, x);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4764
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class B
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var S = Scanner.Scan<string>();
            var T = Scanner.Scan<string>();
            var answer = T.Length;
            for (var i = 0; i < S.Length - T.Length + 1; i++)
            {
                var tmp = 0;
                for (var j = 0; j < T.Length; j++)
                {
                    if (S[i + j] != T[j]) tmp++;
                }
                answer = Math.Min(answer, tmp);
            }
            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 26812
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
#include <bits/stdc++.h>
#include <regex>
using namespace std;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
    int n;
    cin>>n;
    set<string>s;
    string str;
    rep(i,n){
        cin>>str;
        s.insert(str);
    }
    cout<<s.size()<<endl;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    if (a%3 == 0) cout << "Possible" << endl;
    else if(b%3 == 0) cout << "Possible" << endl;
    else if((a+b)%3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,l;
cin>>n>>l;
vector<string>s(n);
for(int i=0;i<n;i++){
    cin>>s[i];
}
sort(begin(s),end(s));
string ans;
for(auto x:s)
    ans+=x;
cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

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


int main() {
    double n,t,a; cin >> n >> t >> a;
    vector<double> h(n);
    double min = 1000000;
    int min_num = 0;
    rep(i, n){
        cin >> h[i];
        if (abs(a - (t - h[i]*0.006)) < min){
            min = abs(a - (t - h[i]*0.006));
            min_num = i+1;
        }
    } 
    cout << min_num << endl;
    return 0;
}


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

int main(void){
  int i,n,q,m,d;
  int sum[101];
  int max,day;

  while(1){
    scanf("%d%d",&n,&q);
    if(!n && !q) break;

    memset(sum,0,sizeof(sum));
    max = 0;
    while(n--){
      scanf("%d",&m);
      while(m--){
	scanf("%d",&d);
	sum[d]++;
      }
    }
    for(i=1;i<=100;i++){
      if(sum[i]>max){
	max = sum[i];
	day = i;
      }
    }
    if(max>=q) printf("%d\n",day);
    else printf("0\n");
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include<string>
using namespace std;
int main() {
    int a[]={1,13,12,11,10,9,8,7,6,5,4,3,2};
    int A,B,z=0,v=0;
    cin>>A>>B;
    for(int i=0;i<13;i++)
    {
        if(a[i]==A){
            z=i;
        }
         if(a[i]==B){
            v=i;
        }
    }
if(z<v){
    cout<<"Alice";}

else if(z>v){
    cout<<"Bob";}
else if(z==v){cout<<"Draw";}

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long

struct node { int t,v,next,from; }a[200010];

int head[100010],num[100010],n,m,h1,h2,h3,cnt,cnt1,tot;
bool bo[100010],bb[100010],flag;
ll ans;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void add(int x,int y,int z,int hh) { a[++tot].t=y;a[tot].v=z;a[tot].from=hh;a[tot].next=head[x];head[x]=tot; }

inline void dfs(int x)
{
	bo[x]=true;cnt++;
	if (!num[x]) h1++;
	else if (num[x]==1) h2++;
	else h3++;
	for (int i=head[x];i;i=a[i].next)
	{
		int t=a[i].t;
		if (bb[a[i].from]) continue;
		bb[a[i].from]=true;cnt1++;
		if (!bo[t]) num[t]=(num[x]+a[i].v+3)%3,dfs(t);
		else if (num[t]!=(num[x]+a[i].v+3)%3) flag=true;
	}
}

int main()
{
	n=rd();m=rd();tot=0;
	for (int i=1;i<=m;i++)
	{
		int x=rd(),y=rd();
		add(x,y,1,i);add(y,x,-1,i);
	}
	ans=0LL;
	for (int i=1;i<=n;i++)
	{
		flag=false;
		h1=h2=h3=cnt=cnt1=0;
		dfs(i);
		if (flag) { ans+=(ll)cnt*cnt;continue; }
		if (!h1||!h2||!h3) { ans+=(ll)cnt1;continue; }
		ans+=(ll)h1*h2+(ll)h2*h3+(ll)h3*h1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6272
#include <iostream>
#include <utility>

constexpr int MaxN = 100000;

int imos[MaxN];

int main() {
	int n, m;
	std::cin >> n >> m;

	for (int i = 0; i < m; ++i) {
		int a, b;
		std::cin >> a >> b;

		if (a > b)
			std::swap(a, b);

		++imos[a - 1];
		--imos[b - 1];
	}

	for (int i = 0; i <= n; ++i) {
		if (i != 0)
			imos[i] += imos[i - 1];

		if (imos[i] % 2 == 1) {
			std::cout << "NO" << std::endl;
			return 0;
		}
	}

	std::cout << "YES" << std::endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    string s, t;
    cin >> s >> t;

    int n = s.size();
    vector<int> a(26), b(26);
    rep(i, n) {
        a[s[i]-'a']++;
        b[t[i]-'a']++;
    }
    sort(all(a)); sort(all(b));
    rep(i, 26) {
        if (a[i] != b[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000
#define MAX 200001

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

bool solve(ll N, ll A, ll B, vector<ll> &h, ll mid){
    ll cnt = 0;
    rep(i,N){
        ll now = h[i];
        if(now-B*mid <= 0) continue;
        if((now-B*mid) % (A-B) == 0){
            cnt += (now-B*mid) / (A-B);
        }
        else{
            cnt += (now-B*mid) / (A-B) + 1;
        }
    }
    if(cnt <= mid) return true;
    else return false;
}

int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> h(N);
    rep(i,N) cin >> h[i];
    ll left = 0;
    ll right = 10000000000;
    while(right-left>1){
        ll mid = (left + right) / 2;
        if(solve(N,A,B,h,mid)){
            right = mid;
        }
        else{
            left = mid;
        }
    }
    cout << right << endl;
}

Measured memory_bytes: 3948
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	int i,j,k=101,p=-1,n,m;
	cin>>s;
	for(i=0;i<s.length();i++){
		if(s[i]=='C'){
			for(j=i+1;j<s.length();j++){
			if(s[j]=='F'){
				cout<<"Yes"<<endl;
				return 0;
			} 
		}
	}
    }
    cout<<"No"<<endl;
}

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

const int Maxn=500;

int N,A[Maxn+5][Maxn+5];

void Solve(int l,int r,int id) {
	if(l==r)return;
	int mid=(l+r)>>1;
	for(int i=l;i<=mid;i++)
		for(int j=mid+1;j<=r;j++)
			A[i][j]=id;
	Solve(l,mid,id+1),Solve(mid+1,r,id+1);
}

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d",&N);
	Solve(1,N,1);
	for(int i=1;i<N;i++) {
		for(int j=i+1;j<N;j++)
			printf("%d ",A[i][j]);
		printf("%d\n",A[i][N]);
	}
	return 0;
}

Measured memory_bytes: 1408
from collections import Counter
N = int(input())

cnt = 0
counter1 = Counter()
#counter2 = Counter()
for i in range(1,N+1):
    left = str(i)[0]
    right = str(i)[-1]
    counter1[(left, right)] += 1
    #counter2[(right, left)] += 1

for i in range(1, N+1):
    left = str(i)[0]
    right = str(i)[-1]
    cnt += counter1[(right, left)]

print(cnt)


Measured memory_bytes: 40428
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-10; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}

//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	llint ans = 0, n = 0, m, count, sum = 0, ch = 0;
	llint s, a, aa, aaa, rr = 0, gg = 0, bb = 0,b;
	bool check = false;

	vector<llint> r, g;
	char c;
	cin >> aa>>aaa;
	a = min(aa, aaa);
	b = max(aa, aaa);
	llint i;
	while (1) {
		i++;
		if (b - i == i - a) {
			cout << i << endl; 
			break;
		}
		else if (i - a > b - i) {
			cout << "IMPOSSIBLE" << endl;
			break;
		}
	}
	
	please AC;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          string w = Input.ScanStr();
          for(int i=0;i<w.Length-1;i++){
            if(w.Substring(i,2)=="AC"){
              Console.WriteLine("Yes");
              return;
            }
          }
          
          Console.WriteLine("No");
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


//void warshall_floyd(int n){
//    for(int k=0;k<n;k++){
//        for(int i=0;i<n;i++){
//            for(int j=0;j<n;j++){
//                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
//            }
//        }
//    }
//}
//ll calc_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        ++res;
//        N /= 10;
//    }
//    return res;
//}
//ll sum_digit(ll N) {
//    ll res = 0;
//    while (N) {
//        res += N % 10;
//        N /= 10;
//    }
//    return res;
//}

int main(){
    string s; int n; cin >> s >> n;
    set<string> a;
    for(int i = 0;i <= s.length();i++){
        for(int j = 1;j <= n;j++){
            a.insert(s.substr(i,j));
        }
    }
    auto itr = a.begin();
    for(int i = 0;i < n;i++)++itr;
    cout << *itr;
}



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

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

using namespace std;

using edge=struct {int to,cap,rev;};
using G=vector<vector<edge>>;
const int inf=1<<29;

void add_edge(G &graph,int a,int b,int c){
	//cout << a << " " << b << " " << c << endl;
	graph[a].push_back({b,c,int(graph[b].size())});
	graph[b].push_back({a,0,int(graph[a].size()-1)});
}

int max_flow(G &graph,int s,int t){
	int n=graph.size(),flow=0;
	vector<int> used(n);

	auto dfs=[&](int v,int t,int f,const auto& self)->int{
		if(v==t) return f;
		used[v]=true;
		for(auto &e:graph[v]){
			if(used[e.to] || e.cap<=0) continue;
			int d=self(e.to,t,min(f,e.cap),self);
			if(d > 0){
				e.cap-=d;
				graph[e.to][e.rev].cap+=d;
				return d;
			}
		}
		return 0;
	};

	while(1){
		fill(begin(used),end(used),false);
		int f=dfs(s,t,inf,dfs);
		if(f==0) break;
		flow+=f;
	}
	return flow;
}

int main(void){
	int h,w,c,m,nw,nc,nm;
	while(cin >> h >> w >> c >> m >> nw >> nc >> nm){
		if(h==-1) break;

		const int ho=0,wo=h,co=h+2*(w+1),mo=h+2*(w+c+2);	
		const int s=h+2*(w+c+m+3);
		const int t=s+1;

		const int all=t+1;

		G graph(all);
		rep(i,h) add_edge(graph,s,ho+i,1);

		rep(i,w){
			int n,j;
			cin >> n;
			rep(loop,n){
				cin >> j;
				j--;
				add_edge(graph,ho+j,wo+2*i,1); 
			}
		}

		rep(i,h) add_edge(graph,ho+i,wo+2*w,inf);

		rep(i,w) add_edge(graph,wo+2*i,wo+2*i+1,1);
		add_edge(graph,wo+2*w,wo+2*w+1,nw);


		rep(i,c){
			int n,j;
			cin >> n;
			rep(loop,n){
				cin >> j;
				j--;
				add_edge(graph,wo+2*j+1,co+2*i,1); 
			}
		}

		rep(i,w) add_edge(graph,wo+2*i+1,co+2*c,inf);
		rep(i,c) add_edge(graph,wo+2*w+1,co+2*i,inf);

		rep(i,c) add_edge(graph,co+2*i,co+2*i+1,1);
		add_edge(graph,co+2*c,co+2*c+1,nc);


		rep(i,m){
			int n,j;
			cin >> n;
			rep(loop,n){
				cin >> j;
				j--;
				add_edge(graph,co+2*j+1,mo+2*i,1); 
			}
		}

		rep(i,c) add_edge(graph,co+2*i+1,mo+2*m,inf);
		rep(i,m) add_edge(graph,co+2*c+1,mo+2*i,inf);
		

		rep(i,m) add_edge(graph,mo+2*i,mo+2*i+1,1);
		add_edge(graph,mo+2*m,mo+2*m+1,nm);
		
		rep(i,m+1) add_edge(graph,mo+2*i+1,t,inf);

		cout << max_flow(graph,s,t) << endl;
	}
	return 0;
}

Measured memory_bytes: 3212