akhauriyash/Code-Regression huggingface dataset:
/*~~~~~~ !! Roopam Mishra !!
 
    " ॐ नमः शिवाय "
    
    जो वास्तविक नहीं है उससे कभी भी मत डरो.
    
    “And don’t you dare call this code pathetic, you foul — you evil little cockroach!!”
    Even I don't understand now what I wrote, yet you are not allowed to call this pathetic..
                                                                                ~~~~~~*/
 
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define MOD 1000000007
#define INF 1000000000000000000
#define endll "\n"
#define pb push_back
#define forn(i,n) for(i=0;i<n;i++)
#define forab(i,a,b) for(i=a;i<=b;i++)
#define vpll vector<pair<ll,ll>>
#define pll pair<ll,ll>
#define vll vector<ll>
#define ff first
#define ss second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define test ll t;cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main() 
{
	fast_io;
	string s1,s2;
	cin>>s1>>s2;
	ll n,m,i,j;
	n=s1.length();
	m=s2.length();
	string s="";
	ll lcs[n+1][m+1];
	for(i=0;i<=n;i++)
	{
	    for(j=0;j<=m;j++)
	    {
	        if(i==0 || j==0)
	        lcs[i][j]=0;
	        else
	        if(s1[i-1]==s2[j-1])
	        {
	            lcs[i][j]=1+lcs[i-1][j-1];
	        }
	        else
	        {
	            lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
	        }
	    }
	}
	i=n;j=m;
	while(i>0 && j>0)
	{
	    if(s1[i-1]==s2[j-1])
	    {
	        s+=s1[i-1];
	        i--;
	        j--;
	    }
	    else
	    if(lcs[i-1][j]>lcs[i][j-1])
	    {
	        i--;
	    }
	    else
	    {
	        j--;
	    }
	}
	reverse(s.begin(),s.end());
	cout<<s<<endll;
	return 0;
} 

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

using namespace std;

const int N = 5e5+1;
const int L = 3e4+1;

#define ll long long
#define pb push_back
#define fi first
#define se second
#define re return 0
#define fast ios_base::sync_with_stdio(false)
int n, m, l, r, q, b, a[N], ans;

string s;
int main () {

    fast;

    cin >> n >> m >> q;
    
    if (n+m+q>=22) cout << "bust";
    else cout << "win";
}


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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
// #define MOD 998244353
#define VL vector<ll>

vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main()
{
	ll N, M;
	cin >> N >> M;
	vector<vector<ll>> v(M);
	REP(i, M) {
		ll a, b;
		cin >> a >> b;
		v[i].push_back(a);
		REP(j, b) {
			ll c;
			cin >> c;
			c--;
			v[i].push_back(c);
		}
	}

	vector<ll> dp(pow(2, N)+1, INF);
	dp[0] = 0;
	REP(i, pow(2, N)+1) {
		ll tmp = 0;
		REP(j, N) {
			if ((i >> j) & 1LL) tmp += pow(2, j);
		}
		REP(j, M) {
			ll ind = tmp;
			REP(k, v[j].size()-1) {
				if (!((tmp >> v[j][k+1]) & 1LL)) ind += pow(2, v[j][k+1]);
			}
			// PRINT(ind);
			dp[ind] = min(dp[ind], dp[i] + v[j][0]);
		}
	}
	// REP(i, pow(2, N)) {
	// 	cout << dp[i] << " ";
	// }
	// cout << endl;
	if (dp[pow(2, N)-1] == INF) {
		PRINT(-1);
	} else {
		PRINT(dp[pow(2, N)-1]);
	}
	return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  if(A > 12) {
    cout << B << endl;
  } else if (A > 5) {
    cout << B / 2 << endl;
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> prl;
typedef vector<ll> vcl;
typedef map<ll,ll> mapl;
typedef unordered_map<ll,ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 998244353;

//Binomial Coefficients
const ll c_max = 1e6+5;
ll fac[c_max], finv[c_max], inv[c_max];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep(i,2,c_max-1){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
ll COM(ll comn, ll comk){
    if (comn < comk) return 0;
    if (comn < 0 || comk < 0) return 0;
    if (comn >= c_max){
    ll cret = finv[comk];
    rep(i,0,comk-1) cret = (cret * (comn - i)) % mod;
    return cret;
    }
    return fac[comn] * (finv[comk] * finv[comn - comk] % mod) % mod;
}

//Power
ll powmod(ll px, ll py, ll pmod){
    if(py == 0) return 1;
    if(py % 2 == 0) return powmod((px * px) % pmod, py / 2, pmod);
    else return (px * powmod(px, py - 1, pmod)) % pmod;
} 
ll mypow(ll px, ll py){
    if(py == 0) return 1;
    if(py % 2 == 0) return mypow((px * px), py / 2);
    else return (px * mypow(px, py - 1));
}

int main() {
    // your code goes here
    COMinit();
    ll n,m,k,ans=0;
    cin >> n >> m >> k;
    rep(i,0,k){
        ans=(ans+powmod(m-1,n-1-i,mod)*COM(n-1,i)%mod)%mod;
    }
    ans=ans*m%mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27072
using System;

namespace ITP1_7_B
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var input = Console.ReadLine().Split(' ');
                int n = Int32.Parse(input[0]);
                int x = Int32.Parse(input[1]);
                if (n == 0 && x == 0) { return; }
                int count = 0;
                for (int i = 1; i <= n - 2; i++)
                {
                    for (int j = i + 1; j <= n - 1; j++)
                    {
                        for (int k = j + 1; k <= n; k++)
                        {
                            if (i + j + k == x)
                            {
                                count++;
                            }
                        }
                    }
                }
                Console.WriteLine("{0}", count);
            }

        }
    }
}

