akhauriyash/Code-Regression huggingface dataset:
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { it.toLong() }.groupBy { it }.filter { it.value.size >= 2 }

    if (aa.isEmpty()) {
        println(0)
        return
    }

    if (aa.size == 1) {
        val a = aa.entries.first()
        if (a.value.size < 4) {
            println(0)
        } else {
            println(a.key * a.key)
        }
        return
    }

    val sorted = aa.entries.sortedByDescending { it.key }
    if (sorted[0].value.size >= 4) {
        println(sorted[0].key * sorted[0].key)
    } else {
        println(sorted[0].key * sorted[1].key)
    }
}



Measured memory_bytes: 61224
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
#include<bitset>

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;

int main() {
	int n, i, j, k, m;
	vector< vi >a;

	cin >> n;
	a.resize(n);
	rep(i, n) {
		a[i].resize(n);
	}
	m = n * (n - 1) / 2;
	if (n % 2 == 0) {
		rep(i, n / 2) {
			a[i][n - (i + 1)] = 1;
			m--;
		}
	}
	else {
		rep(i, n / 2) {
			a[i][n - (i + 2)] = 1;
			m--;
		}
	}
	cout << m << endl;
	rep(i, n) {
		for (j = i + 1; j < n; j++) {
			if (a[i][j] == 0)cout << i + 1 << " " << j + 1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
N=int(input())

list=[]
for i in range(N):
    list.append(str(input()))


a = list.count("AC")
b = list.count("WA")
c = list.count("TLE")
d = list.count("RE")

print("AC x "+ str(a))
print("WA x "+ str(b))
print("TLE x "+ str(c))
print("RE x "+ str(d))


Measured memory_bytes: 16228
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <vector>

#define MAX_N (100000L)
#define MAX_M (100000L)

using namespace std;

void topological_sort(const vector<vector<long>> &adj_lists, vector<long> &ns) {
  // N is the number of nodes in the graph
  const long N = adj_lists.size();
  // count the number of incoming edges for each node
  vector<long> num_ins(N, 0);
  for (long i = 0; i < N; i++) {
    for (long j : adj_lists[i]) {
      num_ins[j]++;
    }
  }

  // queue to store nodes with no more incoming edges
  queue<long> que;
  // initialize queue
  for (long i = 0; i < N; i++) {
    if (num_ins[i] == 0) {
      que.push(i);
    }
  }
  // update
  long k = 0;
  while (!que.empty()) {
    // take out element from the front of the queue
    const long i = que.front();
    ns[k++] = i;
    que.pop();
    // remove all edges going out of this node
    for (long j : adj_lists[i]) {
      num_ins[j]--;
      if (num_ins[j] == 0) {
        que.push(j);
      }
    }
  }
}

int main() {
  // read inputs
  long N, M, xs[MAX_M], ys[MAX_M];
  scanf("%ld %ld", &N, &M);
  for (long k = 0; k < M; k++) {
    scanf("%ld %ld", &xs[k], &ys[k]);
    xs[k]--;  // NOTE : modified input
    ys[k]--;  // NOTE : modified input
  }

  // create graph
  vector<vector<long>> adj_lists(N, vector<long>());
  for (long k = 0; k < M; k++) {
    const long x = xs[k], y = ys[k];
    adj_lists[x].push_back(y);
  }

  // topological sort
  vector<long> ns(N, 0);
  topological_sort(adj_lists, ns);
//   for (long i = 0; i < N; i++) {
//     printf("%ld ", ns[i]);
//   }
//   printf("\n");

  // solve dp
  long dps[MAX_N];
  for (long k = N - 1; k >= 0; k--) {
    const long i = ns[k];
    long dp = 0;
    for (long j : adj_lists[i]) {
      dp = max(dp, dps[j] + 1);
    }
    dps[i] = dp;
  }

  // print answer
  long ans = 0;
  for (long i = 0; i < N; i++) {
    ans = max(ans, dps[i]);
  }
  printf("%ld\n", ans);
}

Measured memory_bytes: 8832
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max)) 

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, m;
	VI ns, ms;
	while(1){
		int ans_n = -1, ans_m = -1;
		ns.clear();
		ms.clear();
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		rep(i, n){
			int a;
			cin >> a;
			ns.pb(a);
		}
		rep(i, m){
			int a;
			cin >> a;
			ms.pb(a);
		}

		sort(rall(ns));
		sort(rall(ms));

		rep(i, n){
			rep(j, m){
				VI a, b;
				a = ns;
				b = ms;
				swap(a[i], b[j]);
				if(accumulate(all(a), 0) == accumulate(all(b), 0)){
					ans_n = ns[i];
					ans_m = ms[j];
				}
			}
		}
		
		if(ans_n == -1){
			cout << -1 << endl;
		} else {
			cout << ans_n << " " << ans_m << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1220
n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]
count = 0
re = "No"

for i in range(n - 2):
    if d[i][0] == d[i][1] and d[i+1][0] == d[i+1][1] and d[i+2][0] == d[i+2][1]:
        re = "Yes"
        break

print(re)


Measured memory_bytes: 62496
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int f[100][10];
int p[100][11];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < 10; ++j)
            cin >> f[i][j];

    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= 10; ++j)
            cin >> p[i][j];

    int sol = -1e9;
    for (int i = 1; i < (1 << 10); ++i)
    {
        vector<int> c(n);
        for (int j = 0; j < n; ++j)
            for (int k = 0; k < 10; ++k)
                if (f[j][k] && (i & (1 << k)))
                    c[j]++;

        int profit = 0;
        for (int j = 0; j < n; ++j)
            profit += p[j][c[j]];
        sol = max(sol, profit);
    }
    cout << sol;
}


