akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main()
{
  int N;
  int dx[] = {-1, 0, 1, 0};
  int dy[] = {0, 1, 0, -1};
  while(cin >> N, N){
    int x[200], y[200];
    int minX, minY, maxX, maxY;
    x[0] = 0, y[0] = 0;
    minX = minY = maxX = maxY = 0;
    for(int i = 1; i < N; i++){
      int n, d;
      cin >> n >> d;
      x[i] = x[n] + dx[d], y[i] = y[n] + dy[d];
      minX = min(minX, x[i]);
      minY = min(minY, y[i]);
      maxX = max(maxX, x[i]);
      maxY = max(maxY, y[i]);
    }
    cout << maxX - minX + 1 << " " << maxY - minY + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
m,d = map(int,input().split())
c= 0
l = []
for i in range(1,m+1):
    for j in range(1,d+1):
        if j%10 <2 or (j-j%10)//10 < 2:
            continue
        else:
            if (j%10)*((j-j%10)//10) == i:
                c = c+1
                l.append([i,j])
            else:
                continue
print(c)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
double n, a[1000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    double sum = 1;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum *= a[i];
    }
    double ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += sum / a[i];
    }
    cout << setprecision(10) << double(sum) / double(ans) << "\n";
}

Measured memory_bytes: 256
S=input()
P=2019

mod_table=[0]*P
mod_table[0]=1

modp=0
mod10=1
for i in reversed(range(len(S))):
  si=int(S[i])
  modp=(si*mod10+modp)%P
  mod_table[modp]+=1
  mod10=(mod10*10)%P
  
answer=0
for m in mod_table:
  answer+=m*(m-1)//2
  
print(answer)

Measured memory_bytes: 9236
#include<iostream>
using namespace std;
int main() {
    int arr[1000], num, i, j, k, v;
    cin>>num;
    for (i = 0; i < num; i++) {
        cin>>arr[i];
    }
    for (k = 0; k < num; k++) {
        cout<<arr[k];
        if (k != num - 1) {
            cout<<" ";
        }
    }
    cout<<endl;
    for (i = 1; i < num; i++) {
        v = arr[i];
        j = i - 1;
        while (j >= 0 && v < arr[j]) {
            arr[j+1] = arr[j];
            j--;
        }
        arr[j+1] = v;
        for (k = 0; k < num; k++) {
            cout<<arr[k];
            if (k != num - 1) {
                cout<<" ";
            }
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 3076
def aux(v)
  t = v / 9.8
  y = 4.9*t**2
  (1..1000).each {|n|
    if 5*n-5>=y
      return n
    end
  }
  1/0
end

def main
  fh=STDIN
  #fh=File.new("x.txt", "r")
  while fh.gets
    v = $_.chomp.to_f
    puts aux(v)
  end

end

if $0 == __FILE__ then
  main
end


Measured memory_bytes: 6876
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

void solve() {
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i <= n; i++) {
        for(ll j = i; j <= n; j += i) {
            ans += j;
        }
    }
    cout << ans;
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


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

int main(){
    double N, A, B, ans_d, ans_tmp, x;
    long long ans_l;

    std::cin >> A >> B >> N;
//    std::cout << A << B << N << "\n";
    ans_d = 0.0;
    //for(long long i = 1; i <= (long long)N; i++){
    if(N >= B){
        x = B - 1.0;
    }else{
        x = N;
    }
    ans_tmp = floor(A*round(x)/B);
    //std::cout << ans_tmp;
    ans_tmp = ans_tmp - A * floor(round(x)/B);

    if(ans_tmp > ans_d){
        ans_d = ans_tmp;
    }
    //}

    ans_l = (long long)round(ans_d);

    std::cout << ans_l;

}

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

signed main(){
  int N;
  cin >> N;
  unordered_map<string,int> keihinn;
  string S[200020];
  int ans = 0;
  rep(i,N){
    cin >> S[i];
    if(keihinn[S[i]] == 0){keihinn[S[i]] = 1;ans++;}
  }
  cout <<  ans;
}


Measured memory_bytes: 24040
#include<stdio.h>
#include<limits.h>

int main(){
  int n;
  int i;
  long max = LONG_MIN;
  long min = LONG_MAX;
  long sum = 0;
  int num;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &num);

    if(num < min){
      min = num;
    }

    if(num > max){
      max = num;
    }

    sum += num;
  }

  printf("%ld %ld %ld\n", min, max, sum);

  return 0;
}


Measured memory_bytes: 2084
# 解説放送

def solve():
    from itertools import islice, tee

    k, q = map(int, input().split())
    *d, = map(int, input().split())
    for g in tee(d, q):
        n, x, m = map(int, input().split())
        g = map(lambda x: x % m, g)
        g1, g2, g3 = tee(g, 3)
        rep, rest = divmod(n - 1, k)
        last = x + (sum(g1) * rep) + sum(islice(g2, 0, rest))
        eq = sum(rep + (1 if i < rest else 0) for i, gg in enumerate(g3) if gg == 0)
        ans = (n - 1) - eq - (last // m - x // m)
        yield ans


def main():
    print(*solve(), sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 114396
/*
* Author. Silviase(@silviasetitech)
* For AtCoder
*/

import java.util.*;
import java.lang.*;
import java.math.*;


public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        long k = sc.nextInt();
        long a = sc.nextInt();
        long b = sc.nextInt();
        if (a >= b - 2) {
            // just hit the pocket
            System.out.println(k+1);
        } else {
            // hit to a and always change(except last one)
            k -= a-1;
            // nokoru k times
            // k/2 times change and if odd +1
            if (k % 2 == 0) {
                System.out.println(a + (b-a)*(k/2));
            }else{
                System.out.println(a + (b-a)*(k/2)+1);
            }
        }


        sc.close();


    }
}

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


int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long test=1;
	
	while(test--)
	{
	    long long B,a,b,c=0,k,d=0,i,n,m,j,temp,ans;
	    string s;
	    cin>>s;
	    reverse(s.begin(),s.end());
	    while(s.length())
	    {
	        if(s.substr(0,7)=="remaerd")
	            s.erase(0,7);
	        else if(s.substr(0,6)=="resare")
	            s.erase(0,6);
	        else if(s.substr(0,5)=="esare")
	            s.erase(0,5);
	        else if(s.substr(0,5)=="maerd")
	            s.erase(0,5);
	        else
	            break;
	    }
	    if(s.length())cout<<"NO";
	    else cout<<"YES";
    }
}


Measured memory_bytes: 512
from collections import Counter
S = input()
N = len(S)

c = Counter(S)

def checkf(c1,c2,c3):
  return (c[c1] == c[c2] and c[c2] == c[c3]) or (c[c1] == c[c2] and c[c2] == c[c3]+1) or (c[c1] == c[c2]+1 and c[c2] == c[c3])

flg = checkf('a','b','c') or checkf('a','c','b') or checkf('b','a','c') or checkf('b','c','a') or checkf('c','a','b') or checkf('c','b','a')

print("YES" if flg else "NO")

Measured memory_bytes: 3444
//ツ環ョツ青ャ
#include<stdio.h>
int cup[4]={0};
int setN(char s){
	if(s=='A')return 0;
	else if(s=='B')return 1;
	else if(s=='C')return 2;
}
void change(char s,char t){
	int tmp;
	tmp=cup[s];
	cup[s]=cup[t];
	cup[t]=tmp;
}
int main(){
	int i,j,n,_s,_t;
	char s,t;
	cup[0]=1;
	for(;scanf("%c,%c\n",&s,&t)!=EOF;){
		_s=setN(s);
		_t=setN(t);
		change(_s,_t);
	}
	if(cup[0])printf("A\n");
	else if(cup[1])printf("B\n");
	else if(cup[2])printf("C\n");
	return 0;
}

Measured memory_bytes: 0
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N, M = map(int, readline().split())
    G = [[] for i in range(N)]
    for i in range(M):
        s, t = map(int, readline().split())
        G[s-1].append(t-1)

    used = [0]*N
    cnt = 0
    ans = 0
    for i in range(N):
        if used[i]:
            continue
        que = deque([i])
        used[i] = 1
        while que:
            v = que.popleft()
            ans += len(G[v])-1
            for w in G[v]:
                if used[w]:
                    continue
                used[w] = 1
                que.append(w)
        ans += 1
    write("%d\n" % ans)
solve()



Measured memory_bytes: 6092
#include <bits/stdc++.h>
#define int long long
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcount
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int n, w;
int wt[101], val[101];
int dp[101][100001];
signed main(){
    cin >> n >> w;
    for(int i=0; n>i; i++){
        cin >> wt[i] >> val[i];
    }
    for(int i=0; w>=i; i++){
        if(wt[0] <= i){
            dp[0][i] = val[0];
        }
    }
    for(int i=1; n>i; i++){
        for(int j=0; w>=j; j++){
            dp[i][j] = dp[i-1][j];
            if(j-wt[i] >= 0){
                dp[i][j] = max(dp[i][j], val[i] + dp[i-1][j-wt[i]]);
            }
        }
    }
    cout << dp[n-1][w];on;
}










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

//問題文より、入力される文字列の最大の長さ
#define MAXLENGTH 100

int main(void)
{
	char sentence[MAXLENGTH], phrase[MAXLENGTH];
	int sentence_length, phrase_length;
	int start_point, i, j;
	int flag;

	//それぞれ文字列sと文字列pを入力し、その長さを取得する
	scanf("%s", sentence);
	scanf("%s", phrase);
	sentence_length = strlen(sentence);
	phrase_length = strlen(phrase);

	//flagが1ならば文字列sから文字列pが作れる
	flag = 0;
	//文字列の開始位置が最後まで到達すると繰り返し終了
	for(start_point = 0; start_point < sentence_length; start_point++){
		i = start_point;
		j = 0;
		//文字が一致していれば次の文字と比較
		while(sentence[i] == phrase[j]){
			i++;
			//文字列はリング状となっているため最初の文字に戻る
			if(i >= sentence_length){
				i = 0;
			}
			j++;
		}
		//一致した文字数と文字列pの長さが等しければ "Yes" となる
		if(j >= phrase_length){
			flag = 1;
			break;
		}
	}

	//結果を出力
	if(flag){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
}


Measured memory_bytes: 2112
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    S = list(input())



    ans =0
    for k in range(N+1,0,-1):
        i=0
        count =0
        while i<N-k:
            if S[i]==S[i+k]:
                count+=1
                ans =max(ans,count)
            else:
                count=0
            if count==k:
                break

            i+=1

    print(ans)









if __name__ == "__main__":
    main()


Measured memory_bytes: 73520
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, M := sc.nextInt(), sc.nextInt()
	G := make([][]int, N)
	for i := 0; i < M; i++ {
		u, v := sc.nextInt()-1, sc.nextInt()-1
		G[u] = append(G[u], v)
	}
	S, T := sc.nextInt()-1, sc.nextInt()-1
	done := make([][3]int, N)
	for i := 0; i < N; i++ {
		for j := 0; j < 3; j++ {
			done[i][j] = -1
		}
	}
	queue := &Queue{}
	bfs := func(cur, cost int) {
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if done[next][cost%3] != -1 {
				continue
			}
			done[next][cost%3] = cost
			queue.push(Node{next, cost + 1})
		}
	}
	done[S][0] = 0
	queue.push(Node{S, 1})
	for !queue.isEmpty() {
		node := queue.pop()
		bfs(node.cur, node.cost)
	}
	if done[T][0] == -1 {
		fmt.Fprintln(wtr, -1)
	} else {
		fmt.Fprintln(wtr, done[T][0]/3)
	}
}

