akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
const int N=2e5+11,INF=~0u>>2;
struct Edge{int nxt,to;}edge[N<<1];
queue<int> Q;
int n,m,num_edge,head[N],dist[N];
bool vis[N];
void add_edge(int from,int to){
	edge[++num_edge].nxt=head[from];
	edge[num_edge].to=to;
	head[from]=num_edge;
}
bool spfa(){
	for(int i=1;i<=n;++i) dist[i]=INF;
	dist[1]=0;Q.push(1);vis[1]=1;
	while(!Q.empty()){
		int u=Q.front();Q.pop();vis[1]=0;
		for(int i=head[u];i;i=edge[i].nxt){
			int v=edge[i].to;
			if(dist[v]>dist[u]+1){
				dist[v]=dist[u]+1;
				if(!vis[v]) Q.push(v),vis[v]=1;
			}
		}
	}
	if(dist[n]==2) return 1;
	return 0;
}
int main(){
//	freopen("ex.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i){
		int x,y;
		scanf("%d%d",&x,&y);
		add_edge(x,y);add_edge(y,x);
	}
	if(spfa()) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
} 

Measured memory_bytes: 5504
#include<stdio.h>
int main(void)
{
int a,b,d[100],c,x;
	for(c=0;c<7;c++){
scanf("%d %d",&a,&b);
	x=a-b;
	d[c]=x;
	}
for(c=0;c<7;c++){
	printf("%d\n",d[c]);
}
return 0;
}

Measured memory_bytes: 600
import java.util.Arrays;
import java.util.List;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            
            //1行受け取り
            String line;
            try {
                line = sc.nextLine(); 
            }catch(Exception e) {
                break;
            }
            
            //数字の配列を作る
            int[] nums = new int[5];
            
            //lineを分割
            String[] linesp = line.split(",");
            
            
            //配列に数字を入れる
            for(int i = 0; i < 5; i++) {
                nums[i] = Integer.parseInt(linesp[i]);
            }
            
            //0~13の配列を用意してカウント数を入れる
            int[] count = new int[14];
            for(int i = 0; i < 5; i++) {
                count[nums[i]] += 1;
            }
            
            int paircount = 0;
            int straightcount = 0;
            List<Integer> list = new ArrayList<Integer>();
            for(int i = 0; i < 14; i++) {
                if(count[i] > 1) {
                    list.add(count[i]);
                }
                if(count[i] == 2) {
                    paircount += 1;
                }
            }
            
            if(list.contains(4)) {
                System.out.println("four card");
            }else if(list.contains(3) && list.contains(2)) {
                System.out.println("full house");
            }else if(list.contains(3)) {
                 System.out.println("three card");
            }else if(paircount == 2) {
                System.out.println("two pair");
            }else if(paircount == 1) {
                System.out.println("one pair");
            }else {
                for(int i = 1; i < 11; i++) {
                    if(i < 10) {
                        if(count[i] == 1 && count[i+1] == 1 && count[i+2] == 1 && count[i+3] == 1 && count[i+4] == 1) {
                            System.out.println("straight");
                            break;
                        }
                    }else if(i == 10)   
                        if(count[i] == 1 && count[i+1] == 1 && count[i+2] == 1 && count[i+3] == 1 && count[1] == 1) {
                            System.out.println("straight");
                        }else {
                            System.out.println("null");
                        }
                }
            }
            
            
            

        }
    }
}