Measured memory_bytes: 9180
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n, k;
    int sum=0;
    int l[55];
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }

    sort(l, l + n, greater<int>());
    for (int i = 0; i < k; i++) {
        sum += l[i];
    }
    cout << sum << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n%2 == 0) return false;
    if(n%3 == 0) return false;
    // 2と3の倍数でないので6の倍数ではないことが保証された

    if(n%6 != 1 && n%6 != 5) return false;
    // 6の倍数前後の数(素数かもしれない数)であることが保証された

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i=5;i*i<=n;i+=6){
        if(n%i     == 0) return false; // 6n-1
        if(n%(i+2) == 0) return false; // 6n+1
    }

    return true;
}

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

    for (long long i = x; ; i++) {
        if (is_prime(i)) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 888
import java.util.Scanner

fun main(args : Array<String>) {
        val scn = Scanner(System.`in`)
        val a = scn.nextInt()
        val b = scn.nextInt()
        val ans = if (a >= 13) {
                b
        }
        else if (a >= 6) {
                b / 2
        }
        else {
                0
        }
        println(ans)
}


Measured memory_bytes: 31404
import itertools
S=list(input())

answer=0
for perm in itertools.product([True,False],repeat=len(S)-1):
  #print(perm)
  eval_str=""
  for i in range(len(S)-1):
    eval_str+=S[i]
    if perm[i]:
      eval_str+="+"
  eval_str+=S[len(S)-1]
  
  #print(eval_str)
  answer+=eval(eval_str)
  
print(answer)

Measured memory_bytes: 3060
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: usize,
        a: [i32; n - 1],
    }
    let mut ans = vec![0; n];
    for i in a {
        ans[i as usize - 1] += 1;
    }
    for i in ans {
        println!("{}", i);
    }
}


Measured memory_bytes: 4716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