Measured memory_bytes: 256
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from collections import Counter
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    M = 10**6

    A.sort()
    C = Counter(A)
    ans = 0
    seen = [0] * (M+1)
    A = set(A)
    for a in A:
        if C[a] == 1 and seen[a] == 0:
            ans += 1
        for j in range(1, M+1):
            if a * j > M:
                break
            seen[a*j] = 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 154432
#include <iostream>

using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  const auto ng = (A == B && B == C && C == A) || (A != B && B != C && C != A);
  cout << (!ng ? "Yes" : "No") << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


ll mod = 998244353;
struct mint {
	ll x;
	mint(ll x = 0) :x(x%mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
};

void f(vector<mint>&a) {
	int n = a.size();
	for (int k = 1; k < n; k++) {
		for (int i = 2 * k; i < n; i += k) {
			a[k] += a[i];
		}
	}
}
void inv_f(vector<mint>&a) {
	int n = a.size();
	for (int k = n - 1; k >= 1; k--) {
		for (int i = 2 * k; i < n; i += k) {
			a[k] -= a[i];
		}
	}
}

ll modpow(ll a, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

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

	const int MAX = 1000000;
	int n;
	cin >> n;
	vector<int>a(n);
	vector<mint>x(MAX+1);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		x[a[i]] += (mint)a[i];
	}
	f(x);

	vector<mint>y(MAX+1);
	for (int i = 1; i <= MAX; i++) {
		y[i] = x[i] * x[i];
	}
	inv_f(y);

	fore(x, a) {
		y[x] -= (mint)x*(mint)x;
	}

	mint inv2 = modpow(2,mod-2);
	for (int i = 1; i <= MAX; i++) {
		y[i] *= inv2;
	}

	mint ans = 0;
	for (int i = 1; i <= MAX;i++) {
		mint invi = modpow(i,mod-2);
		ans += y[i] * invi;
	}
	puts(ans.x);

	return 0;
}

Measured memory_bytes: 16640
import java.util.Scanner;

public final class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        int[] p = new int[n];
        for(int i=0; i<p.length; i++){
            p[i] = stdIn.nextInt();
        }
        int counter = 0;

        for(int i=1; i<p.length-1; i++){
            if((p[i-1] < p[i] && p[i] <= p[i+1]) || (p[i+1] < p[i] && p[i] <= p[i-1])){
                counter++;
            }
        }

        System.out.println(counter);
    }
}

Measured memory_bytes: 21204
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>

using namespace std;

struct rectagle {
	int pos, height;
};
//13233
int getMax(int T[], int W) {

	stack<rectagle> S;
	int maxv = 0;
	for (int i = 0; i <= W; ++i) {
		rectagle r;
		r.pos = i;
		if (i != W) {
			r.height = T[i];
		} else {
			r.height = 0;
		}
		if (S.empty() || r.height > S.top().height) {
			S.push(r);
		} else {
			int prepos = i;
			while (!S.empty() && S.top().height > r.height) {
				rectagle pop = S.top();
				S.pop();
				int area = (i - pop.pos) * pop.height;
				prepos = pop.pos;
				maxv = max(maxv, area);
			}
			r.pos = prepos;
			S.push(r);
		}
	}

	return maxv;
}

int main() {

	int H, W;
	scanf("%d %d", &H, &W);

	int A[H][W];
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			scanf("%d", &A[i][j]);
		}
	}
	int T[H][W];
	for (int j = 0; j < W; ++j) {
		for (int i = 0; i < H; ++i) {
			if (A[i][j] == 0) {
				if (i == 0) {
					T[i][j] = 1;
				} else {
					T[i][j] = T[i - 1][j] + 1;
				}
			} else {
				T[i][j] = 0;
			}
		}
	}

	int maxv = 0;
	for (int i = 0; i < H; ++i) {
		maxv = max(maxv, getMax(T[i], W));
	}
	cout << maxv << endl;

	return 0;
}