Measured memory_bytes: 26340
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int a,b;
  cin>>a>>b;
  rep(x,1250){
    double pa=x*0.08;
    double pb=x*0.1;
    if(a==(int)pa && b==(int)pb){
      cout<<x<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int n;
	while(cin >> n && n) {
		int m = 1000 - n;

		int a[6] = {500, 100, 50, 10, 5, 1};
		int ans = 0;
		rep(i, 6) {
			if(m >= a[i]) {
				ans += m / a[i];
				m %= a[i];
			}
		}

		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

/** Application main entry point. */
int main (
  int argc,
  char *argv[ ]
  )
{
  int money = 0;
  int amount = 0;
  int m, a, n = 0;

  while ( scanf ( " %d,%d", &m, &a ) == 2 )
  {
    money += m * a;
    amount += a;
    ++n;
  }

  printf ( "%d\n", money );
  printf ( "%d\n", ( amount * 10 / n + 5) / 10 );

  return ( 0 );
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
int main(){
    stack<int> st, ans;
    stack<PP> ps;
    string s;
    int sum = 0, lake = 0, k = 0, depth = 0;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '\\'){
            st.push(i);
            depth++;
        }
        if(s[i] == '/'){
            if(st.empty()){
                depth--;
                continue;
            }
            int temp = st.top();
            st.pop();
            ps.push(make_pair(make_pair(i, temp), depth));
            sum += i - temp;
            depth--;
        }
    }
    PP p;
    if(!ps.empty()){
        p = ps.top();
        ps.pop();
        if(ps.empty()){
            ans.push(p.first.first - p.first.second);
        }
    }
    while(!ps.empty()){  
        lake = p.first.first - p.first.second;    
        PP p2;
        p2 = ps.top();
        ps.pop();
        while(1){
            if(p.first.second < p2.first.second && p.second < p2.second){
                lake += p2.first.first - p2.first.second;
            }
            else if(ps.empty()){
                ans.push(lake);
                ans.push(p2.first.first - p2.first.second);
                break;
            }
            else{
                ans.push(lake);
                p = p2;
                break;
            }
            if(ps.empty()){
                ans.push(lake);
                break;
            }
            p2 = ps.top();
            ps.pop();
        }
    }
  
    cout  << sum << endl << ans.size();
    while(!ans.empty()){
        cout << " " << ans.top();
        ans.pop();
    }
    cout << endl;
}



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

#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fp(i,a,b) for(int i=a ; i<b ; i++)
#define fn(i,a,b) for(int i=a ; i>=b ; i--)
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int M=3005;
const int INF=1e9;
const int MOD=1e9+5;

string s1,s2;
int dp[M][M];
ii car[M][M];
vector<char> v;

int DP(int i,int j){
  if (i < 0 || j < 0) return -INF;
  if (dp[i][j] != -1) return dp[i][j];

  if (s1[i] == s2[j]){
    dp[i][j] = DP(i-1,j-1) + 1;
    car[i][j] = {i-1,j-1};
  }
  else{
    dp[i][j] = max(DP(i,j-1) , DP(i-1,j));

    if (dp[i][j] > DP(i,j-1)) car[i][j] = {i-1,j};
    else car[i][j] = {i,j-1};
  }

  return dp[i][j];
}

int main(){

	fastio;
  cin >> s1 >> s2;
  int x=s1.size()-1,y=s2.size()-1;
  fp(i,0,M)
    fp(j,0,M) dp[i][j] = -1;
  DP(x,y);

  while (x >= 0 && y >= 0){
    ii &cr=car[x][y];
    if (cr.ff == x-1 && cr.ss == y-1) v.pb(s1[x]);
    
    int ax=cr.ff,bx=cr.ss;
    x = ax; y = bx;
  }

  reverse(all(v));
  fp(i,0,v.size()) cout << v[i];
  cout << "\n";

	return 0;
}


Measured memory_bytes: 109840
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vector<int> dp(10010, false);
    dp[0] = true;
    for (int i = 0; i < n; ++i)
        for (int j = 10000; j >= 0; --j)
            if (j - a[i] >= 0 && dp[j - a[i]])
                dp[j] = true;
    int odp = 0;
    for (int i = 1; i < 10001; ++i)
        if (dp[i] && i % 10 != 0)
            odp = max(odp, i);
    cout << odp;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

    struct data_t {
      string S;
      int f;
      int e;
      int lx;
      int ly;
      };




int main(){
  int n,u=0,w;
  cin >> n;
  int x[n],y[n];
  int min=0;
  int r=n*(n-1);
  vector<data_t> data(r);
  
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i];
  }
  
if(n==1) cout << 1 << endl;
  
  
else{
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i!=j){
      data[u].f=i;
      data[u].e=j;
      data[u].lx=x[i]-x[j];
      data[u].ly=y[i]-y[j];
       // cout << data[u].f << data[u].e << data[u].lx << data[u].ly << endl;
        u++;
      }
    }
  }
  
  //cout << "u"<<u << endl;
  
  
  for(int i=0;i<r;i++){
    int cost=0;
    vector<int> f;
    vector<int> e;
    f.push_back(data[i].f);
    e.push_back(data[i].e);
    for(int j=i;j<r;j++){
      auto it1 = find(f.begin(), f.end(), data[j].f);
      auto it2 = find(e.begin(), e.end(), data[j].e);
      if(data[i].f==data[j].e&&data[i].e==data[i].f) w=1;
      else w=0;
      if(it1==f.end()&&it2==e.end()){
         if(data[i].lx==data[j].lx&&data[i].ly==data[j].ly&&w==0){
           cost++;
            //cout << i << " "<< j << endl;
           f.push_back(data[j].f);
           e.push_back(data[j].e);
         }
      }
      
    }
    
    if(min<cost) min=cost;
  }


cout << n-1-min << endl;  
  
}  
  
  
  
  
  
  
  
  
}

Measured memory_bytes: 256
// https://beta.atcoder.jp/contests/abc109

#define SUBMIT