bool comp(pair<ll, ll> a, pair<ll, ll> b) {
    return a.S < b.S;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    
    int n;
    while (cin >> n && n) {
        vector<pair<ll, ll> > v(n);
        rep(i, n) cin >> v[i].F >> v[i].S;
        sort(all(v), comp);
        
        ll dp[n + 1][43]; // 総移動距離を最小にしたい
        // バルーン3個までしか持てんのかい!!
        // i番目の風船(1indexed), i番目にいったときの風船の数
        fill_n(*dp, (n + 1) * 43, 1e18);
        dp[0][0] = 0;
        
        rep(i, n) rep(j, 4) {
            if (dp[i][j] == 1e18) continue;
            // 直接行く
            ll p = (i == 0 ? 0 : v[i - 1].F);
            ll t = (i == 0 ? 0 : v[i - 1].S);
            if ((j + 1) * abs(v[i].F - p) <= v[i].S - t) {
                chmin(dp[i + 1][j + 1], dp[i][j] + abs(v[i].F - p));
            }
            // 一旦帰る
            if ((j + 1) * p + v[i].F <= v[i].S - t) {
                chmin(dp[i + 1][1], dp[i][j] + p + v[i].F);
            }
        }
        rep(i, n + 1) {
            int flg = 0;
            rep(j, 4) if (dp[i][j] != 1e18) { flg = 1; break; }
            if (flg == 0) {
                cout << "NG " << i << endl;
                break;
            }
            if (i == n) {
                ll ans = 1e18;
                rep(i, 4) chmin(ans, dp[n][i]);
                cout << "OK " << ans + v[n - 1].F << endl;
            }
        }
        // rep(i, n + 1) { rep(j, n + 1) cout << dp[i][j] << " "; cout << endl; }
        // rep(j, n + 1) cout << dp[n][j] << " "; cout << endl;
    }
}






Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
const int N =200;
int main()
{
    int n;
    char s[N];
    while(~scanf("%d",&n))
    {
        scanf("%s",s);
        if(n&1)
        {
            printf("No\n");
            continue;
        }
        
        int flag =0;
        for(int i=n/2;i<n;i++)
        {
            if(s[i-n/2]!=s[i])
                flag++;
        }
        if(!flag)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 2000001
#define INF 200000000
int left(int);
int right(int);
void buildMaxHeap();
void maxHeapify(int);
void maxHeapInsert(int);
int parent(int);
void heapIncreaseKey(int, int);
int extract();

int A[MAX];
int n;

void maxHeapify(int i){
  int largest,l,r,tmp;
  l = left(i);
  r = right(i);
   
  if (l<=n && A[l]>A[i])  largest = l;
  else  largest = i;
  
  if(r<=n && A[r]>A[largest])  largest = r;
  if (largest != i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(largest);
  }
}
int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}
int parent(int i){
  return i/2;
}

void buildMaxHeap(){
  int i;  
  for(i=n/2;i>0;i--) maxHeapify(i);
}
	  
void maxHeapInsert(int k){
  n++;
  A[n] = -INF;
  heapIncreaseKey(n,k);
}
 
void heapIncreaseKey(int i, int k){
   int temp;
   
  A[i] = k;
  while(i>1 && A[parent(i)] < A[i]){
    temp = A[i];
    A[i] = A[parent(i)];
    A[parent(i)] = temp;
    i = parent(i);
  }   
}
int extract(){
  int max = A[1];
  A[1] = A[n];
  n--;
  maxHeapify(1);
   
  return max;
}

     
int main(){
  int n,i;
  char C[10];

 
  while(1){
    scanf("%s",C);
    
    if(C[2]=='s'){
      scanf("%d",&n);
      maxHeapInsert(n);
    }
    else if(C[2] == 't'){
      printf("%d\n",extract());
    }
    else if(C[2]=='d'){
      break;
    }
  }
  return 0;
}

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

int main(){
	int num[1000010], num2[1000010];
	for(int i=0; i< 1000010; i++) num[i] = num2[i] = 10e8;
	num[0] = num2[0] = 0;
	for(int j=0; j< 1000010; j++){
		for(int i=0; i < 1200; i++){
			int m = i*(i+1)*(i+2)/6;
			if(1000010 <= m+j) continue;
			num[j+m] = min(num[j]+1, num[j+m]);

			if(m == 0) continue;
			if(m%2 == 0) continue;
			num2[j+m] = min(num2[j]+1, num2[j+m]);
		}
	}
	int n;
	while(cin >> n, n){
		cout << num[n] << " " << num2[n] << endl;
	}
}

Measured memory_bytes: 8968
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <string>
#include <stdio.h>

using namespace std;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair





int main()
{
    int n ;
    scanf("%d",&n);
    ll sum=0 ;
    for(ll i=1 ; i<=n ; i++)
    {
        if( i%3!=0 && i%5!=0 )
            sum+=i;
    }printf("%lld\n",sum);

}




Measured memory_bytes: 3232
N = int(input())
A = list(map(int, input().split()))

stock = 0
money = 1000
for i in range(N-1):
    if A[i+1] >= A[i]:
#         print('Buy')
        stock += money // A[i]
        money = money % A[i]
    else:
#         print('Sell')
        money += stock*A[i]
        stock = 0
        
#     print('money:{}',format(money))
#     print('stock:{}',format(stock))
            
# 最終日に株を持っているなら、それを売って所持金にする。
money += stock*A[N-1]
stock = 0 # この処理いらないけど一応。

print(money)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair
int n;

int main(){

cin >> n;
while(n>0){
    int r = n%10;
    if(r==9)return 0*printf("Yes");
    n/=10;
}
cout << "No";

return 0;}


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

int main()
{
	int h,m,s;
	int hh,mm,ss;
	for(int i=0;i<3;i++){
		cin >> h >> m >> s;
		cin >> hh >> mm >> ss;
		int a,b,c;
		a = hh-h;
		b = mm-m;
		c = ss-s;
		if(c < 0){
			b--;
			c+=60;
		}
		if(b < 0){
			a--;
			b+=60;
		}
		cout << a << " " << b << " " << c << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using pii = pair<int, int>;
const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55);
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
template<typename T, typename U> inline void chmax(T &x, U y) { if (x < y) x = y; }
template<typename T, typename U> inline void chmin(T &x, U y) { if (x > y) x = y; }


int main() {
    int n, a, b;
    cin >> n;
    if (n == 1) {
        puts("Hello World");
        return 0;
    }
    cin >> a >> b;
    cout << a + b << "\n";

    return 0;
}


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

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    vector<int> s(n);
    rep(i,n) cin >> s[i];
    
    sort(s.begin(), s.end());
    
    int sum = 0;
    rep(i,n) sum += s[i];
    
    if(sum % 10 != 0) cout << sum << endl;
    else {
        bool flag = false;
        for(int i = 0; i < n; i++){
            int ans = sum;
            ans -= s[i];
            if(ans % 10 != 0){
                flag = true;
                cout << ans << endl;
                break;
            }
        }
        if(!flag) cout << 0 << endl;
    }
}


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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

//#define int int64_t
int a[N+2];

int32_t  main(){
  IOS;

  for(int i=0;i<5;++i)cin>>a[i];
  int tim=1e5;
  vi v;
  for(int i=0;i<5;++i)v.pb(a[i]);
  sort(all(v));
  do{
    int cnt=0;
    int prev=0;
    bool del=false;
    for(int i=0;i<=100*1000;++i){

      if(i-prev>=v[cnt] && del==false){
        del=true;
//        cout<<i<<"del\n";
        prev=i;
        cnt++;
      }
      if(i%10==0 && del==true ){
        del=false;
        prev=i;
      }
      if(cnt>=5){
//        cout<<i<<endl;
      tim=min(i,tim);
        break;
        //return 0;
      }
    }  

  }while(next_permutation(all(v)));
  cout<<tim<<endl;


  return 0;
}



Measured memory_bytes: 256
def test(x):
  x = x % 10
  if(x == 2 or
     x == 4 or
     x == 5 or
     x == 7 or
     x == 9):
    print('hon')
  elif(x == 0 or
       x == 1 or
       x == 6 or
       x == 8):
    print('pon')
  else:
    print('bon')
    
test(int(input()))

Measured memory_bytes: 61704
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k,pos;
    cin>>n>>k;
    vector<int>x;
    int ans=0;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
    }
        cout << (n-1 + (k-2))/(k-1) << endl;

	return 0;
}


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