type Node struct {
	cur, cost int
}

type Queue struct {
	arr []Node
}

func (q *Queue) push(v Node) {
	q.arr = append(q.arr, v)
}

func (q *Queue) pop() Node {
	res := q.arr[0]
	q.arr = q.arr[1:]
	return res
}

func (q *Queue) isEmpty() bool {
	return len(q.arr) == 0
}


Measured memory_bytes: 14464
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	static FastReader input = new FastReader();
	static PrintWriter out = new PrintWriter(System.out);
	static String s, t;

	static int[][] memo;
	static boolean[][] visited;

	public static int lcs(int i, int j) {
		if (i >= s.length() || j >= t.length())
			return 0;

		if (visited[i][j])
			return memo[i][j];

		if (s.charAt(i) == t.charAt(j)) {
			visited[i][j] = true;
			return memo[i][j] = 1 + lcs(i + 1, j + 1);
		}

		visited[i][j] = true;
		int x = lcs(i + 1, j);
		int y = lcs(i, j + 1);
		int best = Math.max(x, y);
		return memo[i][j] = best;

	}

	public static int lcs1(int i, int j) {

		if (i >= s.length() || j >= t.length())
			return 0;

		if (s.charAt(i) == t.charAt(j)) {
			visited[i][j] = true;
			System.out.print(s.charAt(i));
			return 1 + lcs1(i + 1, j + 1);
		}

		visited[i][j] = true;

		int x = lcs(i + 1, j);
		int y = lcs(i, j + 1);

		int optimal = lcs(i, j);

		if (optimal == x) {

			return lcs1(i + 1, j);
		} else {
			return lcs1(i, j + 1);
		}

	}

	public static void main(String[] args) throws NumberFormatException, IOException {

		s = input.next();
		t = input.next();

		memo = new int[s.length()][t.length()];

		visited = new boolean[s.length()][t.length()];

		lcs(0, 0);
		lcs1(0, 0);
		out.flush();

	}
}