#include <bits/stdc++.h>
using namespace std;

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    stringstream stream(R"(50
)");
#endif
    int N;
    stream >> N;
    string prev;
    set<string> s;
    for (int i = 0; i < N; ++i) {
        string curr;
        stream >> curr;
        if (s.find(curr) != s.end()) {
            cout << "No" << endl;
            exit(0);
        }

        if (i != 0 && prev[prev.length() - 1] != curr[0]) {
            cout << "No" << endl;
            exit(0);
        }
        prev = curr;
        s.insert(curr);
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define ll long long
int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c)
    {
        puts(a&1?"0":"-1");
        exit(0);
    }
    int ans=0;
    ll a1,b1,c1;
    while(true)
    {
        if(a&1||b&1||c&1) break;
        //cout<<a<<" "<<b<<" "<<c<<endl;
        a1=(b+c)/2;
        b1=(a+c)/2;
        c1=(a+b)/2;
        a=a1; b=b1; c=c1;
        ++ans;
    }
    cout<<ans;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {

	int n, a=2, b, i, j, sum=0, min;

	scanf("%d", &n);
	b = n - 1;
	
	while (b) {
		
		sum += b % 10;
		b  = b/10;
		
	}
	sum += 1;
	min = sum;
	
	for (a=2; a <= n - 1 && n-a >= 2; a++) {
		
		sum = 0;
		i = a;
		b = n - a;
		j = b;

		while (i > 0) {
			sum += i % 10;
			i /= 10;
		}
		while (j > 0) {
			sum += j % 10;
			j /= 10;
		}
		if (min > sum) {
			min = sum;
		}
	}

	printf("%d", min);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    vector<P>xy(N);
    map<P,int>Mp;
    for(int i = 0; i < N; i++) {
        cin >> xy[i].first >> xy[i].second;
    }
    sort(xy.begin(),xy.end());
    for(int i = 0; i < N; i++) {
        for(int j = i+1; j < N; j++) {
            Mp[{xy[i].first-xy[j].first,xy[i].second-xy[j].second}]++;
        }
    }
    int cnt = 0;
    for(pair<P,int> x:Mp) {
        cnt = max(cnt,x.second);
    }
    cout << N-cnt << endl;
}

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

using namespace std;