const int MOD = 1e9 + 7;

signed main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);

  for (int i = 0; i < N; i++) cin >> S[i];
  for (int i = 0; i < M; i++) cin >> T[i];

  static int dp[2020][2020];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < 2020; i++) dp[i][0] = dp[0][i] = 1;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD;
      if (S[i] != T[j]) {
        dp[i + 1][j + 1] = (dp[i + 1][j + 1] - dp[i][j] + MOD) % MOD;
      }
    }
  }

  cout << dp[N][M] << endl;
  return 0;
}


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

int main(){
    int n,ans=0;
    cin >>n;
    string s;
    map<string,int> mp;
    rep(i,n){
        cin >>s;
        mp[s]++;
        if(mp[s]==1){ans++;}
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 19228
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, m, x, y) = in.readLine().split("\\s+").map(_.toInt)
    val xs = in.readLine().split("\\s+").map(_.toInt)
    val ys = in.readLine().split("\\s+").map(_.toInt)

    val xsMax = xs.max
    val ysMin = ys.min

    out.println(
      if (xsMax >= ysMin) {
        "War"
      } else if (x < xsMax && xsMax < y || xsMax <= x && x < ysMin) {
        "No War"
      } else {
        "War"
      }
    )

    out.flush()
  }
}


Measured memory_bytes: 27196
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    string s;
    cin >> s;

    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

	return 0;
}

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

void bfs(vector<vector<int>> &G, vector<int> &dist, vector<int> &prev, int start) {
    dist[start] = 0;
    queue<int> q;
    q.push(start);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int next_v : G[v]) {
            if (dist[next_v] != -1) continue;
            dist[next_v] = dist[v] + 1;
            prev[next_v] = v;
            q.push(next_v);
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    
    vector<int> dist(N, -1), prev(N, -1);
    bfs(G, dist, prev, 0);

    cout << "Yes" << endl;
    for (int i = 1; i < N; i++) cout << prev[i] + 1 << endl;
}

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

const int MAXN = 100010;
typedef long long LL;
LL xs[MAXN], ys[MAXN], D;
int n, X, Y;
typedef std::pair<LL, LL> pi;
std::map<pi, int> id;
typedef std::vector<LL> VI;
typedef std::map<LL, VI> M;
M mx, my, cx, cy;
int ansl[MAXN], fa[MAXN];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void merge(int x, int y) { fa[find(x)] = find(y); }
void chk(int x, pi y) { if (id.count(y)) --ansl[x], merge(x, id[y]); }
void con(int x, M & m, M & e, LL i, LL L, LL R, bool b) {
	if (!m.count(i)) return ;
	VI & t = m[i];
	int l = std::lower_bound(t.begin(), t.end(), L) - t.begin();
	int r = std::upper_bound(t.begin(), t.end(), R) - t.begin();
	if (l == t.size() || t[l] > R) return ;
	ansl[x] += r - l;
	merge(x, id[b ? pi(t[l], i) : pi(i, t[l])]);
	merge(x, id[b ? pi(t[r - 1], i) : pi(i, t[r - 1])]);
	e[i][l] = r - 1;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> X >> Y;
	for (int i = 1, x, y; i <= n; ++i) {
		std::cin >> x >> y;
		fa[i] = id[pi(xs[i] = x + y, ys[i] = x - y)] = i;
	}
	D = std::max(std::abs(xs[X] - xs[Y]), std::abs(ys[X] - ys[Y]));
	for (int i = 1; i <= n; ++i)
		mx[xs[i]].push_back(ys[i]), my[ys[i]].push_back(xs[i]);
	for (auto & t : mx) {
		std::sort(t.second.begin(), t.second.end());
		cx[t.first] = VI(t.second.size(), 0);
	}
	for (auto & t : my) {
		std::sort(t.second.begin(), t.second.end());
		cy[t.first] = VI(t.second.size(), 0);
	}
	for (int i = 1; i <= n; ++i) {
		con(i, mx, cx, xs[i] - D, ys[i] - D, ys[i] + D, 0);
		con(i, mx, cx, xs[i] + D, ys[i] - D, ys[i] + D, 0);
		con(i, my, cy, ys[i] - D, xs[i] - D, xs[i] + D, 1);
		con(i, my, cy, ys[i] + D, xs[i] - D, xs[i] + D, 1);
		chk(i, pi(xs[i] - D, ys[i] - D));
		chk(i, pi(xs[i] - D, ys[i] + D));
		chk(i, pi(xs[i] + D, ys[i] - D));
		chk(i, pi(xs[i] + D, ys[i] + D));
	}
	for (auto & i : cx) {
		LL x = i.first;
		VI & t = i.second; const int sz = t.size();
		for (int j = 1; j < sz; ++j) {
			t[j] = std::max(t[j], t[j - 1]);
			if (t[j - 1] > j - 1) merge(id[pi(x, mx[x][j - 1])], id[pi(x, mx[x][j])]);
		}
	}
	for (auto & i : cy) {
		LL y = i.first;
		VI & t = i.second; const int sz = t.size();
		for (int j = 1; j < sz; ++j) {
			t[j] = std::max(t[j], t[j - 1]);
			if (t[j - 1] > j - 1) merge(id[pi(my[y][j - 1], y)], id[pi(my[y][j], y)]);
		}
	}
	LL ans = 0;
	for (int i = 1; i <= n; ++i) if (find(i) == find(X)) ans += ansl[i];
	std::cout << ans / 2 << std::endl;
	return 0;
}


Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