class FastReader {
	BufferedReader br;
	StringTokenizer st;

	public FastReader() {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	String next() throws IOException {
		while (st == null || !st.hasMoreElements()) {
			st = new StringTokenizer(br.readLine());
		}
		return st.nextToken();
	}

	int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(next());
	}

	String nextLine() throws IOException {
		String str = "";
		str = br.readLine();
		return str;
	}
}


Measured memory_bytes: 82288
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner stdin = new Scanner(System.in);
        
        int h;
        int w;
        
        while(true){
            h = stdin.nextInt();
            w = stdin.nextInt();
            if(h == 0 && w == 0)break;
            if(h <= 300 && w <= 300){
                for(int i = 0; i < h; i++){
                    for(int j = 0; j < w; j++){
                        System.out.print("#");
                    }
                    System.out.println();
                }
                System.out.println();
            }
        }
        
        stdin.close();
    }
}

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

int main() {
	static char s[16], t[16], u[16];
	int a, b;

	scanf("%s%s%d%d%s", s, t, &a, &b, u);
	if (strcmp(u, s) == 0)
		a--;
	else
		b--;
	printf("%d %d\n", a, b);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void){
	int A;
	int B;

	scanf("%d", &A);
	scanf("%d", &B);

	if (A % 3 == 0) printf("Possible");
	else if(B % 3 == 0) printf("Possible");
	else if ((A + B) % 3 == 0) printf("Possible");
	else printf("Impossible");

}

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

