akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    
    cout << n * n * n << endl;
    
    return 0;
}



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

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

long long dp[100010];

int main() {
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &h[i]);
    }

    for (int i = 0; i < 100010; i++) {
        dp[i] = INF;
    }

    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);

    for (int i = 2; i < N; i++) {
        chmin(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]));
        chmin(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
    }

    cout << dp[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;
int a, b, m;
int na[100000], nb[100000];
int x[100000], y[100000], z[100000];
int namin=999999, nbmin=999999, ncmin=999999;

int main() {
	cin >> a >> b >> m;
	rep(i, a) {
		cin >> na[i];
		if (na[i] < namin) {
			namin = na[i];
		}
	}
	rep(i, b) {
		cin >> nb[i];
		if (nb[i] < nbmin) {
			nbmin = nb[i];
		}
	}
	rep(i, m) {
		cin >> x[i] >> y[i] >> z[i];
		if ((na[x[i]-1] + nb[y[i]-1] - z[i]) < ncmin) {
			ncmin = (na[x[i]-1] + nb[y[i]-1] - z[i]);
		}

	}
	cout << min((namin + nbmin), ncmin) << endl;
	return 0;
}


Measured memory_bytes: 2176
/**/
#include <bits/stdc++.h>
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

long long pow_mod(long long base,long long power) {
	long long res = 1;
	while(power) {
		if(power&1)
			res = res * base % mod;
		base = base * base % mod;
		power >>= 1;
	}
	return res;
}

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

	int N;
	cin>>N;
	vector<int> a(N);
	for(int i = 0;i < N;i++)
		cin>>a[i];
	sort(a.begin(),a.end());
	int st = 0;
	if(N%2 == 0)
		st++;
	bool can = true;
	for(int i = 0;i < N;i++) {
		can &= a[i] == st;
		if((i&1) != (N&1))
			st+=2;
	}
	if(!can)
		cout<<"0\n";
	else
		cout<<pow_mod(2,N>>1)<<'\n';
	return 0;
}
/**/


Measured memory_bytes: 640
#include<stdio.h>
int main(){
	char s[100][100];
	int h,w,i,j,k;
	h=w=i=j=k=0;
	scanf("%d %d\n",&h,&w);
//	getchar();
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			scanf("%c",&s[i][j]);
		//s[i][j]=getchar();
		}
		getchar();
	}
	
//	for(i=0;i<h;i++){
//		for(j=0;j<w;j++){
//			printf("%c",s[i][j]);
//		}
//	}
//	
	
	
	for(k=0;k<w+2;k++){
		printf("#");
	}
	printf("\n");
	for(i=0;i<h;i++){
		printf("#");
		for(j=0;j<w;j++){
		//	printf("%c",s[i][j]);
		putchar(s[i][j]);
		}
		printf("#\n");
	} 
	for(k=0;k<w+2;k++){
		printf("#");
	}
	return 0;
}

Measured memory_bytes: 128
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Exception
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.Trans.State.Strict
import           Data.Array.Base
import           Data.Array.ST                    (STUArray, runSTUArray)
import           Data.Bits
import           Data.Bool
import qualified Data.ByteString.Char8            as B
import           Data.Char
import           Data.Coerce
import qualified Data.Foldable                    as F
import           Data.Function
import           Data.Int
import qualified Data.IntMap.Strict               as IM
import qualified Data.IntSet                      as IS
import qualified Data.List                        as L
import qualified Data.Map.Strict                  as M
import           Data.Monoid
import           Data.Ord
import qualified Data.Set                         as S
import           Data.STRef
import           Data.Tuple
import           Data.Word
import           Debug.Trace
import           GHC.Arr                          (Array, Ix (..), STArray)
import           GHC.Exts
import           System.Exit
import           System.IO

main :: IO ()
main = do
    !n <- readLn :: IO Int
    xs <- L.unfoldr (B.readInt.B.dropWhile isSpace) <$> B.getContents
    print.maybe (-1) id $ solve n xs

solve n xs@(hd:_)
    | hd > 0 = Nothing
    | otherwise = go 0 0 n $ reverse xs
  where
    go !res !h !rest (0:xs)
        | h == 0 = go res 0 (rest - 1) xs
        | otherwise = Nothing
    go !res !h !rest (x:xs) = case compare h x of
        EQ -> go res (h - 1) (rest - 1) xs
        LT | x < rest -> go (res + x) (x - 1) (rest - 1) xs
        _  -> Nothing
    go res 0 0 [] = Just res
    go _ _ _ _ = Nothing