int main(void){
    int n;
    using P = pair<pair<string, int>, int>;
    cin >> n;
    vector<P> vp(n);
    rep(i,n){
        string s;
        int p;
        cin >> s >> p;
        vp[i] = {{s,-p},i+1};
    }
    sort(all(vp));
    rep(i,n){
        cout << vp[i].second << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string s; cin>>s;
    stack<char>hoge;
    rep(i,(ll)s.size()){
        if(s[i]=='S'){
            hoge.push('S');
        }else{
            if(hoge.size()&&hoge.top()=='S'){
                hoge.pop();
            }else{
                hoge.push('T');
            }
        }
    }
    cout<<hoge.size()<<endl;
}

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

int main(void){
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    vector<long long> result(4);
    result.at(0) = a*c;
  	result.at(1) = a*d;
  	result.at(2) = b*c;
  	result.at(3) = b*d;
    cout << *max_element(result.begin(), result.end()) << endl;
}

Measured memory_bytes: 3628
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(const int s = 0, const int d = 0, const Weight w = 0) : src(s), dst(d), weight(w) {}
};

using Edges = std::vector<Edge>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

class Graph {
  std::vector<Edges> g;
  using iterator = std::vector<Edges>::iterator;
  using const_iterator = std::vector<Edges>::const_iterator;

public:
  Graph(const int size = 0) : g(size) {}
  size_t size() const { return g.size(); }
  const Edges &operator[](const int i) const { return g[i]; }
  void addArc(const int src, const int dst, const Weight w = 1) { g[src].emplace_back(src, dst, w); }
  void addEdge(const int node1, const int node2, const Weight w = 1) {
    addArc(node1, node2, w);
    addArc(node2, node1, w);
  }
  iterator begin() { return g.begin(); }
  const_iterator begin() const { return g.begin(); }
  iterator end() { return g.end(); }
  const_iterator end() const { return g.end(); }
};

template<int inf = std::numeric_limits<Weight>::max() / 8> Matrix warshallFloyd(const Graph &g) {
  int n = g.size();
  Matrix d(n, Array(n, inf));
  rep(i, n) d[i][i] = 0;
  for (auto &adj : g) {
    for (auto &e : adj) cmin(d[e.src][e.dst], e.weight);
  }
  rep(k, n) rep(i, n) rep(j, n) {
    if (d[i][k] != inf && d[k][j] != inf) cmin(d[i][j], d[i][k] + d[k][j]);
  }
  return d;
}

main {
  int n, m;
  cin >> n >> m;
  Graph g(n);
  while (m--) {
    int s, t;
    cin >> s >> t;
    g.addArc(s, t, -1);
  }
  Matrix dist = warshallFloyd(g);
  bool hasCycle = false;
  rep(i, n) hasCycle |= dist[i][i] < 0;
  cout << hasCycle << endl;
}

Measured memory_bytes: 3188
a,b,c,x,y=map(int,input().split())
p = a*x + b*y
q = 2*c*max(x,y)
r = 2*c*x + b*(y-x)
s = 2*c*y + a*(x-y)
if x >=y:
        print(min(p,q,s))
else:
        print(min(p,q,r))

Measured memory_bytes: 9192
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    vector<vector<int>> g(n);
    rep(i,m) {
        int a,b; cin>>a>>b; --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    vector<int> dp(n,INF),prev(n,INF);
    queue<int> q;
    q.push(0);
    dp[0] = 0;
    while (!q.empty()) {
        int cur = q.front(); q.pop();
        for (auto &&e: g[cur]) {
            if (chmin(dp[e], dp[cur]+1)) {
                q.push(e);
                prev[e] = cur;
            }
        }
    }

    cout << "Yes" << '\n';
    for (int i = 1; i < n; ++i) {
        cout << prev[i]+1 << '\n';
    }
    return 0;
}

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