int main(){
  int k;
  cin >> k;
  int s=0;
  for(int a=1; a<=k; a++){
    for(int b=1; b<=k; b++){
      int x = __gcd(a,b);
      for(int c=1; c<=k; c++){
        s += __gcd(x,c);
      }
    }
  }
  cout << s;
}

Measured memory_bytes: 3640
n,d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
cn = 0
for i in range(n):
    for k in range(i+1,n):
        a = 0
        for j in range(d):
            a += (x[i][j] - x[k][j])**2
        b = a**0.5
        c = round(b)
        if -0.0001 < b-c < 0.0001:
            cn += 1
print(cn)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n], b[n];
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    
    int ans = 0;

    srep(i,1,30){
        int f[n], g[n];
        rep(j,n){
            f[j] = a[j] % (1<<i);
            g[j] = b[j] % (1<<i);
        }
        sort(g,g+n);
        ll cnt = 0;
        rep(j,n){
            cnt += g+n - lower_bound(g,g+n,3*(1<<(i-1))-f[j]);
            cnt += lower_bound(g,g+n,2*(1<<(i-1))-f[j]) - lower_bound(g,g+n,1*(1<<(i-1))-f[j]);
        }   
        if(cnt % 2 == 1){
            ans += (1<<(i-1));
        }
    }

    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3328
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container;

void main()
{
    auto nq = readln.split.to!(int[]);
    auto N = nq[0];
    auto Q = nq[1];
    auto AS = readln.split.to!(long[]);

    auto CS = new long[](N);
    auto DS = new long[](N);
    auto ES = new long[](N);
    foreach (i; 0..N) {
        if (i > 0) CS[i] += CS[i-1];
        CS[i] += AS[i];
        if (i-2 >= 0) DS[i] += DS[i-2];
        DS[i] += AS[i];
    }

    foreach (_; 0..Q) {
        auto X = readln.chomp.to!long;
        if (X <= AS[0]) {
            writeln(CS[N-1] - CS[N/2-1]);
            continue;
        } else if (X >= AS[N-1]) {
            writeln(DS[N-1]);
            continue;
        }
        int l, r = N-1;
        while (l+1 < r) {
            auto m = (l+r)/2;
            if (AS[m] - X <= 0) {
                l = m;
            } else {
                r = m;
            }
        }
        int i = abs(AS[l] - X) <= abs(AS[r] - X) ? l : r;
        if (i == N-1 || i == N-2) {
            writeln(DS[N-1]);
            continue;
        }

        l = i, r = N-2;
        while (l+1 < r) {
            auto m = (l+r)/2;
            auto t = N - m - 1;
            auto a = m - i + 1;
            auto d = abs(AS[m] - X);
            if (abs(AS[0] - X) <= d) {
                a = m + 1;
            } else {
                int ll, rr = i;
                while (ll+1 < rr) {
                    auto mm = (ll+rr)/2;
                    if (abs(AS[mm] - X) <= d) {
                        rr = mm;
                    } else {
                        ll = mm;
                    }
                }
                a += i - rr;
            }
            if (t >= a) {
                l = m;
            } else {
                r = m;
            }
        }
        auto res = CS[N-1] - CS[l];
        auto n = N - (N - r) * 2 - 1;
        if (n >= 0) res += DS[n];
        writeln(res);
    }
}

Measured memory_bytes: 9416
#include <stdio.h>
#include <algorithm>
using namespace std;

int N;
int A[100000];
int B[100000];
int C[100000];

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) scanf("%d", &A[i]);
    for (int i = 0; i < N; i++) scanf("%d", &B[i]);
    for (int i = 0; i < N; i++) scanf("%d", &C[i]);
    sort(A, A+N);
    sort(C, C+N);
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        int a = lower_bound(A, A+N, B[i]) - A;
        int c = (C+N) - upper_bound(C, C+N, B[i]);
        ans += 1LL * a * c;
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		if (n < 1000) {
			System.out.println("ABC");
		} else {
			System.out.println("ABD");
		}
		
		sc.close();
	}

}