Measured memory_bytes: 18548
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch MakingTriangle | diff MakingTriangle.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address MakingTriangle.cpp && ./a.out

/*

 8/15/2020

 5:05-

 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

void solve() {
  sort(A,A+N);
  int res=0;
  REP(k,N)REP(j,k)REP(i,j) {
    if(A[i]!=A[j]&&A[j]!=A[k]&&A[i]+A[j]>A[k]) ++res;
  }
  cout<<res<<endl;
}

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

  cin>>N;
  REP(i,N) cin>>A[i];
  solve();

  return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int n,b[10],a[3][3];
bool ake[3][3];
int main(){
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)cin>>a[i][j];
  cin>>n;
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      ake[i][j]=false;
      for(int k=0;k<n;k++)
        if(b[k]==a[i][j])
          ake[i][j]=true;
    }
  }
  string unko="No";
  for(int i=0;i<3;i++)
    if(ake[i][0] and ake[i][1] and ake[i][2])
      unko="Yes";
  for(int i=0;i<3;i++)
    if(ake[0][i] and ake[1][i] and ake[2][i])
      unko="Yes";
  if(ake[0][0] and ake[1][1] and ake[2][2])
    unko="Yes";
  if(ake[0][2] and ake[1][1] and ake[2][0])
    unko="Yes";
  cout<<unko<<endl;
  return 0;
}


Measured memory_bytes: 256
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

westernmost = max(x)
easternmost = min(y)
if max(X, westernmost) >= min(Y, easternmost):
    print("War")
else:
    print("No War")

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

int main(void){
  string S;
  cin>>S;
  if(S=="RRR"){
    cout<<3<<endl;
  }
  else if(S=="RRS" or S=="SRR"){
    cout<<2<<endl;
  }
  else if(S=="SSS"){
    cout<<0<<endl;
  }
  else{
    cout<<1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;


int main(){

	int n,length,m_length,index;
	char ORDER[7],message[26],tmp,work[26];

	scanf("%d",&n);

	for(int loop = 0; loop < n; loop++){

		scanf("%s",ORDER);

		for(length = 0; ORDER[length] != '\0';length++);

		scanf("%s",message);

		for(m_length = 0; message[m_length] != '\0';m_length++);

		for(int i = length-1; i >= 0; i--){
			switch(ORDER[i]){
			case 'J':
				tmp = message[m_length-1];
				for(int k = m_length-2; k >=0; k--){
					message[k+1] = message[k];
				}
				message[0] = tmp;
				break;
			case 'C':
				tmp = message[0];
				for(int k = 1; k < m_length; k++){
					message[k-1] = message[k];
				}
				message[m_length-1] = tmp;
				break;
			case 'E':
				if(m_length % 2 == 0){
					index = 0;
					for(int k = m_length/2; k < m_length; k++){
						work[index++] = message[k];
					}
					for(int k = 0; k < m_length/2;k++){
						work[index++] = message[k];
					}
					for(int k = 0; k < m_length; k++)message[k] = work[k];
				}else{
					index = 0;
					for(int k = (m_length+1)/2; k < m_length; k++){
						work[index++] = message[k];
					}
					work[index++] = message[(m_length-1)/2];
					for(int k = 0; k < (m_length-1)/2;k++){
						work[index++] = message[k];
					}
					for(int k = 0; k < m_length; k++)message[k] = work[k];
				}
				break;
			case 'A':
				index = 0;
				for(int k = m_length-1; k >= 0; k--){
					work[index++] = message[k];
				}
				for(int k = 0; k < m_length; k++)message[k] = work[k];
				break;
			case 'P':
				for(int k = 0; k < m_length; k++){
					if(message[k] >= '0' && message[k] <= '9'){
						if(message[k] == '0'){
							message[k] = '9';
						}else{
							message[k] -= 1;
						}
					}
				}
				break;
			case 'M':
				for(int k = 0; k < m_length; k++){
					if(message[k] >= '0' && message[k] <= '9'){
						if(message[k] == '9'){
							message[k] = '0';
						}else{
							message[k] += 1;
						}
					}
				}
				break;
			}
		}

		printf("%s\n",message);
	}

    return 0;
}

Measured memory_bytes: 2508
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
// 104, 79, 118, 
// 169, 133, 17, 
// 180, 106, 125, 
// 171, 42, 159, 
// 45, 76, 101, 
int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	long long ret=0;
	long long ks=1;
	for(int i=0;i<a;i++)for(int j=0;j<a;j++){
		printf("? %d %d %d %d\n",i,j,i,j);
		fflush(stdout);
		int t;
		scanf("%d",&t);
		if(t)ret=(ret+ks)%d;
		ks=ks*2%d;
	}
	int sz=ret/8000000%200;
	char *p = new char[sz*1000000];
	for(int i=0;i<sz*1000000;i++)p[i]='e';
	printf("! %lld\n",ret);
}

Measured memory_bytes: 96464
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <algorithm>

using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> W(N,0);
  int sum = 0;
  for(int i=0;i<N;i++) {
    int w;
    cin >> w;
    sum += w;
    W[i] = w;
  }
  int minDiff = __INT_MAX__;
  int W1 = 0;
  int W2 = sum;
  for(int i=0;i<N;i++) {
    W1 += W[i];
    W2 -= W[i];
    int v = abs(W1-W2);
    if (v < minDiff) minDiff = v;
    else {
      break;
    }
  }
  cout << minDiff << endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

void Main() {
  // code
  int n, god = 0, minc = 0;
  cin >> n;
  vector<bool> color(8, false);
  rep(i, n) {
    int a;
    cin >> a;
    if (a < 400)
      color.at(0) = true;
    else if (a < 800)
      color.at(1) = true;
    else if (a < 1200)
      color.at(2) = true;
    else if (a < 1600)
      color.at(3) = true;
    else if (a < 2000)
      color.at(4) = true;
    else if (a < 2400)
      color.at(5) = true;
    else if (a < 2800)
      color.at(6) = true;
    else if (a < 3200)
      color.at(7) = true;
    else
      god++;
  }
  rep(i, 8) if (color.at(i)) minc++;
  cout << (minc == 0 ? 1 : minc) << " " << minc + god << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
from fractions import Fraction
from decimal import Decimal

a, b = map(float, input().split())
# print(b)
# print(format(b, '.15f'))
# b = Fraction(b, 10)
# print(b)

ans = Decimal(str(a)) * Decimal(str(b))
# ans = seki / (10**15)
print(int(ans))

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  int n,m; cin>>n>>m;
  vector<int> d(m, 0);
  for (int i=0; i<n; i++) {
    int k; cin>>k;
    for (int j=0; j<k; j++) {
      int a; cin>>a;
      d[a-1]++;
    }
  }
  int ans=0;
  for (int i=0; i<m; i++) {
    if (d[i]==n) ans++;
  }
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

struct union_find {
	vector<int> v;
	int k;
	union_find(int n) : v(n, -1), k(0) {}
	int find(int x) { return (v[x] < 0) ? x : (v[x] = find(v[x])); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x != y) {
			if (-v[x] < -v[y]) swap(x, y);
			v[x] += v[y]; v[y] = x;
			k++;
		}
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int main() {
	for (;;) {
		int n, m; cin >> n >> m;
		if (n == 0) break;
		vector<int> s(m), t(m), c(m);
		for (int i = 0; i < m; i++) {
			cin >> s[i] >> t[i] >> c[i];
			s[i]--; t[i]--;
		}
		for (int C = 1; C <= 1000; C++) {
			union_find ufs(n), ufe(n), ufg(n);
			for (int i = 0; i < m; i++) {
				if (c[i] <= C) ufs.unite(s[i], t[i]);
				if (c[i] >= C) ufg.unite(s[i], t[i]);
			}
			if (ufs.k >= n / 2 && ufg.k >= n / 2 - 1) {
				cout << C << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1328
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int m = scanner.nextInt();
		int n = scanner.nextInt();
	
		Map<Integer, List<Integer>> map = new HashMap<Integer, List<Integer>>();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 1; i <= m; i++) {
			map.put(i, new ArrayList<Integer>());
			if (i != 2) {
				list.add(i);
			}
		}
		int[] deg = new int[m + 1];
		while (n-- > 0) {
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			deg[y]++;
			map.get(x).add(y);

		}
		int y = 0;
		while (list.size() != 0) {
			int x = list.get(y);
			if (deg[x] == 0 && x != 2) {
				System.out.println(x);
				deg[x] = -1;
				for (int t : map.get(x)) {
					deg[t]--;
				}
				list.remove(y);
				if (y == list.size()) {
					y--;
				}
			} else {
				y = (y + 1) % list.size();
			}
		}
		System.out.println(2);
	}
}

Measured memory_bytes: 18568
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
bool cal(string s, int &idx) {
	if (s[idx] == 'T') {
		idx++;
		return true;
	}
	if (s[idx] == 'F') {
		idx++;
		return false;
	}
	if (s[idx] == '-') {
		idx++;
		return !cal(s,idx);
	}

	if (s[idx] == '(') {
		bool val1=cal(s, ++idx);
		int how;
		if (s[idx] == '*')
			how = 0;
		if (s[idx] == '+')
			how = 1;
		if (s[idx] == '>')
			how = 2;
		bool val2 = cal(s, ++idx);
		idx++;
		if (how == 0) {
			return val1&&val2;
		}
		if (how == 1) {
			return val1||val2;
		}
		if (how == 2) {
			return !(val1 && !val2);
		}
		//??\??????
		return true;
	}
	//??\??????
	return true;
}

int main() {
	string s;
	while (cin >> s, s != "#") {
		string ans = "YES";
		auto pos = s.find("->");
		while (pos != string::npos) {
			s.replace(pos, 2, ">");
			pos = s.find("->", pos + 1);
		}
		pos = s.find("--");
		while (pos != string::npos) {
			s.replace(pos, 2, "");
			pos = s.find("--", pos);
		}
		int eq;
		REP(k, s.length())
			if (s[k] == '=')
				eq = k;

		REP(i, 2048) {
			string s2 = s;
			REP(j, 11) {
				REP(k, s2.length()) {
					if (s2[k] == 'a' + j)
						if ((i >> j) & 1) {
							s2[k] = 'T';
						}
						else {
							s2[k] = 'F';
						}
				}
			}
			int idx1 = 0, idx2 = 0;
			string s3 = s2.substr(0, eq);
			string s4 = s2.substr(eq + 1, s2.length() - eq - 1);
			if (cal(s3, idx1) != cal(s4, idx2)) {
				ans = "NO";
				break;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3184
s = []
for t in input().split():
	try:
		v = int(t)
	except ValueError:
		a = s.pop()
		b = s.pop()
		if t == '+': v = b + a
		elif t == '-': v = b - a
		elif t == '*': v = b * a
	s.append(v)
print(s.pop())


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

int n, q, tend, ed;
string st;

int main() {
    cin >> n >> q;
    queue<pair<string,int>> p;
    for (int i=0; i<n; i++) {
        cin >> st >> ed;
        p.push({st, ed});
    }
    for (int t=0; !p.empty();) {
        if (p.front().second > q) {
            p.front().second -= q;
            t +=q;
            p.push({p.front().first, p.front().second});
            p.pop();
        }
        else {
            t+=p.front().second;
            cout << p.front().first << " " << t << endl;
            p.pop();
        }
    }
}


Measured memory_bytes: 6296
import java.util.Scanner;

public class Main{
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);

        /*
         * 標準Int入力 
         * int y = scan.nextInt();
         */
        int n = scan.nextInt();
        int k = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();
        if (n <= k){
            System.out.println(n * x);
        }else{
            System.out.println(k * x + (n - k) * y);
        }
    }

    public static int xx(final int n) {
        int count = 0;

        for (int i = 1; i <= n; i++) {
            count = count + i;
        }

        return count;
    }

    public static void test() {
        System.out.println("テストだよ~");
    }

    public static int max(final int x, final int y) {
        if (x > y){
            return x;
        }else{
            return y;
        }
    }
}