Measured memory_bytes: 16892
#include <bits/stdc++.h>
#include <boost/math/constants/constants.hpp>

using real = double;

real pi = boost::math::constants::pi<real>();
::std::size_t t = 1;

template<class RandomAccessIterator1, class RandomAccessIterator2, class RandomAccessIterator3>
RandomAccessIterator1 convolution(RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, RandomAccessIterator2 last2, RandomAccessIterator3 result){
    using value_type = typename ::std::iterator_traits<RandomAccessIterator1>::value_type;
    using size_type = ::std::size_t;
    size_type N = last1 - first1, M = last2 - first2;
    while(t < N + M)t <<= 1;

    const auto fft_inplace = [](auto& res, value_type hint){
        ::std::size_t N = res.size();

        // bit reverse
        for(::std::size_t i = 0, j = 0; i < N; ++i){
            if(i < j)::std::swap(res[i], res[j]);
            j ^= N / (1 + (i ^ (i + 1))) * (i ^ (i + 1));
        }

        ::std::stack<value_type> root;
        root.push(hint);
        for(::std::size_t i = 2; i < N; i <<= 1)root.push(hint *= hint);

        // fft
        for(::std::size_t i = 1; i < N; i <<= 1){
            auto t = root.top();
            root.pop();
            for(::std::size_t j = 0; j < N; j += 2 * i){
                auto coef = static_cast<value_type>(1);
                for(::std::size_t k = 0; k < i; ++k){
                    auto tmp = res[j + k];
                    res[j + k] += coef * res[j + k + i];
                    res[j + k + i] = tmp - coef * res[j + k + i];
                    coef *= t;
                }
            }
        }
    };

    ::std::vector<value_type> input1(first1, last1), input2(first2, last2), res(t);
    input1.resize(t);
    input2.resize(t);
    value_type hint = value_type(::std::cos(pi / (t / 2)), ::std::sin(pi / (t / 2))), ihint = value_type(::std::cos(pi / (t / 2)), -::std::sin(pi / (t / 2)));
    fft_inplace(input1, hint);
    fft_inplace(input2, hint);
    ::std::transform(input1.begin(), input1.end(), input2.begin(), res.begin(), ::std::multiplies<value_type>());
    fft_inplace(res, ihint);

    return ::std::copy(res.begin(), res.end(), result);
}

int main(){
    using real = double;
    using namespace std;
    unsigned long N, L;
    cin >> N >> L;
    vector<unsigned long> T(N);
    copy_n(istream_iterator<unsigned long>(cin), N, T.begin());
    vector<complex<real>> ps(N), res(4 * N);
    transform(T.begin(), T.end(), ps.begin(), [&L](auto t){return complex<real>(cos(pi * t / L), sin(pi * t / L));});
    convolution(ps.begin(), ps.end(), ps.rbegin(), ps.rend(), res.begin());
    complex<real> x{0};
    for(long i = 0, c = -N; i + 1 < N; ++i)x += res[i] * static_cast<real>(c += 2);
    t *= N * (N - 1) * (N - 2) / 6;
    x /= t;
    cout << setprecision(15) << fixed;
    cout << x.real() << " " << x.imag() << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long LL;
typedef long double lb;
#define ri register int
const lb PI=3.141592653589793238462643383279;
const ll inf=1000000000000000000ll;
const int N=1000005,M=1000000007;
long long qpow(long long a,long long b)
{
	long long s=a,ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*s%M;
		b>>=1;
		s=s*s%M;
	}
	return ans;
}
int n,k,x,y,c[N],mn[N],f[N],w[N],tmn=1<<30,t2mn=1<<30,mnn,v[N],i,s;
long long ans=1,fac[N];
int main()
{
	memset(mn,0x7f,sizeof(mn));
	scanf("%d %d %d",&n,&x,&y);
	for(i=1;i<=n;++i)
	{
		scanf("%d %d",&c[i],&w[i]);
		mn[c[i]]=min(mn[c[i]],w[i]);
	}
	for(i=1;i<=n;++i)
		if(mn[i]<tmn)
		{
			t2mn=min(t2mn,tmn);
			tmn=mn[i];
			mnn=i;
		}
		else
			t2mn=min(t2mn,mn[i]);
	for(i=1;i<=n;++i)
		if(c[i]==mnn)
		{
			if(t2mn+w[i]<=y||tmn+w[i]<=x)
				++f[c[i]];
		}
		else
			if(tmn+w[i]<=y||mn[c[i]]+w[i]<=x)
				++f[c[i]];
	for(i=1;i<=n;++i)
		if(tmn+mn[i]>y)
			f[i]=0;
	fac[0]=1;
	for(i=1;i<=n;++i)
		fac[i]=fac[i-1]*i%M;
	for(i=1;i<=n;++i)
	{
		s+=f[i];
		ans=ans*qpow(fac[f[i]],M-2)%M;
	}
	cout<<ans*fac[s]%M;
}


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