Measured memory_bytes: 22996
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int e,ans;
	while(cin>>e,e){
		ans=e;
		int x;
		double d=sqrt(e)+1,g=pow(e,(double)1/3)+1;
		rep(y,d){
			rep(z,g){
				x=e-y*y-z*z*z;
				if(x<0)continue;
				ans=min(ans,x+y+z);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {
    int a;
    cin >> a;
    int ans = a + a * a + a * a * a;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,x;
	cin>>n>>x;
	long long a[n+1],b[n+1];
	a[0]=1,b[0]=1;
	//b:Total num of layers;a:patties
	for(int i=1;i<=n;i++)
	{
		a[i]=a[i-1]*2+1;
		b[i]=b[i-1]*2+3;
	}
	long long ans=0;
	while(x>0){
		if(x==b[n]){
			ans+=a[n];
			x-=b[n];
		}
		else if(x>=b[n]/2+1){
			ans+=a[n-1]+1;
			x-=b[n]/2+1;
		}
		else
		   x--;
		n--;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[m],sum=0;
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>n)
        cout<<-1<<endl;
    else
        cout<<n-sum<<endl;

}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n;cin>>n;
    if(n==0){
        cout<<0<<endl;
        return 0;
    }
    vin s(1000);
    ll fac=2;
    int i=0;
    while(n){
        if(n%fac)s[i]=1;
        else s[i]=0;
        if(n%fac){
            if(i%2)n+=pow(2,i);
            else n-=pow(2,i);
        }
        fac*=2;
        i++;
    }
    for(int j=i-1;j>=0;j--)cout<<s[j];
    cout<<endl;
}

Measured memory_bytes: 256
N = input()
for i in xrange(N):
    b, c = [0], [0]
    for j in map(int, raw_input().split()):
        if b[-1] < j: b.append(j)
        elif c[-1] < j: c.append(j)
        else: break
    else:
        print 'YES'
        continue
    print 'NO'

Measured memory_bytes: 6372
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)


N = ni()
A  = nl()

dict ={}

for a in A:
    if a in dict:
        x = dict[a]
        dict[a] = [ x[0]+1, -1,-1]        
    else:
        dict[a]=[1,-1,-1]

#print(dict)
sum=0
for a in A:
    x = dict[a]
    if x[1] == -1:
        n = x[0]
        dict[a]=[n,n*(n-1)//2,n-1]
        sum = sum + n*(n-1)//2

#print(dict)

#print(sum)
for a in A:
    print(sum-dict[a][2])



Measured memory_bytes: 31264
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B, K = map(int, readline().split())

    if K < A:
        print(A - K, B)
    elif K < A + B:
        print(0, A + B - K)
    else:
        print(0, 0)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int a,b,c,d,e,f; cin >> a >> b >> c >> d >> e >> f;
    int ans=0,anssugar=0;
    double nodo=0;
    for(int i = 0; i<=30; i++){
        for(int j = 0; j<=30; j++){
            if(i==0&&j==0) continue;
            if(100*i*a+100*j*b>f) break;
            double water = 100*i*a+100*j*b;
            int bestsugar = (i*a+j*b)*e;
            for(int k = 0; k<=3000; k++){
                for(int l = 0; l<=3000; l++){
                    double sugar = k*c+l*d;
                    if(sugar>bestsugar) break;
                    else if(water+sugar>f) break;
                    else{
                        if(nodo<(sugar/(sugar+water))){
                            nodo = (sugar/(sugar+water));
                            ans = sugar+water;
                            anssugar = sugar;
                        }
                    }
                }
            }
        }
    }
    if(ans==0&&anssugar==0){
        cout << min(a,b)*100 << " " << 0 << endl;
    }
    else{
        cout << ans << " " << anssugar << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int ans = 0;
	while(A >= B){
		B *= 2;
		ans++;
	}
	while(B >= C){
		C *= 2;
		ans++;
	}

	if (ans <= K){
		cout << "Yes" << "\n";
	} else {
		cout << "No" << "\n";
	}


	return 0;
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

vector<u32> min_p(1000006);

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

  vector<u32> a(n);
  rep(i, n) cin >> a[i];

  min_p[0] = 1;
  for (u32 i = 1; i < min_p.size(); i++) {
    min_p[i] = i;
    for (u32 j = 2; j * j < i; j++) {
      if (i % j == 0) {
        min_p[i] = j;
        break;
      }
    }
  }

  bool sc = true;
  u32 g = gcd(a[0], a[1]);
  for (u32 i = 2; i < n; i++) {
    g = gcd(g, a[i]);
  }
  if (g != 1)
    sc = false;

  unordered_map<u32, u64> m;
  unordered_set<u32> plist;

  rep(i, n) {
    plist.clear();
    while (1) {
      plist.insert(min_p[a[i]]);
      a[i] /= min_p[a[i]];
      if (min_p[a[i]] == a[i]) {
        plist.insert(a[i]);
        break;
      }
    };

    for (auto d : plist) {
      m[d]++;
    }
  }

  bool pc = true;

  for (auto p : m) {
    if (p.first != 1 && p.second > 1)
      pc = false;
  }

  if (pc)
    cout << "pairwise coprime";
  else if (sc)
    cout << "setwise coprime";
  else
    cout << "not coprime";

  return 0;
}


Measured memory_bytes: 14404
#include <iostream>
#include <string>
using namespace std;
int main(){ 
    string n;
    cin >> n;
    if (n[1]==n[2]) {
        if (n[0]==n[1]||n[2]==n[3]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static ArrayList<Integer> ps = new ArrayList<>();
	static final int M = 300001;
	static HashSet<Integer> ans;

	static void init() {
		ArrayList<Integer> list = new ArrayList<>();
		for (int i=6; i<=M; i++) {
			if (i%7 == 1 || i%7 == 6) list.add(i);
		}

		boolean[] f = new boolean[M+1];
		for (int i=0; i<list.size(); i++) {
			f[list.get(i)] = true;
		}

		for (int i=6; i<=M; i++) {
			if (!f[i]) continue;
			ps.add(i);
			for (int j=i+i; j<M; j+=i) {
				f[j] = false;
			}
		}

		// dump(ps);
	}

	static boolean rec(int n) {
		if (n == 1) return true;
		boolean f = false;
		for (int i=0; i<ps.size(); i++) {
			if (n%ps.get(i) == 0) {
				if (rec(n/ps.get(i))) {
					ans.add(ps.get(i));
					f = true;
				}
			}
		}
		return f;
	}

	static boolean solve() {
		int n = in.nextInt();
		if (n == 1) return false;

		// dump(ps);

		ans = new HashSet<Integer>();
		rec(n);
		ArrayList<Integer> list = new ArrayList<>(ans);
		Collections.sort(list);
		out.print(n+":");
		for (int i=0; i<list.size(); i++) {
			out.print(" "+list.get(i));
		}
		out.println();
		// dump(ans);

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		init();
		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 34924
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
#define ALL(x) (x).begin(),(x).end()

int main(){
	ll K;
	cin >> K;
	ll N = 50;
	vector<ll> A(N);
	// K/N周回す
	for(int i=0;i<N;i++) {
		A[i] = (N-1) + K/N;
	}
	// あまりの処理
	ll d = K % N;
	for(int i=0;i<d;i++) {
		A[i] += N;
		for(int j=0;j<N;j++) {
			if(i == j) continue;
			A[j]--;
		}
	}

	cout << N << endl;
	for(int i=0;i<N;i++) cout << A[i] << ((i == N-1) ? "\n" : " ");	
}

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

int levenshtein(const string &a, const string &b){
    int n = a.length();
    int m = b.length();
    vector<vector<int>> dp(n+1, vector<int>(m+1));
    for(int i=0; i<n+1; i++) dp[i][0] = i;
    for(int j=0; j<m+1; j++) dp[0][j] = j;
    for(int i=1; i<n+1; i++){
        for(int j=1; j<m+1; j++){
            int cost = (a[i-1]==b[j-1])? 0: 1;
            dp[i][j] = min({dp[i-1][j]+1, dp[i][j-1]+1, dp[i-1][j-1]+cost});
        }
    }
    return dp[n][m];
}

int swap_or_replace(string a, string b){
    int n = a.length();
    int m = b.length();
    if(n != m){
        return max(n, m); 
    }
    int res = 0;
    for(int i=0; i<n; i++){
        if(a[i] == b[i]) continue;
        res++;
        if(i<n-1 and a[i]==b[i+1] and a[i+1]==b[i]){
            b[i+1] = b[i];
        }
    }
    return res;
}

int dist(string a, string b){
    int res = levenshtein(a, b);
    if(a.length() > b.length()) swap(a, b);
    int n = a.length();
    int m = b.length();
    if(n+1 == m){
        for(int i=0; i<m; i++){
            string c = b.substr(0, i) +b.substr(i+1, m-i-1);
            res = min(res, swap_or_replace(a, c)+1);
        }
    }
    if(m == n){
        for(int d=0; d<2; d++){
            res = min(res, swap_or_replace(a, b));
            reverse(a.begin(), a.end());
            reverse(b.begin(), b.end());
        }
    }
    return res;
}

int main(){
    while(1){
        int n,d;
        cin >> n >> d;
        if(n == 0) break;

        vector<string> s(n);
        for(int i=0; i<n; i++){
            cin >> s[i];
        }
        sort(s.begin(), s.end());
        int num = 0;
        for(int i=0; i<n; i++){
            for(int j=i+1; j<n; j++){
                if(dist(s[i], s[j]) <= d){
                    num++;
                    cout << s[i] << "," << s[j] << endl;
                }
            }
        }
        cout << num << endl;
    }
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allg(v) v.begin(), v.end(), greater<int>()

long long powpow(long long m, long long n) {
  long long ret = 1;
  while(n > 0) {
    if(n & 1) ret = ret * m % 1000000007;
    m = m * m % 1000000007;
    n >>= 1;
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  long long m, n;
  cin >> m >> n;
  
  cout << powpow(m, n) << "\n";

}



Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
//UnionFind

const int maxn=10000;

int main(){
    
    vector<vector<int>> nd(maxn);
    bool used[maxn]={0};
    int n;
    int num[maxn];
    int cost[maxn];
    ll sum=0,ma=0;
    
    cin >>n;
    rep(i,n-1){
        int a,b;
        cin >> a>>b;
        a--;b--;
        nd[a].push_back(b);
        nd[b].push_back(a);
    }
    
    rep(i,n){
        cin >> cost[i];
        sum+=cost[i];
        ma=max(ma,(ll)cost[i]);
        cost[i]*=-1;
    }
    
    sort(cost,cost+n);
    
    queue<int> que;
    que.push(0);
    num[0]=-cost[0];
    //cout << num[0]<<endl;
    int ite=1;
    used[0]=true;
    
    while(!que.empty()){
        int arg=que.front();que.pop();
        rep(i,nd[arg].size()){
            if(!used[nd[arg][i]]){
                used[nd[arg][i]]=true;
                que.push(nd[arg][i]);
                num[nd[arg][i]]=-cost[ite++];
            }
        }
    }
    
    cout << sum-ma<<endl;
    rep(i,n){
        cout << num[i]<<' ';
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

// return primes between [2, sqrt(N)]
void SOE(ll N, vi & p) {
    int m = int(floor(sqrt(N))) + 1;
    int s[m];
    REP(i ,m) s[i] = i;

    FOR (i, 2, m) {
        if (s[i] != i) continue;

        p.pb(i);

        for (int j = i+i; j <= m; j += i) {
            s[j] = i;
        }
    }
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N;
    cin >> N;

    vi p;
    SOE(1e12, p);

    print(*lower_bound(ALL(p), N));

    
}


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

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

  int sum = 0;
  int longest = 0;
  for (int i = 0; i < N; ++i) {
    int tmp;
    cin >> tmp;
    sum += tmp;
    if (tmp > longest) longest = tmp;
  }

  sum -= longest;

  if(longest < sum) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 2e9;
const ll LINF = (1LL<<60);

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<P> ed;
  REP(i,n-1){
    int a,b; cin >> a >> b;
    a--, b--;
    ed.emplace_back(a,b);
  }
  vector<int> c(n);
  REP(i,n) cin >> c[i];
  sort(ALL(c));
  ll sum = 0;
  REP(i,n-1) sum += c[i];
  cout << sum << '\n';

  vector<int> num(n, -1);
  num[ed[0].first] = c.back();
  c.pop_back();
  num[ed[0].second] = c.back();
  c.pop_back();

  REP(k,n-2){
    FOR(i,1,n-1){
      auto [a,b] = ed[i];
      if(num[a]==-1 && num[b]==-1) continue;
      if(num[a]!=-1 && num[b]!=-1) continue;
      if(num[a]==-1) num[a] = c.back();
      else num[b] = c.back();
      c.pop_back();
      break;
    }
  }

  REP(i,n) cout << num[i] << ' ';
  cout << '\n';

  return 0;
}


Measured memory_bytes: 3792
N,M = map(int, input().split())
K = []
for i in range(N):
    K.append(list(map(int,input().split())))
    

A = [0 for _ in [0]*M]

for i in range(N):
    for j in range(K[i][0]):
        A[K[i][j+1]-1] += 1
        
print(A.count(N))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int K = in.nextInt();
            int[] x = new int[N];
            int[] y = new int[N];
            for (int i = 0; i < N; i++) {
                x[i] = in.nextInt();
                y[i] = in.nextInt();
                if (in.next().charAt(0) == 'B') {
                    y[i] += K;
                }
            }

            int K2 = 2 * K;

            int[][] w = new int[K2][K2];
            for (int i = 0; i < N; i++) {
                x[i] %= K2;
                y[i] %= K2;
                w[y[i]][x[i]]++;
            }

            TwoDimensionalCumulativeSum cumsum = new TwoDimensionalCumulativeSum(w);

            int max = 0;
            for (int r = 0; r < K2; r++) {
                for (int c = 0; c < K2; c++) {
                    int r0 = 0;
                    int r1 = Math.max(r - K, 0);
                    int r2 = r;
                    int r3 = Math.min(r + K, K2);
                    int r4 = K2;

                    int c0 = 0;
                    int c1 = Math.max(c - K, 0);
                    int c2 = c;
                    int c3 = Math.min(c + K, K2);
                    int c4 = K2;

                    int num = +cumsum.cumulativeSum(r0, c1, r1, c2) + cumsum.cumulativeSum(r0, c3, r1, c4) + cumsum.cumulativeSum(r1, c0, r2, c1) + cumsum.cumulativeSum(r1, c2, r2, c3) + cumsum.cumulativeSum(r2, c1, r3, c2) + cumsum.cumulativeSum(r2, c3, r3, c4) + cumsum.cumulativeSum(r3, c0, r4, c1) + cumsum.cumulativeSum(r3, c2, r4, c3);

                    max = Math.max(max, num);
                }
            }

            System.out.println(max);
        }
    }

}

class TwoDimensionalCumulativeSum {
    private int[][] sum;

    public TwoDimensionalCumulativeSum(int[][] values) {
        int R = values.length;
        int C = values[0].length;
        sum = new int[R + 1][C + 1];
        for (int r = 0; r < R; r++) {
            for (int c = 0; c < C; c++) {
                sum[r + 1][c + 1] = sum[r + 1][c] + sum[r][c + 1] - sum[r][c] + values[r][c];
            }
        }
    }

    public int cumulativeSum(int startRInclusive, int startCInclusive, int endRExclusive, int endCExclusive) {
        return sum[startRInclusive][startCInclusive] - sum[endRExclusive][startCInclusive] - sum[startRInclusive][endCExclusive] + sum[endRExclusive][endCExclusive];
    }
}


Measured memory_bytes: 103100
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;
    for(int i = 0;i < N-1;i++){
        if(S[i]!=S[i+1])ans ++;
        
    }

    cout << ans+1 << endl;
}



Measured memory_bytes: 512
n = int(input())
v = [list(map(int,input().split())) for _ in range(n-1)]
g = {}
for a,b,w in v:
    if a not in g:
        g[a] = []
    if b not in g:
        g[b] = []
    g[a].append([b,w])
    g[b].append([a,w])
from collections import deque
queue = deque([[1,0]])
b = [-1]*n
b[0] = 0
while queue:
    q,d = queue.popleft()
    if d%2==1:
        b[q-1] = 0
    else:
        b[q-1] = 1
    for new_q in g[q]:
        v_,d_ = new_q
        if b[v_-1]==-1:
            queue.appendleft([v_,d+d_])
for i in b:
    print(i)

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

class union_find {
public:
  vector<ll> data;

  union_find(){};
  union_find(ll size) { data.assign(size, -1); }

  bool unite(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return false;
    }
    if (data[x] > data[y]) {
      swap(x, y);
    }
    data[x] += data[y];
    data[y] = x;
    return true;
  }

  bool same(int x, int y) { return root(x) == root(y); }

  ll root(ll x) {
    if (data[x] < 0) {
      return x;
    } else {
      return data[x] = root(data[x]);
    }
  }

  ll size(ll x) { return (-data[root(x)]); }
};

ll N, M;
vector<ll> X, Y, Z;

void solve() {
  union_find uf = union_find(N);
  for (int i = 0; i < M; i++) {
    uf.unite(X[i], Y[i]);
  }
  vector<bool> used(N, false);
  ll res = 0;
  for (int i = 0; i < N; i++) {
    int i_root = uf.root(i);
    if (used[i_root] == false) {
      used[i_root] = true;
      res++;
    }
  }
  cout << res << "\n";
}

int main() {
  cin >> N >> M;
  X.resize(M);
  Y.resize(M);
  Z.resize(M);
  for (int i = 0; i < M; i++) {
    cin >> X[i] >> Y[i] >> Z[i];
    X[i]--;
    Y[i]--;
  }
  solve();
  return 0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}
/*

 */
int a, b;
int main()
{
  cin >> a>>b;
  int ans = 0;
  for (size_t i = 0; i < 2; i++)
  {
    if (a<b) {
      ans += b--;
    } else
    {
      ans += a--;
    }
  } 

  cout << ans << endl;
  return 0;
}


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

int main() {
  string S;
  cin >> S;
  int count = 0, answer =  0;
  bool ATGCcheck;
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) == 'A' || S.at(i) == 'T' || S.at(i) == 'G' || S.at(i) == 'C'){
      count++;
      answer = max(answer,count);
    }else{
      answer = max(answer,count);
      count = 0;
      //このままだとABCCCCとか最後AGCTの時加算されないので上のanswer追加
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
//#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


#define pb push_back 
#define f first
#define s second
#define min3(a, b, c) min(min(a, b), c)
#define max3(a, b, c) max(max(a, b), c)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

template <class T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = 1e9;
//const ll INF = 1e18;
const ll mod = 1000000007;
// const ll mod = 998244353;

void solve(int tc){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max(max(a*c, a*d), max(b*c, b*d));
}

int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    
    int tc = 1;
    //cin >> tc;
    for (int t = 0; t < tc; t++) solve(t);

    return 0;
}

Measured memory_bytes: 3664