Measured memory_bytes: 23764
require 'set'
m = gets.to_i
m.times do
    s = gets.strip
    set = Set.new
    for i in 1...s.length
        a = s[0...i]
        b = s[i...s.length]
        set.add(a + b)
        set.add(a + b.reverse)
        set.add(b + a)
        set.add(b + a.reverse)
        set.add(a.reverse + b)
        set.add(a.reverse + b.reverse)
        set.add(b.reverse + a)
        set.add(b.reverse + a.reverse)
    end
    puts set.size
end

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

int main(){
  int x,n;
  cin>>x>>n;
  vector<int> d(102);
  rep(i,n){
    int p;
    cin>>p;
    d[p]=1;
  }
  P ans(99999,-1);
  for(int i=0;i<=101;i++){
    if(d[i]==1) continue;
    int dif=abs(x-i);
    ans=min(ans,P(dif,i));
  }
  cout<<ans.second<<endl;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    if(t.size()>s.size()){
        cout << "UNRESTORABLE";
        return 0;
    }

    int sz = t.size(), siz = s.size();
    for(int i=s.size()-1;i>=0;i--){
        if(i+sz<=siz){
            bool chk = 1;
            for(int j=0,k=i;j<sz;j++,k++){
                if(s[k]==t[j] || s[k]=='?')continue;
                else{chk=0;break;}
            }
            if(chk==1){
                for(int j=0,k=i;j<sz;j++,k++)
                    s[k] = t[j];
                for(int i=0;i<siz;i++)if(s[i]=='?')s[i]='a';
                cout << s;
                return 0;
            }
        }
    }
    cout << "UNRESTORABLE";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int X, N;
	int p[100];
	cin >> X >> N;
	for(int i = 0; i < N; i++){
		cin >> p[i];
	}
	
	bool OK[102];
	fill(OK, OK+102, true);
	for(int i = 0; i < N; i++){
		OK[p[i]] = false;
	}
	
	int min = abs(X-(-1));
	int ans = -1;
	
	for(int i = 0; i <= 101; i++){
		if(OK[i]){
			if(abs(X-i) < min){
				min = abs(X-i);
				ans = i;
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include <functional>
using namespace std;
typedef pair<int,int> mypair;

int main(void){
int n,r;
while(1)
{
cin>>n>>r;
if(n==0)break;
vector<mypair> huda(n);
mypair temp;
for(int i=0;i<n;i++){
	temp.first=n-i;
temp.second=n-i;
huda[i]=temp;
}


int p,c;
for(int i=0;i<r;i++){
	cin>>p>>c;
	for(int j=0;j<p-1;j++)
	huda[c+j].first=huda[j].second;
	for(int j=0;j<c;j++)
	huda[j].first=huda[p-1+j].second;
	for(int j=0;j<n;j++){
		huda[j].second=huda[j].first;
	}
	
}
//for(int i=0;i<n;i++)
//cout<<huda[i].first<<' '<<huda[i].second<<endl;
cout<<huda[0].second<<endl;
}
return 0;
}

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

int main(){
	double ans,sx,sy,x1,y1,x2,y2;
	
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	
	sx = x2 - x1;
	sy = y2 - y1;
	ans = sqrt(sx*sx + sy*sy);
	
	printf("%lf\n",ans);
	
	return 0;
}


Measured memory_bytes: 2104
#define LOCAL

#undef _GLIBCXX_DEBUG

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

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define LLINF 100000000000000005LL
#define INF (int)1e9+1
#define pb push_back

// Copied from Gennady-Korotkevich's template

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string)s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}\n";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto& x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}\n";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}

void debug_out() {
	cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "\n[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// End of Gennady-Korotkevich's template 

using llong = long long;
using PII = pair<int, int>;

int main()
{
	IOS;
	int n, x, t;
	cin >> n >> x >> t;
	cout << ((n+x-1) / x) * t;
	return 0;
}


Measured memory_bytes: 3656
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define INF 10000000000000000

int main(){
  ll n,m,p,a,b,c;
  cin >> n >> m >> p;
  vector<pair<ll,ll> > graph[n+1];
  vector<pair<ll,ll> > graph_inv[n+1];
  ll from1[n+1],toN[n+1];

  for(int i=0;i<m;i++){
    cin >> a >> b >> c;
    graph[a].push_back(make_pair(b,p-c));
    graph_inv[b].push_back(make_pair(a,p-c));
  }
  for(int i=0;i<n+1;i++){
    from1[i] = 0;
    toN[i] = 0;
  }
  from1[1] = 1;
  queue<ll> q;
  q.push(1);
  while(!q.empty()){
    ll now = q.front();
    q.pop();
    ll temp;
    for(int i=0;i<graph[now].size();i++){
      temp = graph[now][i].first;
      if(from1[temp]==0){
        from1[temp] = 1;
        q.push(temp);
      }
    }
  }

  q.push(n);
  toN[n] = 1;
  while(!q.empty()){
    ll now = q.front();
    q.pop();
    ll temp;
    for(int i=0;i<graph_inv[now].size();i++){
      temp = graph_inv[now][i].first;
      if(toN[temp]==0){
        toN[temp] = 1;
        q.push(temp);
      }
    }
  }

  bool loop = false;
  for(int i=1;i<n+1;i++){
    for(int j=0;j<graph[i].size();j++){
      if(i != graph[i][j].first) continue;
      if(from1[i]+toN[i] == 2){
        if(graph[i][j].second < 0) loop = true;
      }
    }
  }
  if(loop){
    cout << -1 << endl;
    return 0;
  }

  ll dist[n+1];
  for(int i=0;i<n+1;i++){
    dist[i] = INF;
  }
  dist[1] = 0;
  for(int i=0;i<n;i++){
    loop = false;
    for(int j=1;j<n+1;j++){
      if(dist[j] == INF) continue;
      if(from1[j]+toN[j] != 2) continue;
      for(int k=0;k<graph[j].size();k++){
        ll now = graph[j][k].first;
        if(now == j) continue;
        if(from1[now]+toN[now] != 2) continue;
        if(dist[now] > dist[j]+graph[j][k].second){
          dist[now] = dist[j]+graph[j][k].second;
          loop = true;
        }
      }
    }
  }
  if(loop){
    cout << -1 << endl;
    return 0;
  }
  cout << max(0ll,-1*dist[n]) << endl;

  return 0;
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n,q; cin >> n >> q;
    string str; cin >> str;
    vl s(n+1);
    rep(i,n){
        if(i+1 < n && str[i] =='A' && str[i+1] == 'C')s[i+1] = s[i]+1;
        else s[i+1] = s[i];
    }
    rep(i,q){
        int l,r; cin >> l >> r;
        cout << s[--r]-s[--l] << endl;
    }
}


Measured memory_bytes: 1872
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int l, r;
    cin >> l >> r;
    vi v;
    for (int i = l; i <= min(r, l + 2019); ++i)
        v.push_back(i % 2019);
    int sol = 2019;
    for (int i = 0; i < v.size(); ++i)
        for (int j = i + 1; j < v.size(); ++j)
            sol = min(sol, (v[i] * v[j]) % 2019);
    cout << sol;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i = n; i < (int) N; i++)
#define p(s)		cout<<(s)<<endl
using namespace std;

int main() {
	int a,b,c;
	set<int> s;
	cin>>a>>b>>c;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	p(s.size());
	return 0;
}


Measured memory_bytes: 256
import sys
N,L = map(int,input().split())
apples = [L+i for i in range(N)]
best = sum(apples)
if 0 in apples:
    print(sum(apples))
elif L>=0 :
    print(sum(apples)-apples[0])
else :
    print(sum(apples)-apples[len(apples)-1])

Measured memory_bytes: 3060
x , y , a , b , c = map(int,input().split())
p = sorted(list(map(int,input().split())),reverse=True)
q = sorted(list(map(int,input().split())),reverse=True)
r = sorted(list(map(int,input().split())),reverse=True)

d = sorted(p[:x]+q[:y]+r,reverse=True)
print(sum(d[:(x+y)]))

Measured memory_bytes: 22720
#include <iostream>
using namespace std;
main(){
  int data[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  cout <<data[k-1];
}


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

int n,p;
int dp[101][76];

bool isp(int n){
    for(int i=2;i*i<=n;++i)if(n%i==0)return 0;
    return 1;
}

int main(){
    cin>>n;
    dp[0][1]=1;
    for(int i=2;i<=n;++i){
        if(isp(i)==0)continue;
        int cnt=0;
        for(int j=1;j<=n;++j){
            int a=j;
            while(a%i==0)cnt++,a/=i;
        }

        for(int j=0;j<=cnt;++j){
            for(int k=0;k*(j+1)<=75;k++){
                dp[i][k*(j+1)]+=dp[p][k];
            }
        }
        p=i;
    }
    cout<<dp[p][75]<<endl;
}

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

e = [[] for _ in range(n)]
# e[switch] : 接続先電球リスト

for i in range(m):
    k, *s = map(int, input().split())
    s = map(lambda x: x - 1, s)
    for ss in s:
        e[ss].append(i)

p = tuple(map(int, input().split()))

ans = 0
for bits in range(1 << n):
    cnt_on_sw = [0] * m
    # cnt_on_sw[lamp] : オンになっているスイッチ数
    for sw in range(n):
        if (bits >> sw) & 1:
            for lamp in e[sw]:
                cnt_on_sw[lamp] += 1
    cnt_on_sw = tuple(map(lambda x: x % 2, cnt_on_sw))
    if cnt_on_sw == p:
        ans += 1
print(ans)


Measured memory_bytes: 3064
for i in range(20):
    n=int(input())
    if n==0:break
    
    x=[]
    for j in range(n):
        a=int(input())
        x.append(a)
        
    for k in range(10):
        y=x.count(k)
        
        if y==0:
            print('-')
        else:
            print('*'*y)


Measured memory_bytes: 5700
import java.util.*

private fun readInts() = readLine()!!.split(" ").map { it.toInt() }
private fun readLongs() = readLine()!!.split(" ").map { it.toLong() }
private fun readDoubles() = readLine()!!.split(" ").map { it.toDouble() }
private fun <K, V> Map<out K, V>.toMutableMap(): MutableMap<K, V> = LinkedHashMap(this)
private fun <K, V> mutableMapOf(): MutableMap<K, V> = LinkedHashMap()
private fun <K, V> mutableMapOf(vararg pairs: Pair<K, V>) = pairs.toMap().toMutableMap()

fun main(args: Array<String>) {
    val N = readInts()[0]
    val xu = (0 until N)
        .map { readLine()!!.split(" ").let { it[0].toFloat() to it[1] } }
        .toList()

    var btc = 0.0
    var yen = 0.0

    xu.forEach {
        val (x, u) = it
        if (u == "BTC") {
            btc += x
        } else {
            yen += x
        }
    }

    println(yen + (btc * 380000.0))
}

Measured memory_bytes: 36084
#pragma GCC optimize (3)
#include<bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ff(v,a,b) for(int v=a;v<=b;v++)
#define fr(v,a,b) for(int v=a;v>=b;v--)
#define clr(a,v) memset(a,v,sizeof(a))
#define rep(v,a,b) for(int v=(a);(v)<(b);v++)
#define ll long long
using namespace std;
int n,a[200005],b[200005];
int main() {
	cin>>n;
	ff(i,1,n)cin>>a[i];
	for (int i=n; i>=1; --i) {
		if (i*2>n) b[i]=a[i];
		else {
			int sum=0;
			for (int j=i+i; j<=n; j+=i) sum=(sum+b[j])%2;
			b[i]=sum^a[i];
		}
	}
	int tot=0;
	ff(i,1,n) tot+=b[i];
	cout<<tot<<endl;
	ff(i,1,n) if (b[i]) cout<<i<<' ';
	return 0;
}

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(ll X, ll K, ll D)
{
    X = llabs(X);

    auto t = X / D;

    if (t >= K)
        return X - K*D;

    X -= t*D;
    K -= t;

    return K % 2 ? llabs(X - D) : X;
}

int main()
{
    ios::sync_with_stdio(false);

    ll X, K, D;
    cin >> X >> K >> D;

    auto ans = solve(X, K, D);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
  int m,a,b,data[1001];
  while(cin>>m){
    if(m==0) return 0;
    for(int i=0;i<=1000;i++) data[i] = 0;
    data[0] = 1;
    for(int i=0;i<m;i++){
      cin >> a >> b;
      for(int k=1000;k>=0;k--){
	if(data[k]!=0){
	  for(int i=1;i<=b;i++){
	    if(a*i+k<=1000) data[a*i+k] += data[k];
	  }
	}
      }
    }
    //for(int i=0;i<10;i++) cout << data[i] << endl;
    //cout << data[2] << endl;
    int n,ansn;
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> ansn;
      cout << data[ansn] << endl;
    }
  }
}

Measured memory_bytes: 1160
let () =
  let n = read_int () in
  let read_dice () = Scanf.sscanf (read_line ()) "%d %d %d %d %d %d" (fun a b c d e f -> [(a,f);(b,e);(c,d)]) in
  let rec loop dices result = function
      0 -> result
    | i -> let dice2 = read_dice () in
           let is_same_dice dice1 dice2 =
             let rec scan_through dice2 bop = function
                 0 -> false
               | i -> let scan' dice2 bop =
                        let r1,r2 = List.fold_left2 (
                                        fun (r1,r2) (a,b) (c,d) -> let b1,b2 = (a = c && b = d), (a = d && b = c) in
                                                                   if b1 && b2 then 1, true
                                                                   else if b1 then 1 * r1, r2
                                                                   else if b2 then -1 * r1, r2
                                                                   else 0, false
                                      ) (1,false) dice1 dice2
                        in
                        bop r1 0 || (r1 <> 0 && r2 )
                      in
                      scan' dice2 bop || ( i > 1 && let dice2' = (List.tl dice2) @ [(List.hd dice2)] in
                                                    scan_through dice2' bop (i-1)
                                         )
             in
             scan_through dice2 (>) 3 || scan_through (List.rev dice2) (<) 3
           in
           let result' = List.fold_left (fun acc dice -> acc || (is_same_dice dice dice2) ) false dices in
           result' || loop (dice2::dices) result' (i-1)
  in
  let dice1 = read_dice () in
  print_string @@ if loop [dice1] false (n-1) then "No\n"
                  else "Yes\n"


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