#define ll              long long int
#define scan(any)       for(auto &i:any) cin>>i;
#define print(any)      for(auto i:any) cout<<i<<" "; 
#define endl            '\n'
#define pb              push_back
#define vll             vector<ll> 
#define f(i,x,y)        for(i=x;i<y;i++)
#define INF             LLONG_MAX
#define fast            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define s(x)            sort(x.begin(),x.end())
#define all(v)          v.begin(),v.end()
#define p2(n,x)         cout << fixed << setprecision(x) <<n<<endl; 
#define pll             pair<ll,ll> 
#define ff              first
#define ss              second
#define blt(x)          __builtin_popcount(x)

void solve()
{
    ll i,j,k,n;
    cin>>n;
    ll ans=0;
    ll mx=-100;
    f(i,0,n)
    {
        cin>>j>>k;
        if(j==k)
            ans++;
        else
        {
            mx=max(mx,ans);
            ans=0;
        }
    }
    mx=max(mx,ans);
    if(mx>=3)
        cout<<"Yes";
    else
        cout<<"No";
}

int main()
{
    
    fast
    ll t = 1;

    while(t--)
    solve();
    
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<set>
#include<vector>
#include<array>
#include<algorithm>
#include<chrono>

uint64_t xor64(void) {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 7);
  return x = x ^ (x >> 9);
}

auto b_cl = std::chrono::system_clock::now();
inline double get_time() {
  auto e_cl = std::chrono::system_clock::now();
  double msec = std::chrono::duration_cast<std::chrono::milliseconds>(e_cl - b_cl).count();
  return msec;
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(auto& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(auto& si: s[d]) std::cin >> si;
  }
  std::vector<int> t(D);
  {
    int sum = 0;
    for(int ci: c) sum += ci;
    std::vector<int> sc(26, 0);
    int d = 0;
    for(;;) {
      for(int i = 0; i < 26; ++i) sc[i] += c[i];
      for(int i = 0; i < 26; ++i) if(sc[i] >= sum) {
        if(d < D) { t[d] = i; ++d; }
        sc[i] -= sum;
      }
      if(d >= D) break;
    }
  }
  std::set<int> last[26];
  for(auto& li: last) li.insert(-1); // sentinel
  int ans = 0;
  for(int d = 0; d < D; ++d) {
    int t1 = t[d];
    ans += s[d][t1];
    last[t1].insert(d);
    for(int i = 0; i < 26; ++i) {
      ans -= c[i]*(d - *last[i].rbegin());
    }
  }
  for(auto& li: last) li.insert(D); // sentinel
  
  // additional score when t[d] = i compare to t[d] = -1
  auto sum_up = [](int d) { return d*(d-1)/2; };
  auto score = [&](int d, int i)->int {
    int res = s[d][i];
    auto it = last[i].lower_bound(d);
    int nd = *it;
    int pd = *--it;
    int diff = sum_up(d-pd) + sum_up(nd-d) - sum_up(nd-pd);
    res -= c[i]*diff;
    return res;
  };
  int lm = 0, renew = 0;
  int sc[26];
  auto one_day = [&](int d) {
    int pi = t[d];
    last[pi].erase(d);
    for(int i = 0; i < 26; ++i) sc[i] = score(d, i);
    int mi = std::max_element(sc, sc+26) - sc;
    if(mi != pi) {
      ans += sc[mi] - sc[pi];
      ++renew;
    }
    last[mi].insert(d);
  };
  
  // hill climbing
  int range = 16;
  for(int rep = 0;; ++rep) {
    if((xor64()>>25)%2) {
      one_day(xor64()%365);
    } else {
      // swap
      int d1 = xor64()%D, d2 = xor64()%D;
      while(d1 < d2-range || d2 < d1-range || t[d1] == t[d2]) {
          d1 = xor64()%D; d2 = xor64()%D;
      }
      int pi1 = t[d1], pi2 = t[d2];
      last[pi1].erase(d1);
      int diff = score(d1, pi2) - score(d1, pi1);
      last[pi2].insert(d1);
      last[pi2].erase(d2);
      diff += score(d2, pi1) - score(d2, pi2);
      if(diff > 0) {
        last[pi1].insert(d2);
        t[d1] = pi2;
        t[d2] = pi1;
        lm = 0;
      } else {
        last[pi2].insert(d2);
        last[pi2].erase(d1);
        last[pi1].insert(d1);
      }
    }
    if(rep%100 == 0) {
      int x = get_time();
      if(x > 1980) break;
      //if(x > 200) range = 25;
      //if(x > 400) range = 20;
      //if(x > 700) range = 15;
      //if(x > 1000) range = 10;
    }
  }
  for(auto ti: t) std::cout << ti+1 << "\n";
  return 0;
}


Measured memory_bytes: 3744
#include <stdio.h>
#include <math.h>