using namespace std;

int main() {
	int n; scanf("%d", &n);
	vector<int> w(n);
	for (int i = 0; i < n; ++i) scanf("%d", &w[i]);
	// sort(begin(w), end(w));
	vector<int> sumUntil(n + 1);
	int allSum = 0;
	for (int i = 0; i < n; ++i) {
		sumUntil[i + 1] = sumUntil[i] + w[i];
		allSum += w[i];
	}
	int ans = 1000000000;
	for (int i = 0; i <= n; ++i) {
		ans = min(ans, abs(allSum - 2*sumUntil[i]));
	}
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

bool vis[20];

bool ok(int num) {
	while(num) {
		if(vis[num % 10]) return 0;
		num /= 10;
	}
	return 1;
}

int get_len(int num) {
	int cnt = 0;
	while(num) cnt++, num /= 10;
	return cnt;
}

int work(int len) {
	int ans = 0; while(len--) ans = ans * 10 + 9; return ans;
}

int main() {
	int N, K;
	cin >> N >> K;
	for(int i = 1; i <= K; ++i) {
		int t; cin >> t; vis[t] = 1;
	}
	int len = get_len(N); int maxx = work(len);
	for(int i = N; i <= maxx; ++i) {
		if(ok(i)) {
			cout << i << endl; return 0;
		}
	}
	int k;
	for(int i = 1; i <= 9; ++i) {
		if(!vis[i]) {k = i; break;}
	}
	cout<<k;
	int t = (!vis[0]) ? (0) : k;
	while(len--) cout << t;
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
///
// File:  1141.cpp
// Author: ymiyamoto
//
// Created on Mon Nov 13 01:51:59 2017
//

#include <cmath>
#include <cstdint>
#include <iostream>

using namespace std;

bool is_prime(uint32_t n)
{
  if (n <= 1) return false;

  for (uint32_t i = 2; i <= (uint32_t)sqrt((double)n); i++) {
    if (n % i == 0) {
      return false;
    }
  }

  return true;
}

int32_t main()
{
  while (true) {
    uint32_t a, d, n;
    cin >> a >> d >> n;
    if (a == 0) break;

    for (uint32_t i = 0;; i++) {
      uint32_t num = a + i * d;
      if (is_prime(num)) {
        n--;
      }
      if (n == 0) {
        cout << num << endl;
        break;
      }
    }
  }

  return 0;
}

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

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<int,int> P;
const ll MAX_N=131072;
const ll INF=1000000;
const ll MOD=1000000007;

int main(){
  string w;cin>>w;
  map<char,int> m;
  for(auto v:w){
    m[v]+=1;
  }
  for(auto v:m){
    if (v.second%2){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001; // > 10^9
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    int n; cin >>n;
    vector<int> a(n); rep(i,n) cin >> a[i];
    
    sort(a.begin(), a.end());

    int odd = 0;
    int even = 0;
    for (int i = 0; i < a.size();) {
        int j = i;
        while (j < a.size() && a[i] == a[j]) {
            j++;
        }
        if ((j - i) % 2 == 0) {
            even++;
        } else {
            odd++;
        } 
        i = j;
    }

    if (even % 2 == 1) {
        cout << even + odd - 1 << endl;
    } else {
        cout << even + odd << endl;
    } 

    return 0;
}



Measured memory_bytes: 640
n = int(input())
*a, = map(int, input().split())

w = [0]*n
w[0] = sum(a) - 2*sum([ai for i, ai in enumerate(a) if (i + 1)%2 == 0])

for i in range(n - 1):
    w[i + 1] = 2*a[i] - w[i]

print(*w)


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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
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;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

string s;

int main(){
    cin >> s;
    int n = s.length();
    REP(i,n/2)
    {
        if(s[i]!=s[n-i-1])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    REP(i,n/2)
    {
        if(s[i]!=s[n/2-i-1])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    FOR(i,(n+1)/2,n)
    {
        if(s[i]!=s[n-i-1])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        string s=cin.next();
        int start =0;
        int goal = 0;
        for(int i=0;i<s.Length;i++)
        {
          if(s[i]=='A'){start=i;break;}
        }
        for(int i=s.Length-1;i>0;i--)
        {
          if(s[i]=='Z'){goal=i;break;}
        }
        Console.WriteLine(goal-start+1);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}


Measured memory_bytes: 13216
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <string>
#include <cmath>
#define SIZE 100005
#define INF 1000000000

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

vector <int> vec[SIZE];
int L[SIZE],R[SIZE];
int id[SIZE];
bool ans;

void solve(int v=0,int p=-1)
{
	L[v]=-INF-1,R[v]=INF+1;
	if(id[v]!=-1) L[v]=R[v]=id[v];
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to!=p)
		{
			solve(to,v);
			if(L[to]<-INF/2) continue;
			if(L[v]<-INF/2)
			{
				L[v]=L[to]-1;
				R[v]=R[to]+1;
			}
			else
			{
				if(abs(L[to])%2==abs(L[v])%2)
				{
					ans=false;
					return;
				}
				L[v]=max(L[v],L[to]-1);
				R[v]=min(R[v],R[to]+1);
			}
		}
	}
	if(L[v]>R[v]) ans=false;
}
void make(int v=0,int p=-1)
{
	if(v==0&&id[v]==-1) id[v]=L[v];
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to!=p)
		{
			if(id[to]==-1)
			{
				if(L[to]<=id[v]-1&&id[v]-1<=R[to]) id[to]=id[v]-1;
				else id[to]=id[v]+1;
			}
			make(to,v);
		}
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--;b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	memset(id,-1,sizeof(id));
	int Q;
	scanf("%d",&Q);
	while(Q--)
	{
		int v,p;
		scanf("%d %d",&v,&p);v--;
		id[v]=p;
	}
	ans=true;
	solve();
	if(!ans)
	{
		puts("No");
	}
	else
	{
		make();
		puts("Yes");
		for(int i=0;i<n;i++) printf("%d\n",id[i]);
	}
	return 0;
}


Measured memory_bytes: 15360
import sys, math, collections, heapq, itertools
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    file = sys.stdin.readline #single: int(file()), line: map(int, file().split())
    INF = 10 ** 25
    mod = 7 + 10 ** 9
    N = int(file())
    b = [[int(i) for i in input().split()] for j in range(N)]
    bset = set()
    for i in range(len(b)): bset |= {(b[i][0], b[i][1])}
    b.sort()
    maxpair = 0
    for i in range(len(b)):
        for j in range(i+1, len(b)):
            p, q = b[j][0] - b[i][0], b[j][1] - b[i][1]
            if p != 0 or q != 0:
                pair = 0
                for k in range(len(b)):
                    if (b[k][0] + p, b[k][1] + q) in bset:
                        pair += 1
                maxpair = max(maxpair, pair)
    print(N - maxpair)
    return 0
  
if __name__ == "__main__":
    solve()

Measured memory_bytes: 3444
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <string>
#include <functional>
#include <math.h>
#include <utility>
#define INF 100000000
using namespace std;
typedef pair<int,int> P;
int N,ans;
vector<int> vec,vec2,tmp;
void deal(int t){
	int fir=0;
	bool update=true;
	while(update){
		update=false;
		fir=max(t-6,0);
		int color=0;
		for(int i=max(t-6,0);i<min(t+6,(int)tmp.size());i++){
			if(tmp[i]==color&&i!=tmp.size()-1)continue;
			int count=i-fir;
			if(i==tmp.size()-1)count++;
			if(count>=4){		
				while(count--)tmp.erase(fir+tmp.begin());
				t=fir;
				update=true;
				break;
			}else{
				fir=i;color=tmp[i];
			}
		}
	}

	return;
}
int main()
{
	while(cin>>N&&N){
		vec.clear();vec2.clear();ans=N;
		for(int i=0;i<N;i++){
			int tmp;cin>>tmp;
			vec.push_back(tmp);
		}
		for(int i=0;i<N;i++){
			bool flag=false;
			if(1<=i&&i<N-1)if(vec[i-1]==vec[i+1]&&vec[i-1]!=vec[i])flag=true;
			if(i<N-3&&!flag)if(vec[i+1]==vec[i+2]&&vec[i+1]==vec[i+3])flag=true;
			if(3<=i&&!flag)if(vec[i-1]==vec[i-2]&&vec[i-1]==vec[i-3])flag=true;
			if(flag)vec2.push_back(i);
		}
		if(vec2.empty()){cout<<ans<<endl;continue;}
		for(int i=0;i<(int)vec2.size();i++){
			int m=vec2[i];
			if(m!=0){
				tmp=vec;tmp[m]=vec[m-1];deal(m);
				ans=min(ans,(int)tmp.size());
				if(m==N-1)continue;
				if(vec[m-1]!=vec[m+1]){
					tmp=vec;tmp[m]=vec[m+1];deal(m);
					ans=min(ans,(int)tmp.size());
				}
			}else{
				tmp=vec;tmp[m]=vec[m+1];deal(m);
				ans=min(ans,(int)tmp.size());
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
char itoa(int n) { return n + '0';}
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 () {
  int n = in();
  vvi a(n,vi(n));
  rep(i,n) {
    int u, k;
    cin >> u >> k;
    u--;
    rep(j,k) {
      int v;
      cin >> v;
      v--;
      a[u][v] = 1;
    }
  }
  rep(i,n)rep(j,n) printf("%d%c", a[i][j], j == n-1 ? '\n' : ' ');
  return 0;
}


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

	int n;
	int k;
	cin>>n>>k; 
	int ans = n;
		n=abs(n%k);
		ans = min(ans,n);
		n = k-n;
		ans = min(ans,n);
		cout<<ans;
}

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

using namespace std;

int N,M;
int mincost; 
int total; 

int main()
{

    int n,m;
    cin >>n>>m;
    for(int i;i<n;i++)
    {
        total |= 1<<i; 
    }

    vector<int> cost(m); 
    vector<int> mask(m); 
    for(int i=0;i<m;i++)
    {
        cin>>cost[i]; 
        //cout<<cost[i]<<endl; 
        int b;
        cin>>b;
        //cout<<b<<endl; 
        //cout<<"mask"; 
        for(int j=0;j<b;j++)
        {
            int t;
            cin >>t; 
            mask[i] |= 1<<(t-1); 
        }
            //cout<<mask[i]<<endl; 
    }


    const int INF=1e9; 
    vector<int> dp(5000,INF); 
    dp[0]=0; 
    for(int i=1;i<=m;i++)
    {
        for(int j=0;j< (1<<n);j++)
        {
            //cout<<"considering i & j "<<i<<" "<<j<< "and j|mask "<< (j|mask[i-1])<<endl; 
            //cout<<dp[j]<<endl; 
            dp[j|mask[i-1]] =min(dp[j|mask[i-1]],dp[j]+cost[i-1]);
        }
    }
    /*
    for(int j=0;j< (1<<n);j++)
    {
        cout<<dp[j]<<" "; 

    }
    */
    cout<<endl; 
    if(dp[(1<<n)-1]==INF)
    {
        dp[(1<<n)-1]=-1;    
    }
    cout<<dp[(1<<n)-1]<<endl; 
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  ll n; cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll q; cin >> q;
  vector<ll> b(q),c(q);
  rep(i,q) {
    cin >> b[i] >> c[i];
  }

  map<ll,ll> mp;
  ll sum = 0;
  rep(i,n) {
    mp[a[i]]++;
    sum += a[i];
  }

  rep(i,q) {
    ll cnt = mp[b[i]];
    sum -= cnt*b[i];
    sum += cnt*c[i];
    mp[b[i]] = 0;
    mp[c[i]] += cnt;
    cout << sum << "\n";
  }
  
  return 0;
}


Measured memory_bytes: 11412
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <random>

using namespace std;
int main()
{
  int n;
  cin >> n;
  int mid = n/2;
  vector<int> list;
  
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    list.push_back(a);
  }
  sort(list.begin(), list.end());
   
  cout << list[mid] - list[mid - 1] << endl;
  return 0;
}

Measured memory_bytes: 892
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7

def getlist():
	return list(map(int, input().split()))

def main():
	K = int(input())
	A, B = getlist()
	for i in range(1001):
		if A <= K * i and K * i <= B:
			print("OK")
			return

	print("NG")
	


if __name__ == '__main__':
	main()

Measured memory_bytes: 64936
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
template <typename T>
void warshall_floyd(vector<vector<T>> &g, T inf) {
    rep(k, g.size()) {
        rep(i, g.size()) {
            rep(j, g.size()) {
                if (g[i][k] == inf || g[k][j] == inf) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}


int main() {
    init();
    ll N, M, L;
    cin >> N >> M >> L;
    vvc<ll> G(N, vc<ll>(N,INF));
    rep(i, N) G[i][i] = 0;
    rep(i,M){
        ll a,b,c;
        cin >> a >> b >> c;
        a--, b--;
        if(c<=L){
            G[a][b] = c, G[b][a] = c;
        }
    }

    warshall_floyd(G, INF);

    vvc<ll> D(N, vc<ll>(N, INF));
    rep(i, N) D[i][i] = 0;
    rep(i,N)rep(j,N){
        if (i == j) continue;
        if (G[i][j] <= L) D[i][j] = 1;
    }

    warshall_floyd(D, INF);

    ll Q;cin>>Q;
    rep(_,Q){
        ll s, t;
        cin >> s >> t;
        s--,t--;
        cout << (D[s][t] == INF ? -1 : D[s][t] - 1) << endl;
    }
}

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

#define int long long

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int order = 1;
    while(true){
        if(order == 0){
            a -= d;
            if(a <= 0){
                cout << "No" << endl;
                break;
            }
            order = 1;
        }
        else{
            c -= b;
            if(c <= 0){
                cout << "Yes" << endl;
                break;
            }
            order = 0;
        }

    }
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a*b/gcd(a,b);
}

long long com(long long n,long long k){
	
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h,w;
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			string s;
			cin>>s;
			if(s=="snuke"){
				char H='A';
				H+=j-1;
				cout<<H;
				cout<<i<<endl;
			}
		}
	}
}

	


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

/*
regexを使う場合
  | -> or, どれか
  * -> 直前の文字を0回以上繰り返す
  ? -> 直前の文字を0回か1回繰り返す
*/ 

int main() {
  string s;
  cin >> s;
  // (dream(er)?|eraser?)* でも良い
  cout << (regex_match(s, regex("(dream|dreamer|erase|eraser)*")) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 28236
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9

int main(){

    while(1){
        int n; cin >> n;
        if(!n) break;
        vector<vector<int> > t(n, vector<int> (n + 1));
        for(int i = 0; i < n; i++){
            for(int j = 0; j <= n; j++){
                cin >> t[i][j];
            }
        }

        vector<int> DP((1<<n), INF);
        DP[0] = 0;

        for(int bit = 0; bit < (1<<n); bit++){
            int S = bit;
            int cost;
            for(int i = 0; i < n; i++){
                if(bit & (1<<i)){
                    S = S & ~(1<<i);
                    cost = t[i][0];
                    for(int j = 0; j < n; j++){
                        if(S & (1<<j)) cost = min(cost, t[i][j + 1]);
                    }
                    DP[bit] = min(DP[bit], DP[S] + cost);
                    S = S | (1<<i);
                }
            }
        }

        cout << DP[(1<<n) - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3372
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long int dp[101][21] = {0};
	int  n, s[101],i,j;
	scanf("%d", &n);
	for (i = 1; i <= n; i++)
		scanf("%d", &s[i]);
	dp[1][s[1]] = 1;
	for ( i = 1; i <= n-1; i++)
	{
		for (j = 0; j <21; j++)
		{
			if (dp[i][j] >=1)
			{
				if(j+s[i+1]<=20)
					dp[i + 1][j + s[i+1]] +=dp[i][j] ;
				if(j-s[i+1]>=0)
					dp[i + 1][ j- s[i+1]] += dp[i][j];
			}
		}
	}
	printf("%lld\n", dp[n - 1][s[n]]);
	return 0;
}

Measured memory_bytes: 3236
class Pond:
    def __init__(self, arg_left, arg_area):
        self.left = arg_left
        self.area = arg_area

form = input()
stack = []
stack2 = []
totalArea = 0
for i in range(len(form)):
    #'/'以外なら積む
    tmpForm = form[i]
    if tmpForm == '\\':
        stack.append(i)
    #'/'なら直前の\を探しに行く
    elif tmpForm == '/' and len(stack) > 0:
        xLeft = stack.pop()
        xRight = i
        tmpArea = xRight - xLeft
        totalArea += tmpArea

        #池が連続する場合の処理
        while len(stack2) > 0 and stack2[-1].left > xLeft:
            tmpArea += stack2.pop().area

        stack2.append(Pond(xLeft, tmpArea)) #新たな池を登録

print(totalArea)
ans = []
ans.append(len(stack2))
for pond in stack2:
    ans.append(pond.area)
print(' '.join(map(str, ans)))



Measured memory_bytes: 6448
package main

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

func main() {
	var sum float64
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		sum += 1 / float64(a)
	}
	fmt.Println(1 / sum)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int aa = (double)a/(double)0.08 + 0.999999;
    int bb = (double)b/(double)0.1 + 0.999999;
    if ((int)(aa*0.1) == b){
        cout << aa << endl;
    }else if ((int)(bb*0.08) == a){
        cout << bb << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n, a[114514], ans;
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	if (n % 2) {
		int last = a[n / 2];
		rep(i, n - 1) {
			if (i % 2 == 0) {
				ans += last - a[i / 2];
				last = a[i / 2];
			}
			else {
				ans += a[n - 1 - i / 2] - last;
				last = a[n - 1 - i / 2];
			}
		}
		int ans2 = 0;
		last = a[n / 2];
		rep(i, n - 1) {
			if (i % 2 == 0) {
				ans2 += a[n - 1 - i / 2] - last;
				last = a[n - 1 - i / 2];
			}
			else {
				ans2 += last - a[i / 2];
				last = a[i / 2];
			}
		}
		cout << max(ans, ans2) << endl;
	}
	else {
		int ans2 = 0;
		int last = a[n / 2];
		rep(i, n - 1) {
			if (i % 2 == 0) {
				ans += last - a[i / 2];
				last = a[i / 2];
			}
			else {
				ans += a[n -1- i / 2] - last;
				last = a[n -1- i / 2];
			}
		}
		last = a[n / 2 - 1];
		rep(i, n - 1) {
			if (i % 2 == 0) {
				ans2 += a[n - 1 - i / 2] - last;
				last = a[n - 1 - i / 2];
			}
			else {
				ans2 += last - a[n / 2];
				last = a[n / 2];
			}
		}
		cout << max(ans, ans2) << endl;
	}
}


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

#define int long long

int N, M;
bool G[8][8] = {{}};

int dfs(int b, int v) {
  if ( b == (1<<N)-1 ) return 1;

  int ret = 0;
  for ( int i = 0; i < N; i++ ) {
    if ( b&(1<<i) ) continue;
    if ( G[v][i] ) ret += dfs(b|(1<<i), i);
  }

  return ret;
}

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

  cin >> N >> M;

  for ( int i = 0; i < M; i++ ) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a][b] = true;
    G[b][a] = true;
  }  

  cout << dfs(1, 0) << endl;
  
  return 0;
}


Measured memory_bytes: 256
import itertools
n=int(input())
l=[]
for i in range(n):
  d=int(input())
  for dd in range(d):
    x,y=map(int,input().split())
    l.append([i,x-1,y])

ans=0
for p in itertools.product([0,1],repeat=n):
  for ll in l:
    if p[ll[0]]==1 and p[ll[1]]!=ll[2]:
      break
  else:
    ans=max(ans,sum(p))
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,c,i,a,s=0;
	cin >> n >> c;
	for(i=0; i<c; ++i){
		cin >> a;
		s += a;
	}
	cout << ((s/(n+1))+((s%(n+1))?1:0)) << endl;
	return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = (int)1e5 + 10;
ll gcd(ll a,ll b)
{
    return b ? gcd(b,a % b) : a;
}
char s1[maxn],s2[maxn];
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    scanf("%s %s",s1 + 1,s2 + 1);
    ll com = gcd(n,m);
    ll i = n / com,j = m / com,x = 1,y = 1;
    bool flag = 1;
    while (x <= n)
    {
        if (s1[x] != s2[y])
        {
            flag = 0;
            break;
        }
        x += i;
        y += j;
    }
    if (flag)
        printf("%lld\n",n / com * m);
    else
        printf("-1\n");
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    map<int,int> hoge;
    for(int i=1;i<=m;i++) hoge[i]=0;
    
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        for(int j=0;j<k;j++){
            int a;
            cin>>a;
            hoge[a]++;
        }
    }
    
    int ans=0;
    
    for(int i=1;i<=m;i++){
        if(hoge[i]==n) ans++;
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
from collections import deque
S=list(input())
Q=int(input())
Sque=deque(S)
re=1
for i in range(Q):
    q=input()
    if q=="1":
        re*=-1
    else:
        two,F,C=q.split()
        if re==1:
            if F=="1":
                Sque.appendleft(C)
            else:
                Sque.append(C)
        else:
            if F=="2":
                Sque.appendleft(C)
            else:
                Sque.append(C)
S=list(Sque)
if re==-1:
    S.reverse()

ans="".join(S)
print(ans)



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

int main() {
    int N;
    cin >> N;
    long long a[N][N];
    long long b[N][N];
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            cin >> a[i][j];
            b[i][j] = a[i][j];
        }
    }

    for (int k = 0; k < N; k++)
    {
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                if(b[i][j] > b[i][k] + b[k][j]) b[i][j] = b[i][k] + b[k][j];
            }
        }
    }

    bool can = true;
    long long ans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i+1; j < N; j++)
        {
            if(b[i][j] < a[i][j]) {
                can = false;
            }
            else {
                bool path = true;
                for (int k = 0; k < N; k++)
                {
                    if(i != k && j != k && b[i][j] == b[i][k] + b[k][j]) {
                        path = false;
                    }
                }
                if(path) ans += a[i][j];
            }
        }
    }

    if(can) cout << ans << endl;
    else cout << "-1" << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <math.h>
using namespace std;


int main(){
    int s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < 3; i++){
        if ((s%(int)pow(10,i+1)) / (int)pow(10,i) == 1){
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int Min(int a, int b, int c) {
	if (a <= b) { return std::min(a, c); }
	else return std::min(b, c);
}
int main(void) {
	int a, b; cin >> a >> b;
	if (b % a == 0)cout << a + b << endl;
	else cout << b-a << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/

const int INF = 1e9 - 1;

int ans = INF;
int k;
void dfs(int i, int c) {
  if (i == 0) {
    amin(ans, c);
    return;
  }
  dfs(i - 1, 2 * c);
  dfs(i - 1, c + k);

}

void Calc() {

  var(int, n);
  k = in;
  dfs(n, 1);
  cout << (ans) << endl;

}


Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define inf 10000000000000000
#define N 1000000007
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}

//edge cases when n=1 , m=1. wrong variable in loop. if<->while
signed main()
{
	speed
	//global var
	int n,k;cin>>k>>n;
	vector<int> inp(n);
	vector<int> rinp(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>inp[i];
		rinp[i]=k-inp[i];
	}
	int ans=inp[n-1]-inp[0];
	for(int i=0;i<n-1;++i)
	{
		ans=min(ans,inp[i]+rinp[i+1]);
	}
	cout<<ans<<"\n";

}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;


void trace(int A[],int N){
    REP(i,N){
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}

int binarysearch(int key,int n,int A[]){
    int left = 0,right = n,mid;
    while(left < right){
        mid = (left + right) / 2;
        if(key == A[mid]) return 1;
        if(key > A[mid])left = mid + 1;
        else right = mid;
    }
    return 0;
}

int main(){
    int n,q,ans;
    cin >> n;
    int s[n];
    REP(i,n)cin >> s[i];
    cin >> q;
    REP(i,q){
        int k;
        cin >> k;
        if(binarysearch(k,n,s))ans++;
    }
    cout << ans << endl;
}



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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, i;
  cin >> N >> i;
  cout << N - i + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
def check(x):
  if x==0:
    return 0
  else:
    t=0
    for i in range(N):
      t+=math.ceil(A[i]/x)-1
    if t<=K:
      return 10
    else:
      return 0
low=1
high=max(A)
sig=(low+high)//2
while True:
  if check(sig)==10:
    if check(sig-1)==0:
      ans=sig
      break
    else:
      high=sig-1
      sig=(low+high)//2
  else:
    low=sig+1
    sig=(high+low)//2
print(ans)


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

int main(){
//freopen("text.in.txt","r",stdin);

int a,b;
cin>>a>>b;
int sum=0;
if(a==3)
    sum+=100000;
if(a==2)
    sum+=200000;
    if(a==1)
    sum+=300000;
    if(b==3)
    sum+=100000;
if(b==2)
    sum+=200000;
    if(b==1)
    sum+=300000;
    if(a==1 && b==1)
        sum+=400000;
    cout<<sum;
return 0;
}


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

int mark[100010], parent[100010];

int nma[100010];
int find(int x){
	if(nma[x] == x)return x;
	return nma[x] = find(nma[x]);
}
// x >= y
void unite(int x, int y){
	nma[y] = find(x);
}

char type[100010];
int v[100010];

int main(){
	int N, Q;
	while(cin >> N >> Q, N | Q){
		for(int i=2;i<=N;i++){
			cin >> parent[i];
		}

		memset(mark, 0, sizeof(mark));
		mark[1] = 1;
		for(int i=0;i<Q;i++){
			cin >> type[i] >> v[i];
			if(type[i] == 'M'){
				++mark[v[i]];
			}
		}

		for(int i=1;i<=N;i++){
			nma[i] = i;
		}
		for(int i=1;i<=N;i++){
			if(mark[i] == 0){
				unite(parent[i], i);
			}
		}

		ll res = 0;
		for(int i=Q-1;i>=0;i--){
			if(type[i] == 'M'){
				--mark[v[i]];
				if(mark[v[i]] == 0){
					unite(parent[v[i]], v[i]);
				}
			} else {
				res += find(v[i]);
			}
		}
		
		cout << res << endl;	
	}

	return 0;
}

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

int main(int argc, char const *argv[])
{
    int A, B;
    cin >> A >> B;

    for (size_t i = 0; i <= 1000; i++)
    {
        int a = i * 0.08;
        int b = i * 0.1;
        if (a == A && b == B)
        {
            cout << i << endl;
            return 0;
        }
    }

    cout << "-1" << endl;
}


Measured memory_bytes: 256