int N, S[200000];

bool Check(int k)
{
  for(int i = 0; i < k; i++) {
    for(int j = k + i; j < N; j += k) {
      if(S[j - k] != S[j]) return(false);
    }
  }
  return(true);
}

int main()
{
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> S[i];
  }
  for(int i = N; i >= 1; i--) {
    if(N % i == 0) {
      if(Check(N / i)) {
        cout << i << endl;
        exit(0);
      }
    }
  }
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
ll n,m,k,ans;
string s,t;
const ll powll = 1LL<<1;

int main(){
  /*
  int t; cin >> t;
  vector<string> ans = {};
  while(t--){
    
  }
  rep(i,ans.size()) cout << ans[i];
  */
  int h,n; cin >> h>> n;
  int a[n]; rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i,n) ans += a[i];
  if(h <= ans) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

ll n, h[100100], dp[100100];

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) cin >> h[i];
    for(int i = 0; i < 100100; i++) dp[i] = inf;

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

    cout << dp[n-1] << endl;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

int main(){
  int n; cin >> n;
  vector<int> l(n); rep(i,n) cin >> l[i];

  sort(all(l));
  l.push_back(inf);

  ll ans = 0;
  rep(i,n){
    repm(j,i+1,n){
      int high = l[i]+l[j];
      int low = max(l[i]-l[j],l[j]-l[i]);

      auto high_itr = lower_bound(all(l), high) - l.begin();
      auto low_itr = upper_bound(all(l), low) - l.begin();

      ans += high_itr - low_itr;

      if(low_itr <= i && i < high_itr) ans--;
      if(low_itr <= j && j < high_itr) ans--;
    }
  }

  ans = (ll)(ans/3);

  cout << ans << endl;
}


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

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

    cout << max(A * B, C * D) << endl;

    return 0;
}

Measured memory_bytes: 256