int main (void){
	int n; //じゃんけん回数
	int k; //k回前の手は出せない
	int r, s, p; //グー、チョキ、パーの点数
	long int sum =0; //合計点数
	int i; //for文用
	char t[100000];
	//改行した後の最初に%*cを記述することで改行文字を読み飛ばす
	scanf("%d%d%*c%d%d%d%*c%s", &n, &k, &r, &s, &p, t);
	for(i=0; i<n; i++){
		if(i-k>=0 ){
			if(t[i-k]== t[i])
			t[i]= 'o';
		}
		//点数配点間違えてt[i]はあくまで機体の手、勝つのは別の手
		switch (t[i]){
			case 'r':
						sum +=p;
						break;
			case 's':
						sum +=r;
						break;
			case 'p':
						sum +=s;
						break;
			default:
						break;
						
		}
	}
	printf("%ld", sum);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#define mod 1000000007
using namespace std;
typedef long long ll;
bool chmax(ll &a,ll b){
    if(a>b)return 0;
    a=b; return 1;
}
bool chmin(ll &a,ll b){
    if(a<b)return 0;
    a=b; return 1;
}

vector<string> v;
int main(){
    string s; ll k;
    cin>>s>>k;
    for(int i=0;i<s.size();i++)for(int j=1;j<=5&&i+j<=s.size();j++){
	v.push_back(s.substr(i,j));
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    cout<<v[k-1]<<endl;
}


Measured memory_bytes: 1660
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  6 11:36:14 2019

@author: Yamazaki Kenichi
"""

n = int(input())
A = [[]]
A = A + [list(map(int,input().split())) for i in range(n)]

def dfs(k):
    global counta
    for i in range(A[k][1]):
        if T[A[k][i+2]][0] == -1:
            T[A[k][i+2]][0] = 0
            T[A[k][i+2]][1] = counta
            counta += 1
            dfs(A[k][i+2])
    T[k][2] = counta
    T[k][0] = 1
    counta += 1

T = [[-1,-1,-1] for i in range(n+1)]
counta = 1
for i in range(1,n+1):
    if T[i][0] == -1:
        T[A[i][0]][0],T[A[i][0]][1] = 0, counta
        counta += 1
        dfs(i)

for i in range(1,n+1):
    print(" ".join(map(str,[i,T[i][1],T[i][2]])))



Measured memory_bytes: 5652
a, b = map(int, input().split())

if b<10:
  c = 10*a + b
elif b == 100:
  c = 1000*a + b
else:
  c = 100*a + b

for i in range(316):
  if c == i**2:
    print("Yes")
    c = 0
    break

if c !=0:
  print("No")


Measured memory_bytes: 3060
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    if(N == 1){
      int count1 = 0;
      int K1 = sc.nextInt();
      for(int i = 0; i < K1 ; i++){
        int love = sc.nextInt();
        if(love <= M){
          count1++;
        }
      }
      
      System.out.println(count1);
      
    }else{
    
    ArrayList<Integer> love = new ArrayList<Integer>();
    for(int i = 0; i < N ; i++){
      int K = sc.nextInt();
      int[] list = new int[K];
       for(int j = 0; j < K ; j++){
         list[j] = sc.nextInt();
         love.add(list[j]);
       }   
    }
      
    Collections.sort(love);
 
    ArrayList<Integer> countAll = new ArrayList<Integer>();
    int count = 0;
    for(int i = 1; i <= M  ; i++){
      for(int j = 0; j < love.size(); j++){
        int jd = love.get(j);
        if(jd == i){
          count = count + 1;
        }
      }
      countAll.add(count);
      count = 0;
    }
      
    int lastCount = 0;
    for(int i = 0; i < countAll.size() ; i++){
      if(countAll.get(i) == N){
        lastCount++;
      }
    }
    System.out.println(lastCount);   
    }
  }  
}

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

class AC
{
  public void Do()
  {
    var N = Split.Long();
    var A = Split.Long(); 
    var B = Split.Long();

    if ((Math.Abs(A - B) % 2) == 0)
    {
      Console.WriteLine(Math.Abs(A - B)/2);
      return;
    }

    var a = Math.Min(A-1,N-A);
    var b = Math.Min(B-1,N-B);
    if (a > b)
    {
      var tmp = B;
      B = A;
      A = tmp;
    }
    if (A - 1 > N - A)
    {
      A = N - A+1;
      B = N - B+1;
    }

    Console.WriteLine(A + (B-A)/2);
  
 }

#if !piyo
  static void Main(string[] args)
  {
    new AC().Do();
  }
#endif
}

static class Split
{  public static string String()
  {
    if (_ss.Count == 0)
    {
      var s = Console.ReadLine();
      if (s == null)
        return null;

      _ss = s.Split(_delim).ToList();
    }

    var ret = _ss[0];
    _ss.RemoveAt(0);
    return ret;
  }

  public static int Int()
  {
    var str = String();
    return int.Parse(str);
  }
  public static long Long()
  {
    var str = String();
    return long.Parse(str);
  }

  static List<string> _ss = new List<string>();
  static char[] _delim = new[] { '\t', ' ' };
}

Measured memory_bytes: 11220
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>

//fast(?) Input
#define buf_sz 1<<24
char buf[buf_sz];
unsigned int nextint(){
	static int id = 0;
	if(id == 0)read(0, buf, buf_sz);
	unsigned int res = 0;
	while(id<buf_sz && buf[id]<'0' || '9'<buf[id])id++;
	while(id<buf_sz && '0'<=buf[id] && buf[id]<='9'){
		res *= 10;
		res += buf[id++] - '0';
	}if(id>=buf_sz)exit(1);
	return res;
}

long modpow(long x, long y, long m){
	long res = 1;
	while(y){
		if(y&1)res = res * x % m;
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

const long mod = 998244353;
const long pr = 3;

void butterfly(long a[], int h){
	static bool first = true;
	static long sum_e[30];
	if(first){
		first = false;
		long es[30], ies[30];
		int cnt2 = __builtin_ctz(mod - 1);
		long e = modpow(pr, (mod-1)>>cnt2, mod);
		long ie = modpow(e, mod-2, mod);
		for(int i=cnt2; i>=2; i--){
			es[i-2] = e;
			ies[i-2] = ie;
			e = e * e % mod;
			ie = ie * ie % mod;
		}
		long now = 1;
		for(int i=0; i<=cnt2-2; i++){
			sum_e[i] = es[i] * now % mod;
			now = now * ies[i] % mod;
		}
	}
	for(int ph=1; ph<=h; ph++){
		int w = 1<<(ph-1), p=1<<(h-ph);
		long now = 1;
		for(int s=0; s<w; s++){
			int offset = s<<(h-ph+1);
			for(int i=0; i<p; i++){
				long l = a[i+offset],
					 r = a[i+offset+p] * now % mod;
				a[i+offset] = (l + r) % mod;
				a[i+offset+p] = (l - r + mod) % mod;
			}
			now = now * sum_e[__builtin_ctz(~s)] % mod;
		}
	}
}
void butterfly_inv(long a[], int h){
	static bool first = true;
	static long sum_ie[30];
	if(first){
		first = false;
		long es[30], ies[30];
		int cnt2 = __builtin_ctz(mod - 1);
		long e = modpow(pr, (mod-1)>>cnt2, mod);
		long ie = modpow(e, mod-2, mod);
		for(int i=cnt2; i>=2; i--){
			es[i-2] = e;
			ies[i-2] = ie;
			e = e * e % mod;
			ie = ie * ie % mod;
		}
		long now = 1;
		for(int i=0; i<=cnt2-2; i++){
			sum_ie[i] = ies[i] * now % mod;
			now = now * es[i] % mod;
		}
	}
	for(int ph=h; ph>=1; ph--){
		int w = 1<<(ph-1), p=1<<(h-ph);
		long inow = 1;
		for(int s=0; s<w; s++){
			int offset = s<<(h-ph+1);
			for(int i=0; i<p; i++){
				long l = a[i+offset],
					 r = a[i+offset+p];
				a[i+offset] = (l + r) % mod;
				a[i+offset+p] = (l - r + mod) * inow % mod;
			}
			inow = inow * sum_ie[__builtin_ctz(~s)] % mod;
		}
	}
}

long *convolution(long a[], int n, long b[], int m){
	int t = 0;
	while(n+m-1 > (1<<t))t++;
	if(t > 26)exit(1);
	long *c = (long*)calloc(1<<t, sizeof(long));
	memcpy(c, a, sizeof(long) * n);
	long *d = (long*)calloc(1<<t, sizeof(long));
	memcpy(d, b, sizeof(long) * m);
	butterfly(c, t); butterfly(d, t);
	for(int i=0; i<(1<<t); i++)c[i] = c[i] * d[i] % mod;
	free(d);
	butterfly_inv(c, t);
	long inv = modpow(1<<t, mod-2, mod);
	for(int i=0; i<(1<<t); i++)c[i] = c[i] * inv % mod;
	return c;
}

long A[1<<19], B[1<<19];
int main(){
	int N = nextint(), M = nextint();
	for(int i=0; i<N; i++)A[i] = nextint();
	for(int i=0; i<M; i++)B[i] = nextint();
	long *C = convolution(A, N, B, M);
	for(int i=0; i<N+M-1; i++){
		if(i)putchar(32);
		printf("%ld", C[i]);
	}putchar(10);
	return 0;
}

Measured memory_bytes: 37388
program Project1;
     
{$APPTYPE CONSOLE}
     
uses
  SysUtils;
var
  a,h,w,i,j,count,count2,x,y,sw,m,n,b,c,soeji,sum,max,k:Integer;
  l:array of Integer;
  s,s123,s1,s2,s3:string;
  al:string = 'abcdefghijklmnopqrstuvwxyz';
  tf,tfl,tfr:Boolean;
begin
  try
    { TODO -oUser -cConsole メイン : ここにコードを記述してください }
    Read(n);
    Read(m);
    Readln(x);  
    count :=0;
    count2:=0;
    max   :=0;

    for i := 0 to m-1 do begin
      Read(a);
      if a>x then
        Inc(count)
      else
        Inc(count2);
    end;

    Readln;
    Writeln((count+count2-abs(count-count2))div 2);

    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Measured memory_bytes: 128