int main(void) {
	int N;
	cin >> N;

	int x6 = N / 100000;
	int x5 = N / 10000 - x6 * 10;
	int x4 = N / 1000 - x6 * 100 - x5 * 10;
	int x3 = N / 100 - x6 * 1000 - x5 * 100 - x4 * 10;
	int x2 = N / 10 - x6 * 10000 - x5 * 1000 - x4 * 100 - x3 * 10;
	int x1 = N - x6 * 100000 - x5 * 10000 - x4 * 1000 - x3 * 100 - x2 * 10;

	if (N == 10 || N == 100 || N == 1000 || N == 10000 || N == 100000) {
		cout << 10;
	}
	else {
		cout << x1 + x2 + x3 + x4 + x5 + x6;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX_LENGTH 32

int main(void)
{
        char line[MAX_LENGTH];
        int a,b;

        fgets(line, sizeof(line), stdin);
        sscanf(line, "%d %d", &a, &b);
        printf("%d %d\n", a * b, (a + b) * 2);

        return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll k,x; cin>>k>>x;
	if(500*k>=x)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <tuple>
#include <cstdint>

static int64_t solve(int64_t m, int64_t n, int64_t mod);
static int64_t mod_comb(int64_t n, int64_t k, int64_t mod);
static int64_t mod_inv(int64_t a, int64_t m);

int main()
{
    int64_t m, n;
    std::cin >> n >> m;
    std::cout << solve(m, n, 1000000007) << std::endl;

    return 0;
}

static int64_t solve(int64_t m, int64_t n, int64_t mod)
{
    int64_t i = 2;
    int64_t x = m;
    int64_t r = 1;

    while (i * i <= x) {
        int64_t c = 0;
        while (x % i == 0) {
            c++;
            x /= i;
        }

        if (c != 0) {
            r = r * mod_comb(c + n - 1, c, mod) % mod;
        }

        i++;
    }

    if (x != 1) {
        r = r * n % mod;
    }

    return r;
}

static int64_t mod_comb(int64_t n, int64_t k, int64_t mod)
{
    int64_t r = 1;

    for (int64_t i = 1; i <= k; i++) {
        r = r * (n - k + i) % mod;
        r = r * mod_inv(i, mod) % mod;
    }

    return r;
}

static int64_t mod_inv(int64_t a, int64_t m)
{
    int64_t p = a, q = m;
    int64_t x = 1, y = 0, u = 0, v = 1;

    while (q != 0) {
        int64_t k = p / q;
        std::tie(p, q) = std::make_tuple(q, p % q);
        std::tie(x, y, u, v) = std::make_tuple(u, v, x - k * u, y - k * v);
    }

    if (x < 0) {
        return x + m;
    } else {
        return x;
    }
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n;
    cin >> n;
    VI v(1010101, 0);
    VI w(1010101, 0);
    int a[n];
    for (i = 0; i < n; i++) {
        cin >> a[i];
        w[a[i]]++;
    }
    for(i=0;i<1010101;i++){
        if(w[i]==0) continue;
        for (j = 1; i * j < 1010101; j++) {
            v[i * j] += w[i];
        }
    }
    int cnt = 0;
    for (i = 0; i < n; i++) {
        if (v[a[i]] == 1) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 19800
n = int(input())
a = list(map(int , input().split()))
count = 0
for i in range(n):
  if a[i] == 0:
    continue
  if a[a[i] - 1] == i + 1:
    a[a[i] - 1] = 0
    count += 1
print(count)

Measured memory_bytes: 13880
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

int h, w;

ll func(ll h, ll w) {
	ll ans = 100005LL * 100005LL;
	for (ll i = 1; i < h; i++) {
		ll x = h - i;
		ll y = x / 2;
		ll z = (x + 1)/2;
		ll a1 = y*w, a2 = i*w, a3 = z*w;
		ll ma = max(max(a1, a2), a3);
		ll mi = min(min(a1, a2), a3);
		ans = min(ans, abs(ma-mi));
		y = w / 2;
		z = (w + 1) / 2;
		a1 = i*w; a2 = y*(h - i); a3 = z*(h - i);
		ma = max(max(a1, a2), a3);
		mi = min(min(a1, a2), a3);
		ans = min(ans, abs(ma - mi));

	}
	return ans;
}

int main(){
	cin >> h >> w;

	ll ans = func(h, w);
	ans = min(ans, func(w, h));
	
	cout << ans << endl;
	return 0;
}


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

int main(int argc, const char * argv[]) {
   
    int a,b,x;
    
    cin >> a >> b;
    
    x=(a+b)/2;
    
    if((a+b)%2==0){
        cout << x << endl;
    }
    else {
        cout << x+1 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

template <class T>
inline void read(T &x)
{
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

int p[200010];
int n, ans = 1, min;

int main()
{
    read(n);
    for (int i = 1; i <= n; ++i)
        read(p[i]);
    min = p[1];
    for (int i = 2; i <= n; ++i)
    {
        if (p[i] < min) ++ans;
        min = std::min(min, p[i]);
    }
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;

int main(void) {
  vector <int> a(3);
  for(int i = 0; i < 3; i++) {
    cin >> a[i];
  }
  int k;
  cin >> k;

  sort(a.begin(), a.end());
  long long mx = a[2];
  for(int i = 0; i < k; i++) {
    mx *= 2;
  }
  cout << a[0] + a[1] + mx << endl;
}

Measured memory_bytes: 256
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  list($k) = explode(" ", trim(fgets(STDIN)));

  $x = explode(" ", trim(fgets(STDIN)));

  $ans = 0;
  for($i=0; $i<$n; $i++){
    if($x[$i] > abs($x[$i]-$k)){
      $ans = $ans + abs($x[$i]-$k)*2;
    }else{
      $ans = $ans + $x[$i]*2;
    }
  }
  echo $ans;

Measured memory_bytes: 16172
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-10;

typedef int weight;
struct edge
{
	int to; weight cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};

typedef vector<edge> Edges;
typedef vector<Edges> Graph;
//int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int main()
{
	int n, q;
	while (cin >> n >> q, n)
	{
		Graph g(n);
		REP(i, n-1)
		{
			int a;
			cin >> a;
			a--;
			g[a].push_back(edge{ i + 1, 0 });
		}
		vi ans(n), mark(n);
		mark[0] = true;
		ll sum = 0;
		REP(i, q)
		{
			char c; int v;
			cin >> c >> v;
			v--;
			if (c == 'Q') sum += ans[v]+1;
			else
			{
				if (mark[v]) continue;
				mark[v] = true;
				queue<int> que;
				que.push(v);
				while (que.size())
				{
					int t = que.front();
					que.pop();
					ans[t] = v;
					REP(j, g[t].size())
					{
						if (mark[g[t][j].to] == 1) continue;
						que.push(g[t][j].to);
					}
				}
			}
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 7336
n,y = map(int,input().split())
for i in range(n+1):
    for j in range(n+1-i):
        k = n - i - j
        if i*10000 + j*5000 + k*1000 == y and  i + j + k == n and k >= 0:
            print(i,j,k)
            exit()
print("-1 -1 -1")


Measured memory_bytes: 9176
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 15 11:10:31 2020

@author: asaka
"""

N, M, X = map(int, input().split())
C = []
A = []
ans = float("inf")

for n in range(N):
    temp = list(map(int, input().split()))
    C.append(temp[0])
    A.append(temp[1:])
    
for i in range(2**N):
    mny = 0
    score = [0]*M
    for j in range(N):
        if i&(2**j)>0:
            mny += C[j]
            for k in range(M):
                score[k] += A[j][k]
    if min(score)>=X:
        ans = min(ans, mny)

if ans==float("inf"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 68904
n, m = map(int, input().split())

dic = {}
for i in range(m):
    a, b = map(int, input().split())
    if not a in dic:
        dic[a] = [b]
    else:
        dic[a].append(b)
    if not b in dic:
        dic[b] = [a]
    else:
        dic[b].append(a)

queue = [1]
res = [0] * (n+1)
while queue != []:
    p = queue[0]
    del queue[0]
    for i in dic[p]:
        if res[i] == 0:
            res[i] = p
            queue.append(i)
            
print('Yes')
for elem in res[2:]:
    print(elem)


Measured memory_bytes: 40372
<?php
while(1){
    fscanf(STDIN,"%d",$q);
    if($q==-1)break;
    $x=$q/2;
    while(abs(pow($x,3)-$q)>=0.00001*$q){
        $x-=(pow($x,3)-$q)/(3*$x*$x);
    }
    echo $x."\n";
}
?>

Measured memory_bytes: 6652
#include <stdio.h>
int count (int n) {
   int a, b, c, d, counter = 0;
   for (a=0; a<10; a++)
      for (b=0; b<10; b++)
         for (c=0; c<10; c++)
            for (d=0; d<10; d++)
               if (a+b+c+d == n) counter++;
   return counter;
}
int main() {
   int n;
   while (scanf("%d", &n) != EOF) {
      printf("%d\n", count(n) );
   }
   return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int b[2000009];
int c[2000009];
int dp(int a){
    if(c[a] != -1){
        return c[a];
    }
    if(a<2){
        c[a] = 0;
        return 0;
    }
    else{
        c[a] = min(dp(a-2)+abs(b[a]-b[a-2]),dp(a-1)+abs(b[a]-b[a-1]));
        return c[a];
    }
}
int main(){
    int x;
    cin >> x;
    for(int i=1;i<x+1;i++){
        cin >> b[i];
        c[i] = -1;
    }
    b[0] = b[1];
    cout << dp(x);
}



Measured memory_bytes: 7808
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();   
        int N = r.i();
        int K = r.i();
        int[] x = r.ii();
        int ans = 0;
        for(int xi : x)
            ans += Math.min(xi, K-xi); 
        println(ans*2);        
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e10;
const ll MOD = 1e9+7;
int h,w;
string grid[2005];
int l[2005][2005],r[2005][2005],u[2005][2005],d[2005][2005];

int main(){
    cin >> h >> w;
    string s;
    rep(i,h){
        cin >> s;
        grid[i] = s;
    }
    rep(i,h){
        rep(j,w){
            if (grid[i][j] == '#'){
                u[i][j] = 0;
                d[i][j] = 0;
                l[i][j] = 0;
                r[i][j] = 0;
            }
            else{
                if (i == 0) u[i][j] = 1;
                if (i == h-1) d[h-1][j] = 1;
                if (j == 0) l[i][j] = 1;
                if (j == w-1) r[i][w-1] = 1;
            }
        }
    } 
    rep(i,h){
        rep(j,w){
            if (grid[i][j] != '#'){
                if (i != 0) u[i][j] = u[i-1][j] + 1;
                if (j != 0) l[i][j] = l[i][j-1] + 1;
                
            }
            if (grid[h-i-1][j] != '#'){
                if (i != 0) d[h-i-1][j] = d[h-i][j] + 1;
            }
            if (grid[i][w-j-1] != '#'){
                if (j != 0) r[i][w-j-1] = r[i][w-j] + 1;
            }
        }
    }
    int ans = 0;
    rep(i,h) rep(j,w){
        chmax(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3);
    }
    PRINT(ans);
}


Measured memory_bytes: 67072
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    ll N,M; cin>>N>>M;
    vector<vector<ll>>a(M,vector<ll>(2));
    vector<ll>s(N,1);
    vector<bool>red(N,false);

    red[0]=true;
    rep(i,M){
        cin>>a[i][0]>>a[i][1];
        s[a[i][0]-1]--; s[a[i][1]-1]++;
        if(red[a[i][0]-1]==true){
            if(s[a[i][0]-1]>0){
                red[a[i][1]-1]=true;
            }
            else{
                red[a[i][0]-1]=false;
                red[a[i][1]-1]=true;
            }
        }
    }
    ll ans=0;
    rep(i,N){
        if(red[i])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	long long n,m;
	cin >> n >> m;
	if(n==1 and m==1)
		cout << 1 << endl;
	else if(n==1)
		cout << m-2 << endl;
	else if(m==1)
		cout << n-2 << endl;
	else 	
		cout << (n-2)*(m-2) << endl;



	
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a > b){
            System.out.println(2*a - 1);
        }
      else if(a == b){
      		System.out.println(2*a);
      }
        else{
            System.out.println(2*b - 1);
        }
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define cY cout << "Yes" << endl;
#define cN cout << "No" << endl;

int main() {
  int h,n;
  cin >> h >> n;
  vector<int>a(n);
  int sum = 0;
  rep(i,n){
    cin >> a.at(i);
    sum += a.at(i);
  }
  if(sum>=h){
    cY;
  }
  else{
    cN;
  }
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll n;
    cin>>n;
    vector<ll>a;
    for(ll i=1; i*i<=n; ++i){
        if(n%i==0){
            a.push_back(i);
            if(n/i!=i)a.push_back(n/i);
        }
    }
    ll ans=0;
    rep(i,a.size()){
        if(a[i]==1)continue;
        if(n/(a[i]-1)==n%(a[i]-1))ans+=(a[i]-1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int E,ta[1010],to[1000010],nt[1000010],co[1000010],F[1010];
int MF(int s,int t,int min){
  if(s==t||min==0)return min;
  int i,r;
  F[s]=1;
  for(i=ta[s];i+1;i=nt[i]){
    if(F[to[i]])continue;
    r=MF(to[i],t,MIN(min,co[i]));
    co[i]-=r;
    co[(i+E)%(2*E)]+=r;
    if(r)return r;
  }
  return 0;
}
int maxf(int s,int t,int v,int *a,int *b,int *c){
  int i,f,r,j;
  for(i=0;i<v;i++)ta[i]=-1;
  for(i=0;i<E;i++){
    nt[i  ]=ta[to[i+E]=a[i]];
    nt[i+E]=ta[to[i  ]=b[i]];
    co[ta[a[i]]=i  ]=c[i];
    co[ta[b[i]]=i+E]=0;
  }
  for(f=0;r=MF(s,t,1000000000);f+=r){
    for(i=0;i<v;i++)F[i]=0;
  }
  return f;
}   
int main(){
  int v,a[1010],b[1010],c[1010],i;
  scanf("%d %d",&v,&E);
  for(i=0;i<E;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  printf("%d\n",maxf(0,v-1,v,a,b,c));
  return 0;
}

Measured memory_bytes: 4720
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int w,h,n,i;
	long long r=0,f;
	scanf("%d%d",&w,&h);
	n=w+h;
	vector<pair<int,int> >node(n);
	for(i=0;i<w;i++)scanf("%d",&node[i].first),node[i].second=0;
	for(;i<n;i++)scanf("%d",&node[i].first),node[i].second=1;
	sort(node.begin(),node.end());
	for(i=0;i<n;i++){
		if(node[i].second)f=w+1,h--;
		else f=h+1,w--;
		r+=node[i].first*f;
	}
	printf("%lld\n",r);
}

Measured memory_bytes: 1792
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-9
#define M_PI 3.141592653589793
#define bs 1000000007
#define bsize 512

#define ldouble long double

using namespace std;

const int N = 1000031;

long long n,A,B,S[N];
long long oka[N],okb[N];

long long dp[N][2],sdp[N][2];

int main(){
	//freopen("tree.in","r",stdin);
	//freopen("tree.out","w",stdout);
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	cin>>n>>A>>B;

	for (int i=0;i<n;i++)
	{
		cin>>S[i];
	}

	for (int i=0;i<n;i++)
	{
		if (i==0||S[i]-S[i-1]<A)
			oka[i]=i;
		else
			oka[i]=oka[i-1];
		if (i==0||S[i]-S[i-1]<B)
			okb[i]=i;
		else
			okb[i]=okb[i-1];
	}

	dp[0][0]=1;
	dp[0][1]=1;
	sdp[0][0]=sdp[0][1]=1;

	for (int i=0;i<n;i++)
	{
		// solve for A
		long long thold;
		if (i==n-1)
			thold=2e18;
		else
			thold=S[i+1]-B;
		int idr=upper_bound(S,S+n,thold)-S;
		idr=min(idr,i);
		int idl=oka[i];
		if (idl<=idr)
		{
			dp[i+1][0]=sdp[idr][1];
			if (idl>0)dp[i+1][0]-=sdp[idl-1][1];
			dp[i+1][0]%=bs;
			if (dp[i+1][0]<0)
				dp[i+1][0]+=bs;
		}

		//cout<<idl<<"%"<<idr<<endl;

		// solve for B
		if (i==n-1)
			thold=2e18;
		else
			thold=S[i+1]-A;
		idr=upper_bound(S,S+n,thold)-S;
		idl=okb[i];
		idr=min(idr,i);
		if (idl<=idr)
		{
			dp[i+1][1]=sdp[idr][0];
			if (idl>0)
				dp[i+1][1]-=sdp[idl-1][0];
			dp[i+1][1]%=bs;
			if (dp[i+1][1]<0)
				dp[i+1][1]+=bs;
		}
		//cout<<"@"<<idl<<" "<<idr<<endl;
		//cout<<dp[i+1][0]<<"!"<<dp[i+1][1]<<endl;

		sdp[i+1][0]=sdp[i][0]+dp[i+1][0];
		sdp[i+1][1]=sdp[i][1]+dp[i+1][1];
		sdp[i+1][0]%=bs;
		sdp[i+1][1]%=bs;
	}

	cout<<(dp[n][0]+dp[n][1])%bs<<endl;

	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 5888
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = Read();
            var list = new List<int>();
            for (int i = 0; i < r.Length-2; i++)
            {
                var x = int.Parse(r[i] + "" + r[i + 1] + "" + r[i + 2]);
                list.Add(Math.Abs(753 - x));

            }
            WriteLine(list.Min());
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
int N,x,y,pos,tri0,tri1,tri2,pw3[13]={1},A[531441],salsa[531441],sw[531441];
char T[200001];
void OUT(int x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
signed main(void)
{
  x=scanf("%d %s",&N,T+1);
  rep(i,N)pw3[i+1]=3*pw3[i];
  tri0=pw3[N],tri1=pw3[N/2],tri2=pw3[N-N/2];
  rep(i,tri0)salsa[i]=salsa[i/3]*3+(3-i%3)%3;
  rep(i,tri1)
  {
    x=i,pos=0;
    rep(j,strlen(T+1))
    {
      if(T[j+1]=='S'){x=salsa[x];if(sw[pos]>0)pos--;else sw[++pos]=1;}
      if(T[j+1]=='R'){x++;if(x==tri1)sw[++pos]=-1,x=0;}
    }
    rep(j,tri2)
    {
      y=j;
      rep(k,pos){if(sw[k+1]>0)y=salsa[y];else if(sw[k+1]<0){if((++y)==tri2)y=0;}}
      A[i+j*tri1]=y*tri1+x;
    }
  }
  rep(i,tri0)OUT(A[i]),putchar(' ');
}

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

int main()
{
    int k, a, b;
    cin >> k >> a >> b;
    if (b - a <= 2)
    {
        cout << k + 1 << endl;
        return 0;
    }
    if (1 + k - 2 < a)
    {
        cout << k + 1 << endl;
        return 0;
    }
    ll t = a - 1;
    cout << a + ((k - t) / 2) * (b - a) + ((k - t) % 2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x) {cout << #x << " = " << (x) << endl;}

const LL MOD = 1e9 + 7;
inline LL mod_add(LL a, LL b) { return (a + b) % MOD; }
inline LL mod_sub(LL a, LL b) { return (a + MOD - b) % MOD; }
inline LL mod_mul(LL a, LL b) { return ((a % MOD) * (b % MOD)) % MOD; }
LL mod_bipow(LL x, LL y) {   // x^y by bisection method
    if (y == 0) return 1;
    else if (y == 1) return x % MOD;
    else if (y % 2 == 0) {
        LL val = mod_bipow(x, (LL)(y / 2));
        return mod_mul(val, val);
    } else {
        LL val = mod_bipow(x, (LL)(y / 2));
        return mod_mul(mod_mul(val, val), x);
    }
}
LL mod_inv(LL x) { return mod_bipow(x, MOD - 2); }   // x^{-1} = x^{MOD-2} (MOD: prime number)
LL mod_div(LL a, LL b) { return mod_mul(a, mod_inv(b)); }   // a/b = a*b^{-1}

int main() {
	LL H, W;
    cin >> H >> W;
    VS A(H);
    REP(i, H) cin >> A[i];

    VVI dp(H, VI(W));
    dp[0][0] = 1;
    REP(i, H) {
        REP(j, W) {
            if (j + 1 < W && A[i][j + 1] == '.') {
                dp[i][j + 1] = mod_add(dp[i][j + 1], dp[i][j]);
            }
            if (i + 1 < H && A[i + 1][j] == '.') {
                dp[i + 1][j] = mod_add(dp[i + 1][j], dp[i][j]);
            }
        }
    }
	cout << dp[H - 1][W - 1] << endl;
    return 0;
}


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


int main(){

    int H, W;
    string a[100];
    cin >> H >> W;
    for( int i = 0; i < H; i++ ){
        cin >> a[i]; 
    }


    string white_line;
    for( int i = 0; i < W; i++ ) white_line += ".";
    
    string del_line[100];
    int line = 0, col = W;

    // 行の白マスを消去
    for( int i = 0; i < H; i++ ){
        if( a[i] != white_line ){
            del_line[line] = a[i];
            line++;
        }
    }

    // 列の白マスを削除
    for( int i = 0; i < col; i++ ){
        bool del = true;
        for( int j = 0; j < line; j++ ){
            if(del_line[j][i] == '#' ){
                del = false;
                break;
            }
        }
        if( del ){
            for( int j = 0; j < line; j++ ){
                del_line[j].erase( del_line[j].begin() + i );
            }
            col--;
            i--;
        }
    }
    
    // 表示
    for( int i = 0; i < line; i++ ) cout << del_line[i] << endl;

    return 0;

}

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

int main()
{
    int n, k;
    std::cin >> n  >> k;
    int ans = k;

    for (int i = 0; i < n - 1; i++) {
       ans *= (k - 1);
    }
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){


  int n,m;
  cin>>n>>m;
  int count[m+1];
  REP(i,m+1){
    count[i] = 0;
  }

  REP(i,n){
    int k;
    cin>>k;
    REP(j,k){
      int a;
      cin>>a;
      count[a]++;
    }
  }

  int ans = 0;
  REP(i,m+1){
    if(count[i]==n){
      ans++;
    }
  }
  cout<<ans<<endl;



  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int N=1e6+5;

int n,ans,h=1,t,q[N],p; char S[N],T[N];

int main()
{
	scanf("%d%s%s",&n,S+1,T+1); int i,o=1;
	for (i=1; o&&i<=n; i++) if (S[i]!=T[i]) o=0;
	if (o) return puts("0"),0;
	
	for (i=p=n; i; i--)
	{
		if (T[i]==T[i-1]) continue;
		for (p=std::min(p,i); p&&T[i]!=S[p]; p--);
		if (!p) return puts("-1"),0;
		while (h<=t&&q[h]-t+h>i) h++;
		q[++t]=p;
		if (i!=p) ans=std::max(ans,t-h+1);
	}
	printf("%d",ans+1);
	
	return 0;
}

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

int main () {
	char buff[1024];
	float a, b, c, d, e, f;
	float x, y;

	while (fgets (buff, 1024, stdin) != NULL) {
		sscanf (buff, "%f %f %f %f %f %f", &a, &b, &c, &d, &e, &f);

		y = (a * f - d * c) / (a * e - b * d);
		x = (c - b * (a * f - d * c) / (a * e - b * d)) / a;
		
		printf ("%.3f %.3f\n", x, y);
	}
	
	return 0;
}



Measured memory_bytes: 2040
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    

    int[] n = new int[3];
    n[0] = sc.nextInt();
    n[1] = sc.nextInt();
    n[2] = sc.nextInt();

    sc.close();

    Arrays.sort(n);

    int count = 0;

    if ((n[1] - n[0]) % 2 == 1) {
      n[1]++;
      n[2]++;
      count++;
    }

    while (n[0] != n[1]) {
      n[0] += 2;
      count++;
    }

    count += n[2] - n[1];
    
    System.out.println(count);

  }

}

Measured memory_bytes: 24404
unittest
{
	assert( [ "3", "2 3", "1 3", "1 2" ].solve == 3 );
	assert( [ "4", "2 3 4", "1 3 4", "4 1 2", "3 1 2" ].solve == 4 );
	assert( [ "3", "2 3", "3 1", "1 2" ].solve == -1 );
}



import std.algorithm;
import std.container;
import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto ass = new long[][]( n, n - 1 );
	foreach( ref as; ass )
	{
		input.popFront;
		as = input.front.split.to!( long[] );
		as[] -= 1;
	}
	
	auto queue = DList!long( iota( 0L, n ) );
	auto us = new bool[ n ];
	us[] = true;
	auto ds = new long[ n ];
	auto t = n * ( n - 1 ) / 2;
	while( !queue.empty )
	{
		auto x = queue.front;
		queue.removeFront;
		us[ x ] = false;
		
		if( ass[ x ].empty ) continue;
		
		auto y = ass[ x ].front;
		if( ass[ y ].empty ) continue;
		
		auto z = ass[ y ].front;
		if( x != z ) continue;
		
		queue.insert( x );
		us[ x ] = true;
		
		if( !us[ y ] )
		{
			queue.insert( y );
			us[ y ] = true;
		}
		
		auto d = max( ds[ x ], ds[ y ] ) + 1;
		ds[ x ] = d;
		ds[ y ] = d;
		
		ass[ x ].popFront;
		ass[ y ].popFront;
		t--;
	}
	return ( 0 < t ) ? -1 : ds.reduce!max;
}


Measured memory_bytes: 39048
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1 == 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

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

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int maxl = 1e18;
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int a;
        long double b;
        cin >> a >> b;
        b *= 100;
        b+=0.5;
        int temp=b;
        int ans = a * temp;
        ans /= 100;
        cout << ans << endl;
    }
    return 0;
}


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

using ull = unsigned long long;

using namespace std;

int main (void){
  int a, b, c, d;
  scanf("%1d%1d%1d%1d", &a, &b, &c, &d);

  if(a+b+c+d==7) printf("%d+%d+%d+%d=7\n", a, b, c, d);
  else if(a+b+c-d==7) printf("%d+%d+%d-%d=7\n", a, b, c, d);
  else if(a+b-c+d==7) printf("%d+%d-%d+%d=7\n", a, b, c, d);
  else if(a+b-c-d==7) printf("%d+%d-%d-%d=7\n", a, b, c, d);
  else if(a-b+c+d==7) printf("%d-%d+%d+%d=7\n", a, b, c, d);
  else if(a-b+c-d==7) printf("%d-%d+%d-%d=7\n", a, b, c, d);
  else if(a-b-c+d==7) printf("%d-%d-%d+%d=7\n", a, b, c, d);
  else if(a-b-c-d==7) printf("%d-%d-%d-%d=7\n", a, b, c, d);

  return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,m = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	f = zeros(Int,n)
	d = Dict{Int,Int}()
	for i in 1:n
		if haskey(d,a[i])
			d[a[i]] += 1
		else
			d[a[i]] = 1
		end
	end
	for i in keys(d)
		for j in 0:d[i]-1
			if i-j>0
				f[i-j] += 1
			end
		end
	end
	s = 0
	for i in 1:n
		if f[i] == 0
			s += 1
		end
	end
	for i in 1:m
		x,y = readline() |> split |> parseMap
		if a[x]-d[a[x]]+1>0
			f[a[x]-d[a[x]]+1] -= 1
			if f[a[x]-d[a[x]]+1] == 0
				s += 1
			end
		end
		d[a[x]] -= 1
		if haskey(d,y)
			d[y] += 1
		else
			d[y] = 1
		end
		a[x] = y
		if y-d[y]+1>0
			if f[y-d[y]+1] == 0
				s -= 1
			end
			f[y-d[y]+1] += 1
		end
		println(s)
	end
end

main()


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

int N;
int A[110];
int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	int count = 0;
	for(int i=0;i<N;i++){
		int minj = i;
		for(int j=i;j<N;j++){
			if(A[j] < A[minj]){
				minj = j;
			}
		}
		int tmp = A[i];
		A[i] = A[minj];
		A[minj] = tmp;
		if(minj!=i) count++;
	}
	for(int i=0;i<N;i++){
		if(i!=N-1) cout << A[i] <<" ";
		else cout << A[i] << endl;
	}
	cout << count << endl;
}



Measured memory_bytes: 3112