akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

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

    vector<int> And,Or;

    map<int,int> mp;

    for(int i=0;i<N+M;i++){
        int p; cin >> p;
        mp[p]++;
    }

    for(auto p : mp){
        if(p.second > 1) And.emplace_back(p.first);
        Or.emplace_back(p.first);
    }

    cout << And.size() << " " << Or.size() << endl;
    for(size_t i=0;i<And.size();i++) cout << And[i] << endl;
    for(size_t i=0;i<Or.size();i++) cout << Or[i] << endl;
}




Measured memory_bytes: 14108
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int large=0;
        int sum=0;
        while(n-->0)
        {
            int a=sc.nextInt();
            sum+=a;
            if(a>large)
                large=a;
        }
        sum-=large;
        if(large<sum)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, a, b) for(int i=(a); i<(int)(b); i++)

typedef long long ll;

using namespace std;

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

int main(void){
	int n; cin >> n;
	vector<int> a(n+1), b(n);
	rep(i, n+1) cin >> a[i];
	rep(i, n) cin >> b[i];
	ll ans = 0;
	rep(i, n){
		if(a[i] < b[i]){
			ans += a[i];
			b[i] -= a[i];
			if(a[i+1] < b[i]){
				ans += a[i+1];
				a[i+1] = 0;
			} else{
				ans += b[i];
				a[i+1] -= b[i];
			}
		} else{
			ans += b[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import deque
n = int(input())
a = [int(x) for x in input().split()]
d = deque()
is_rev = False
for i in a:
    if is_rev:
        d.appendleft(i)
    else:
        d.append(i)
    is_rev = not is_rev
if is_rev:
    d = list(d)[::-1]
print(*d)


Measured memory_bytes: 25412
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

const int MAX = 300;

int main(){
  int S, D, M;
  while(cin >> S >> D >> M){
    int dp[100][MAX + 1] = {};
    REP(i, S){
      int K;
      cin >> K;
      while(K--){
        int w, p;
        cin >> w >> p;
        for(int y = M; y >= 0; y--){
          if(y - p >= 0) dp[i][y] = max(dp[i][y], dp[i][y - p] + w);
        }
      }
    }
    int ans[MAX + 1] = {};
    REP(i, D){
      int f; cin >> f;
      for(int j = M; j >= 0; j--){
        for(int k = 0; j - k >= 0; k++){
          ans[j] = max(ans[j], ans[j - k] + dp[f][k]);
        }
      }
    }
    while(M > 0 && ans[M] == ans[M - 1]) M--;
    printf("%d %d\n", ans[M], M);
  }
  return 0;
}

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

using ll = long long;
using Pi = pair < int , int >;

int main()
{
    int N, M;
    string S;
    vector < int > output;
    int back[100006];

    cin >> N >> M >> S;

    reverse(begin(S), end(S));
    
    int cur = 0;
    for ( int i = 0; i < N + 1; i++ ) {
        if ( S[i] == '0' ) cur = i;
        back[i] = cur;
    }

    int x = 0;
    while ( x < N ) {
        if ( x + M >= N ) {
            output.push_back(N - x);
            x = N;
        } else if ( back[x + M] == x ) {
            cout << -1 << endl;
            return ( 0 );
        } else {
            output.push_back(back[x + M] - x);
            x = back[x + M];
        }
    }
    
    reverse(begin(output), end(output));

    cout << output[0];
    for ( int i = 1; i < output.size(); i++ ) {
        cout << " " << output[i];
    }
    cout << endl;

    return ( 0 );
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

int n,loc;

int main()
{
	n=ty(),loc=ty();
	if(n==1){puts("Yes\n1");return 0;}
	if(loc==1 || loc==n+n-1){puts("No");return 0;}
	puts("Yes");
	for(int i=n-(loc>n);i>=1;i--)if(i!=loc)printf("%d\n",i);
	printf("%d\n",loc);
	for(int i=n+n-1;i>=n+(loc<=n);i--)if(i!=loc)printf("%d\n",i);
	
	return 0;
}


Measured memory_bytes: 1536
#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...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(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;


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

    string S;
    cin >> S;

    bool f = true;

    if (S[0] != 'A') {
        f = false;
    }

    int cnt = 0;
    FOR(i, 2, S.size() - 1) {
        if (S[i] == 'C') cnt++;
    }

    if (cnt != 1) f = false;

    cnt = 0;
    REP(i, S.size()) {
        debug(S[i], S[i] - 'a')
        if (S[i] - 'a' < 0) cnt++;
    }

    if (cnt > 2) f = false;

    if (f) cout << "AC" << endl;
    else cout << "WA" << endl;

}


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

using namespace std;

int enda(vector<int> &s, int counter) {
    if (s[0] == s[1] && s[1] == s[2]) {
        cout << counter << endl;
        return 0;
    }
}

int main() {
    vector<int> s(3);
    int A, B, C;
    cin >> A >> B >> C;
    s[0] = A;
    s[1] = B;
    s[2] = C;
    sort(s.begin(), s.end());
    int counter = 0;
    enda(s, counter);
    for (int i = 0; s[1] < s[2]; i++) {
        counter++;
        s[0]++;
        s[1]++;
        enda(s, counter);
    }
    for (int i = 0; s[0] < s[1]; i++) {
        counter++;
        s[0] += 2;
        enda(s, counter);
    }
    for (int i = 0; s[1] < s[0]; i++) {
        counter++;
        s[1]++;
        s[2]++;
        enda(s, counter);
    }
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N,M=map(int,input().split())
l=[[-1]*2 for i in range(N)]

for i in range(N):
    a,b=map(int,input().split())
    l[i]=[a,b]

l.sort()
sum=0
i=0
while M>0:
    num=min(M,l[i][1])
    sum+=num*l[i][0]
    M-=num
    i+=1
print(sum)



Measured memory_bytes: 20012
/*
    頭
 */

#include <cstdio>
#include <cstring>
#include <set>
using namespace std;

typedef pair<int, int> Data;
typedef pair<Data, int> Pair;
Pair queue[10000];
int base;
int head;

unsigned int start;
short hascounted[16777215];
int di[][3] = {{1, 4, -1}, {-1, 1, 4}, {-1, 1, 4}, {-1, 4, 100}, {1, -4, -100}, {-1, 1, -4}, {-1, 1, -4}, {-1, -4, 1}};

inline void push(Pair p) {
    queue[head] = p;
    head = (head+1) % 10000;
}

inline Pair front() {
    return queue[base];
}

inline void pop() {
    base = (base+1) % 10000;
}

inline bool empty() {
    return head == base;
}
int main() {
    push(Pair(Data(001234567, 0), 0));

    while (1) {
        start = 0;
        for (int i=0; i<2; i++) {
            for (int j=0; j<4; j++) {
                int digit;

                if (scanf("%d", &digit) == EOF) return 0;
                start = start * 8 + digit;
            }
        }

        if (start == 001234567) {
            printf("0\n");
            continue;
        }

        while (!empty() && !hascounted[start]) {
            Pair p = front(); pop();
            int state = p.first.first;
            int time = p.first.second;
            int pos  = p.second;

            for (int k=0; k<3; k++) {
                int newpos = pos + di[pos][k];
                int mask;
                unsigned int newstate;
                int a;
                int b;

                if (newpos < 0 || 8 <= newpos) break;

                a = 21L-pos*3;
                b = 21L-newpos*3;

                mask = (7 << a) | (7 << b);
                newstate = (state & ~mask);
                newstate |= ((state >> a) & 0x7) << b;
                newstate |= ((state >> b) & 0x7) << a;
                if (!hascounted[newstate]) {
                    push(Pair(Data(newstate, time+1), newpos));
                    hascounted[newstate] = time+1;
                }
            }
        }

        printf("%d\n", hascounted[start]);
    }
}

Measured memory_bytes: 32604
#include "bits/stdc++.h"
using namespace std;

const int N=1e5+20;

int n,m,a[N],u,v,ans;
vector <int> adj[N];

bool ok(int node)
{
	for(auto child:adj[node])
		if(a[node]<=a[child])
			return false;
	return true;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	while(m--)
	{
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	for(int i=1;i<=n;i++)
		if(ok(i)) ans++;
	cout<<ans;
}

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
int compare(pair<int,int> &p1,pair<int,int> &p2)
{
	if(p1.first<p2.first)
	return 1;
	if(p1.first==p2.first)
	{
		if(p1.second<p2.second)
		return 1;
	}
	return 0;
}
int hands(vector<pair<int,int>> &v)
{
	stack<pair<int,int>> s;
	for(auto itr : v)
	{
	   int fir=itr.first,scnd=itr.second;
	   if(s.empty()==1)
	   s.push({fir,scnd});
	   else 
	   {
	       if(fir<=s.top().second && scnd <= s.top().second)
	       {
	       	  s.pop();
	       	  s.push({fir,scnd});
	       }
	       else if(fir>=s.top().second)
	       s.push({fir,scnd});
	   }
	}
	return s.size();
}
int main()
{
	int n,point,range;
	cin>>n;
	vector<pair<int,int>> v;
	for(int i=0;i<n;++i)
	{
		cin>>point>>range;
		v.push_back({point-range,point+range});
	}
	sort(v.begin(),v.end(),compare);
	int count=hands(v);
	cout<<count;
	return 0;
}

Measured memory_bytes: 1908
#include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
     
    const int maxn = 100009;
    LL l[maxn], c[maxn];
    int n, m, s, t; LL ans = 1e15;
     
    inline int read(){
    	char ch = getchar(); int x = 0;
    	while (ch < '0' || '9' < ch) ch = getchar();
    	while ('0' <= ch && ch <= '9') { x = x*10+ch-'0'; ch = getchar(); }
    	return x;
    }
     
    int main(){
    	n = read(); m = read(); s = read();
    	while (--n){
    		t = read();
    		if (s < t){
    			c[1] += t-s; c[s+1] -= t-s;
    			c[s+1] += t+1; c[t+1] -= t+1;
    			l[s+1] += -1; l[t+1] -= -1;
    			c[t+1] += t-s;
    		}
    		else{
    			c[1] += t+1; c[t+1] -= t+1;
    			l[1] += -1; l[t+1] -= -1;
    			c[t+1] += m-s+t; c[s+1] -= m-s+t;
    			c[s+1] += m+t+1;
    			l[s+1] += -1;
    		}
    		s = t;
    	}
    	for (int i=1; i<=m; i++){
    		c[i] += c[i-1];
    		l[i] += l[i-1];
    		ans = min(ans, c[i]+l[i]*i);
    	}
    	printf("%lld\n", ans);
    	return 0;
    }

Measured memory_bytes: 1664
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, a, N) for(int i = a; i < N; i++)

char board[100][100];
int h, w;

bool check(int x, int y) {
    rep(d, -1, 2) {
        if (d == 0) continue;
        int nx = x + d;
        int ny = y + d;
        if (0 <= nx && nx < h)
            if (board[nx][y] == '#') return true;
        if (0 <= ny && ny < w)
            if (board[x][ny] == '#') return true;
    }
    return false;
}

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

    int cnt = 0;
    rep(i, 0, h)
        rep(j, 0, w)
            cin >> board[i][j];

    rep(x, 0, h) {
        rep(y, 0, w) {
            if (board[x][y] == '#') {
                if (check(x, y)) continue;
                else {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ((int)(x).size())

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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  REP(i, K) {
    if (B >= C) {
      C *= 2;
    } else if (A >= B) {
      B *= 2;
    } else {
      break;
    }
  }
  if (A < B && B < C) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3592
l,r=map(int,input().split())
if r>l+4040:
    r=l+4040
dif=r-l
minimum=1000000000
for i in range(l%2019,l%2019 + dif+1):
    for j in range(i+1,l%2019 +dif +1):
        minimum=min(minimum,((i*j)%2019))
print(minimum)

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

typedef long long  ll;
	

int main()
{
  ll n,m;
  cin>>n>>m;
  ll a[n],x,y;
  for(ll i=0;i<n;i++)
  	cin>>a[i];
  vector<ll>adj[n+1];
  for(ll i=0;i<m;i++)
  {
  	cin>>x>>y;
  	adj[x].push_back(y);
  	adj[y].push_back(x);
  }
  ll c=0;
  for(ll i=1;i<=n;i++)
  {
  	if(adj[i].size()==0)
  	c++;
  	else
  	{
  		ll f=0;
  		for(auto j:adj[i])
  		{
  			if(a[j-1]>=a[i-1])
  			{
  				f=1;
  				break;
  			}
  		}
  		if(f==0)
  		c++;
  	}
  }
  cout<<c;
}

Measured memory_bytes: 10264
use std::io::{self, BufReader, Read};
use std::str::FromStr;
use std::string::String;

fn main() {
	let mut sc = ::Scanner::new(io::stdin());
	let r: i32 = sc.next_as().unwrap();
	let ans = match r {
		0...1199 => "ABC",
		1200...2799 => "ARC",
		_ => "AGC"
	};
	println!("{}", ans);
}

#[derive(Debug)]
pub struct Scanner<R> {
	reader: BufReader<R>
}

impl<R: io::Read> Scanner<R> {
	
	pub fn new(read: R) -> Scanner<R> {
		Scanner { reader: BufReader::new(read) }
	}

	pub fn next_str(&mut self) -> Option<String> {
		let mut buf = [0; 1];
		let size = self.reader.read(&mut buf).unwrap();
		if size == 0 {
			None{}
		} else {
			let first = self.skip_whitespace(&mut buf);
			if first.is_none() {
				return None{}
			}
			let mut v = vec![buf[0]];
			loop {
				let size = self.reader.read(&mut buf).unwrap();
				if size == 0 || char::from(buf[0]).is_whitespace() {
					break;
				}
				v.push(buf[0]);
			}
			Some(String::from_utf8(v).unwrap())
		}
	}

	pub fn next_line(&mut self) -> Option<String> {
		let mut buf = [0; 1];
		let mut v :Vec<u8> = vec![];
		let mut size = self.reader.read(&mut buf).unwrap();
		if size == 0 {
			return None{}
		}
		loop {
			if size == 0 || char::from(buf[0]) == '\n' {
				return Some(String::from_utf8(v).unwrap())
			}
			v.push(buf[0]);
			size = self.reader.read(&mut buf).unwrap();
		}
	}

	pub fn next_vec<S: FromStr>(&mut self, size: u32) -> Vec<S> {
		let mut v: Vec<S> = vec![];
		for _ in 0..size {
			let token = self.next_str().unwrap();
			v.push(S::from_str(&token).ok().unwrap());
		}
		v
	}

	pub fn next_as<S: FromStr>(&mut self) -> Option<S> {
		if let Some(s) = self.next_str() {
			if let Ok(v) = S::from_str(&s) {
				return Some(v)
			}
		}
		None{}
	}

	pub fn next_i32(&mut self) -> Option<i32> {
		self.next_as::<i32>()
	}

	pub fn next_i64(&mut self) -> Option<i64> {
		self.next_as::<i64>()
	}

	pub fn next_f32(&mut self) -> Option<f32> {
		self.next_as::<f32>()
	}

	pub fn next_f64(&mut self) -> Option<f64> {
		self.next_as::<f64>()
	}

	fn skip_whitespace(&mut self, mut buf: &mut [u8]) -> Option<u8> {
		loop {
			if !char::from(buf[0]).is_whitespace() {
				return Some(buf[0])
			}
			let size = self.reader.read(&mut buf).unwrap();
			if size == 0 {
				return None{}
			}
		}
	}
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<atcoder/all>

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;
using namespace atcoder;

/////////////////////////////////////////////////////


ll N, Q;

ll i, j, k;
int main(){
    scanf("%lld%lld",&N, &Q);

    fenwick_tree<ll> A(N+3);
    rep(i,0,N){
        ll a;
        scanf("%lld", &a);
        A.add(i, a);
    }
    while(Q--){
        ll t, a, b;
        scanf("%lld%lld%lld", &t, &a, &b);
        if(t==0){
            A.add(a, b);
        }else{
            printf("%lld\n", A.sum(a, b));
        }
    }

    return 0;
}

Measured memory_bytes: 8220
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto abc = sort(readln.chomp.split.map!(to!int).array);
  if (abc[0] == 5 && abc[1] == 5 && abc[2] == 7) writeln("YES");
  else writeln("NO");
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#define INF 1<<27
using namespace std;
int V,E;
int cost[301][301];
bool used[301];
int d[301];

void init(){
  fill(d,d + 101,INF);
  fill(used,used + 101,false);
}

void dijkstra(int s){
  init(); 
  d[s] = 0;
  while(1){
    int v = -1;
    for(int i = 1 ; i < V ; i++ ){
      if(!used[i] && (v == -1 || d[v] > d[i]))v = i;
    }
    if(v == -1)break;
    used[v] = true;

    for(int i = 1 ; i < V ; i++ ){
      d[i] = min(d[i],d[v] + cost[v][i]);
    }
  }
}

int main(){
  cin >> V >> E;
  V++;
  fill(cost[0],cost[101],INF);
  for(int i = 0 ; i < E ; i++ ){
    int a,b,c,d;
    char ch;
    cin >> a >>ch>> b >>ch>> c >>ch>> d;
	cost[a][b] = c;
	cost[b][a] = d;
  }
 
  int s,g,c1,c2;
  char ch;
  cin >> s >>ch>> g >>ch>> c1 >>ch>> c2;

  dijkstra(s);
  int st = d[g];


  dijkstra(g);
  int go = d[s];
  cout << c1-(st + go + c2) << endl; 
}

Measured memory_bytes: 1288
from collections import deque
n = int(input())
trees = [[] for _ in range(n)]

for i in range(n-1):
    a, b, w = map(int, input().split())
    trees[a-1].append([b-1, w])
    trees[b-1].append([a-1, w])

color = [0 for _ in range(n)]
visited = set()

next = deque()
next.append(0)
visited.add(0)
color[0] = 1

while len(next):
    i = next.popleft()
    for j, d in trees[i]:
        if j in visited:
           continue
        if d % 2 == 0:
            color[j] = color[i]
        else:
            color[j] = color[i] * -1
        next.append(j)
        visited.add(j)

for i in color:
    if i == -1:
        print(0)
    else:
        print(i)

Measured memory_bytes: 118024
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;

vector<int> ds(vector<int>dis,vector<vector<pair<int,int>>> g,int start,int goal){
    int n=dis.size();
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> Q;
    dis[start]=0;
    Q.push(make_pair(0,start));

    while(!Q.empty()){
        int pos=Q.top().second;Q.pop();
        for(int i=0;i<g.at(pos).size();i++){
            int to=g.at(pos).at(i).first;
            int cost=g.at(pos).at(i).second;
            if(dis[to]>dis[pos]+cost){
                dis[to]=dis[pos]+cost;
                Q.push(make_pair(dis[to],to));
            }
        }
    }
    return dis;
}
int big=10000007;
ll mod=1000000007;

int main(){
    int n,x,y; cin>>n>>x>>y;
    vector<vector<P>> graph(n);

    for(int i=0;i<n-1;i++){
        graph[i].push_back(make_pair(i+1,1));
        graph[i+1].push_back(make_pair(i,1));
    }
    graph[x-1].push_back(make_pair(y-1,1));
    graph[y-1].push_back(make_pair(x-1,1));

    vector<int> dis(n,big);
    //dis=ds(dis,graph,0,1);//0から各頂点への距離

    map<int,int> distance;
    for(int i=0;i<n;i++){
        vector<int> disi=ds(dis,graph,i,1);
        for(int j=i+1;j<n;j++){
            distance[disi[j]]++;
        }
    }

    for(int k=1;k<n;k++){
        cout<<distance[k]<<endl;
    }

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // cnt leading zeroes
#define ctz(a) __builtin_ctz(a) // cnt trailing zeroes
#define popc(a) __builtin_popcnt(a) // cnt set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 1e9+7;
ll t,n,m,k,x,y;

//string dp[55];

ll len[50];
ll cnt[50];

ll solve(int n,ll x)
{
	if(n==0 && x==1)
		return 1;
	if(x==0)
		return 0;
	else
	{
		ll half=len[n-1];
		//ll ret=0;
		if(x<= half+1)
		{
			return solve(n-1,x-1);
		}
		else if(x== half+2 )
			return cnt[n-1]+1;
		else if(x <= 2*half + 2)
		{
			return cnt[n-1]+1+solve(n-1,x-half-2);
		}
		else
			return cnt[n];
	}
}

int main()
{
	IOS;
	cin>>n>>x;
	len[0]=1;
	for(int i=1;i<=n;i++)
	{
		len[i]=2*len[i-1]+3;
	}
	cnt[0]=1;
	for(int i=1;i<=n;i++)
		cnt[i]=2*cnt[i-1] + 1;
	//ll ans=0;
	//ans=solve(n,x);
/*	dp[0]="P";
	for(int i=1;i<=n;i++)
	{
		dp[i]="B"+dp[i-1]+"P"+dp[i-1]+"B";
	}
	reverse(dp[n].begin(),dp[n].end());
	ll ans=0;
	forn(i,x){
		ans+=(dp[n][i]=='P');
	}
	cout<<ans;*/
	//cout<<len[n];
	cout<<solve(n,x);
}

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

using namespace std;
int main(void) {
    int n;
    cin >> n;

    vector<int> a(n);
    vector<int> r(n);

    for(int i=0; i<n; i++)
        cin >> a[i];

    for(int i=n; i>=1; i--) {
        int t = a[i-1];
        for(int j=1; i*j<=n; j++) {
            if(r[i*j-1]) t = 1-t;
        }
        r[i-1] = t;
    }

    int m=0;
    for(int i=0; i<n; i++) {
        if(r[i])
            m++;
    }
    cout << m << endl;

    for(int i=0; i<n; i++) {
        if(r[i])
            cout << i+1 << endl;
    }
}




Measured memory_bytes: 2432
n, k = map(int, input().split())

mod = 10 ** 9 + 7
num = n * (n + 1) // 2 + 2
ans = 0
for i in range(k, n + 2):
    left = (0 + (i - 1)) * i // 2
    right = ((n - (i - 1)) + n) * i // 2
    ans += (right - left) + 1
    ans %= mod

print(ans)


Measured memory_bytes: 9188
N=input()
K=int(input())

l=len(N)

dp=[[[0]*(K+2) for _ in range(2)] for _ in range(l+1)]

dp[0][1][0]=1

for i,c in enumerate(N):
    x=int(c)

    for j in range(2):
        for d in range(x+1 if j==1 else 10):
            for k in range(K+1):
                dp[i+1][x==d if j==1 else 0][k+1 if 0<d else k]+=dp[i][j][k]   

print(dp[l][0][K]+dp[l][1][K])

Measured memory_bytes: 40816
#include <stdio.h>
#include <algorithm>

using namespace std;

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

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    long long sum = 0;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        scanf("%d", &B[i]);
        C[i] = A[i] - B[i];
        if (C[i] < 0) {
            sum += C[i];
            ans++;
        }
    }
    sort(C, C + N);
    for (int i = N - 1; i >= 0 && sum < 0; i--) {
        sum += C[i];
        ans++;
    }
    if (sum < 0) ans = -1;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1280
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#define ATCODER
#ifdef ATCODER
#include<atcoder/all>
using namespace atcoder;
#endif

#include <algorithm>
#include <utility>
#include <vector>

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64

#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#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 FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1]
template <typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353;
constexpr int MAX = 4400000;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e17 + 1;
constexpr int INF = 1e9 + 1;

void solve() {
	string S = "ACL";
	int K; cin >> K;
	REP(i, K)cout << S;
	cout << endl;
}



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;
	//cin >> q;
	//while (q--)
	solve();

}


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

using namespace std;

int main(){
    int a,b,w;
    cin>>w>>a>>b;
    int ans=max(a-b-w,b-a-w);
    
    cout<<max(ans,0)<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	int N; cin >> N;

	int minus = 0;
	int idx = 0;
	int absMin = INF;
	vector<long> A(N,0);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] < 0) {
			minus++;	
		}
		if (absMin > abs(A[i])) {
			absMin = abs(A[i]);	
			idx = i;
		}
	}

	if (minus % 2 == 0) {
		for (int i = 0; i < N-1; i++) {
			if (A[i] < 0) {
				A[i] *= -1;	
				A[i+1] *= -1;	
			}
		}
	}else { //abs min search
		for (int i = 0; i < N-1; i++) {
			if (idx == i) {
				if (A[i] > 0) {
					A[i] *= -1;
					A[i+1] *= -1;
				}
			}else if (A[i] < 0) {
				A[i] *= -1;	
				A[i+1] *= -1;	
			}
		}
	}


	long sum = 0;
	for (int i = 0; i < N; i++) {
		sum += A[i];
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 4036
r,g,b,n=io.read("*n","*n","*n","*n")

counter=0
for i=0,n do
    for j=0,n do
        rg=r*i+g*j
        if n>=rg and (n-rg)%b==0 then
            counter=counter+1
        end
    end
end
print(counter)

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
B_A = 0
start_B = 0
end_A = 0
ans = 0
for _ in range(N):
    s = input()
    ans += s.count('AB')
    if s[0]=='B' and s[-1]=='A':
        B_A += 1
    elif s[0]=='B':
        start_B += 1
    elif s[-1]=='A':
        end_A += 1

if B_A>=1:
    ans += B_A - 1
    B_A = 1
ans += min(B_A, start_B) + min(B_A, end_A) + max(min(start_B - B_A, end_A - B_A), 0)
print(ans)

Measured memory_bytes: 68468
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)a;i<=(sign)b;++i)
#define Fordown(i,a,b) for(register sign i=(sign)a;i>=(sign)b;--i)
const int N=100+5;
bool cmax(sign &a,sign b){return (a<b)?a=b,1:0;}
bool cmin(sign &a,sign b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
void file()
{
	#ifndef ONLINE_JUDGE
		freopen("test.in","r",stdin);
		freopen("test.out","w",stdout);
	#endif
}
void work()
{
	int n=read<int>();
	For(i,1,n)if(i*(i+1)/2>=n){printf("%d\n",i);break;}
}
int main()
{
	
	work();
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int m = sc.nextInt(), f = sc.nextInt(), r = sc.nextInt();
            if(m==-1 && f==-1 && r==-1) break;
            else if((m==-1 || f==-1) || m+f<30) System.out.println('F');
            else if(m+f >= 80) System.out.println('A');
            else if(m+f >= 65) System.out.println('B');
            else if(m+f>=50 || (m+f>=30 && r>=50)) System.out.println('C');
            else System.out.println('D');
        }
    }
}



Measured memory_bytes: 25984
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll N=1e6+5,inf=1e18,mod=1e9+7;
#define test ll testcases;cin>>testcases; while(testcases--)
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define sz(x) ((ll)((x).size()))
const ld pi=3.141592653589793238;

bool check_prime(ll n)
{
	ll flag=0,i;
	for(i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			flag=1;
			break;
		}
	}
	if(n==1)
	{
		return false;
	}
	else if(flag==0 || n==2 || n==3)
	{
		return true;
	}
	else
	{
		return false;
	}
}

ll fastexpo(ll a,ll b,ll MOD) 
{
	ll result=1;
	while(b>0)
	{
		if(b%2==1)
		{
			result=(result*a)%MOD;
		}
		a=(a*a)%MOD;
		b=b/2;
	}
	return result;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,j,k,f;
    cin>>n;
    string s1,s2;
    cin>>s1>>s2;
    i=0;
    j=0;
    f=0;
    for(f=0;f<2*n;f++)
    {
    	if(f%2==0)
    	{
    		cout<<s1[i];
    		i++;
    	}
    	else
    	{
    		cout<<s2[j];
    		j++;
    	}
    }
    cout<<"\n";
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,b;cin>>n>>a>>b;
  ll mi = a*(n-1)+b,ma = a+(n-1)*b;
  cout<<max(0LL,ma-mi+1)<<endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
while True:
  flag=0
  a=n
  while a!=0:
    now=a%10
    if flag==0:
      pre=now
      flag=1
    if now!=pre:
      flag=2
      break
    pre=now
    a=a//10
  if flag==1:
    print(n)
    break
  n+=1


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

int c=0, N;
map<int, vector<int>> m;

void osp(int a, int t, set<int> s) {
  for(int x : m.at(a)) {
    int z=t+1;
    set<int> y;
    for(auto n : s)
      y.insert(n);
    if(!y.count(x)) {
      y.insert(x);
      if(z==N)
        c++;
      else
        osp(x, z, y);
    }
  }
}

int main() {
  int M,i,a,b;
  cin >> N >> M;
  
  for(i=0; i<M; i++) {
    cin >> a >> b;
    if(!m.count(a))
      m[a].push_back(b);
    else
      m.at(a).push_back(b);
    if(!m.count(b))
      m[b].push_back(a);
    else
      m.at(b).push_back(a);
  }

  set<int> seen;
  seen.insert(1);
  osp(1,1,seen);

  cout << c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
double x,y,xx,yy,xxx,yyy,xxxx,yyyy;
int q;
int main(){
	cin>>q;
	while(q--){
		cin>>x>>y>>xx>>yy>>xxx>>yyy>>xxxx>>yyyy;
		int pd1=0,pd2=0,pd3=0,pd4=0,pd5=0;
		xx-=x,yy-=y,xxx-=x,yyy-=y,xxxx-=x,yyyy-=y;
		if((xx*yyy-xxx*yy)*(xx*yyyy-xxxx*yy)<=0) pd1=1;
		xx+=x,yy+=y,xxx+=x,yyy+=y,xxxx+=x,yyyy+=y;
		
		x-=xx,y-=yy,xxx-=xx,yyy-=yy,xxxx-=xx,yyyy-=yy;
		if((x*yyy-xxx*y)*(x*yyyy-xxxx*y)<=0) pd2=1;
		x+=xx,y+=yy,xxx+=xx,yyy+=yy,xxxx+=xx,yyyy+=yy;
		
		x-=xxx,y-=yyy,xx-=xxx,yy-=yyy,xxxx-=xxx,yyyy-=yyy;
		if((xxxx*y-x*yyyy)*(xxxx*yy-xx*yyyy)<=0) pd3=1;
		x+=xxx,y+=yyy,xx+=xxx,yy+=yyy,xxxx+=xxx,yyyy+=yyy;
		
		x-=xxxx,y-=yyyy,xx-=xxxx,yy-=yyyy,xxx-=xxxx,yyy-=yyyy;
		if((xxx*y-x*yyy)*(xxx*yy-xx*yyy)<=0) pd4=1;
		x+=xxxx,y+=yyyy,xx+=xxxx,yy+=yyyy,xxx+=xxxx,yyy+=yyyy;
		
		if(max(x,xx)>=min(xxx,xxxx)
		&& max(xxx,xxxx)>=min(x,xx)
		&& max(y,yy)>=min(yyy,yyyy)
		&& max(yyy,yyyy)>=min(y,yy)){
			pd5=1;
		}
		double ANS=100000000;
		if(pd1==1 && pd2==1 && pd3==1 && pd4==1 && pd5==1){
			ANS=0;
		}
		double ans,ansx,ansy;
		
		ANS=min(ANS,sqrt((xxx-x)*(xxx-x)+(yyy-y)*(yyy-y)));
		ANS=min(ANS,sqrt((xxxx-x)*(xxxx-x)+(yyyy-y)*(yyyy-y)));
		ANS=min(ANS,sqrt((xxx-xx)*(xxx-xx)+(yyy-yy)*(yyy-yy)));
		ANS=min(ANS,sqrt((xxxx-xx)*(xxxx-xx)+(yyyy-yy)*(yyyy-yy)));
		
		xx-=x,yy-=y,xxx-=x,yyy-=y,xxxx-=x,yyyy-=y;
		ans=xx*xxx+yy*yyy;
		ans/=(xx*xx+yy*yy);
		ansx=ans*xx,ansy=ans*yy;
		if((ansx>=0 && ansx<=xx || ansx<=0 && ansx>=xx) && (ansy>=0 && ansy<=yy || ansy<=0 && ansy>=yy)){
			ANS=min(ANS,sqrt((xxx-ansx)*(xxx-ansx)+(yyy-ansy)*(yyy-ansy)));
		}
//		printf("%.10lf\n",ANS);
		ans=xx*xxxx+yy*yyyy;
		ans/=(xx*xx+yy*yy);
		ansx=ans*xx,ansy=ans*yy;
		if((ansx>=0 && ansx<=xx || ansx<=0 && ansx>=xx) && (ansy>=0 && ansy<=yy || ansy<=0 && ansy>=yy)){
			ANS=min(ANS,sqrt((xxxx-ansx)*(xxxx-ansx)+(yyyy-ansy)*(yyyy-ansy)));
		}
//		printf("%.10lf\n",ANS);
		xx+=x,yy+=y,xxx+=x,yyy+=y,xxxx+=x,yyyy+=y;
		
		x-=xxx,y-=yyy,xx-=xxx,yy-=yyy,xxxx-=xxx,yyyy-=yyy;
		ans=xxxx*x+yyyy*y;
		ans/=(xxxx*xxxx+yyyy*yyyy);
		ansx=ans*xxxx,ansy=ans*yyyy;
		if((ansx>=0 && ansx<=xxxx || ansx<=0 && ansx>=xxxx) && (ansy>=0 && ansy<=yyyy || ansy<=0 && ansy>=yyyy)){
//			cout<<"1 "<<xxxx<<" "<<ansx<<endl;
			ANS=min(ANS,sqrt((x-ansx)*(x-ansx)+(y-ansy)*(y-ansy)));
		}
//		printf("%.10lf\n",ANS);
		ans=xxxx*xx+yyyy*yy;
		ans/=(xxxx*xxxx+yyyy*yyyy);
		ansx=ans*xxxx,ansy=ans*yyyy;
		if((ansx>=0 && ansx<=xxxx || ansx<=0 && ansx>=xxxx) && (ansy>=0 && ansy<=yyyy || ansy<=0 && ansy>=yyyy)){
//			cout<<"2 "<<xxxx<<" "<<ansx<<endl;
			ANS=min(ANS,sqrt((xx-ansx)*(xx-ansx)+(yy-ansy)*(yy-ansy)));
		}
		printf("%.10lf\n",ANS);
	}
	return 0;
}


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

inline int readInt(){
  int ret = 0;
  char c;
  while((c=getchar()) && isdigit(c)){
    ret = ret * 10 + (c-'0');
  }
  return ret;
}

void outint(int a){
  if (a == 0)return;
  outint(a/10);
  putchar('0' + a%10);
}

main(){
  int n,s;
  while(true){
    n = readInt();
    if (n==0)break;
    s = readInt();
    int r[101]={0};
    for(int i=0;i<n;i++){
      int tmp;tmp=readInt();r[tmp]++;
    }
    int ans = 0;
    for(int i=1;i != 101;i++){
      if (r[i] && i+i > s)ans += r[i]*(r[i]-1)/2;
      for(int j=i+1;j<101;j++){
	if (i+j>s)ans += r[i]*r[j];
      }
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

// 15
class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for(int i = 0; i < N; i++)
            a[i] = sc.nextInt();

        Arrays.sort(a);
        int ans = a[N / 2] - a[N / 2 - 1];

        System.out.println(ans);
    }

}


Measured memory_bytes: 59740
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main()
{
    while(true){
        int n,q; cin >> n >> q;
        if(n == 0 && q == 0) break;
        int date[110];
        for(int i = 0; i<110; i++){
            date[i] = 0;
        }
        for(int i = 0; i < n; i++){
            int m; cin >> m;
            for(int j = 0; j < m; j++){
                int tmp; cin >> tmp;
                date[tmp]++;
            }
        }
        int ans = 0;
        int num = 0;
        for(int i = 0; i < 105; i++){
            if(date[i] >= q){
                if(num < date[i]){
                    ans = i;
                    num = date[i];
                }
            }
        }
        cout << ans << endl;
    }
}


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

int main(){
  int	a,b;	cin >> a >> b;
  vector<int>	x(3);
  rep(i,3)	x[i]=i+1;
  
  x[a-1]=0;
  x[b-1]=0;
  for(int i:x)	if(i>0)	cout <<i;
}

Measured memory_bytes: 3564
from collections import deque

N, M = map(int, input().split())

edge = [[] for i in range(N)]
for i in range(M):
    x, y, _ = map(int, input().split())
    edge[x-1].append(y-1)
    edge[y-1].append(x-1)

visited = [False] * N

ans = 0
for i in range(N):
    if visited[i]:
        continue
    else:
        ans += 1

    q = deque([i])
    while q:
        cur = q.popleft()
        visited[cur] = True

        for next in edge[cur]:
            if visited[next]:
                continue
            visited[next] = True
            q.append(next)

print(ans)

Measured memory_bytes: 27980
n = int(input())
s = input()
t = input()

s = list(s)
t = list(t)

s.reverse()

a1 = []
a2 = []

c1 = ""
c2 = ""

for i in range(n):
    c1 += s[i]
    c2 += t[i]
    temp = c1
    a1.append(temp[::-1])
    a2.append(c2)

max = 0
for i in range(n):
    if a1[i] == a2[i]:
        max = i+1
#
# print(a1)
# print(a2)

print(2*n-max)





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


int main(){
    double P1[2],P2[2];
    double distance;

    scanf("%lf%lf%lf%lf",&P1[0],&P1[1],&P2[0],&P2[1]);
    distance = sqrt(pow((P1[0]-P2[0]),2) + pow((P1[1]-P2[1]),2));
    //printf(" %lf %lf %lf %lf\n",P1[0],P1[1],P2[0],P2[1]);
    printf("%lf\n",distance);

    
    


    return 0;
}



Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    int N;
    string s;
    cin >> N;   cin >> s;
    int res = 0;
    for(int i = 0; i < N-2; i++){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
            res++;
        }
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    for(int i=0;i<n;i++) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  long long int size(int x) {
    return sizes[find(x)];
  }
};

int main(){

  long long int n,m;
  cin >> n >> m;

  long long int a[m],b[m];
  for(int i=0;i<m;i++)cin >> a[i] >> b[i];


  long long int s[m+1]={};
  UnionFind tree(n);

  for(int i=m-1;i>=0;i--){
    if(tree.same(a[i]-1,b[i]-1))s[i]=s[i+1];
    else s[i]=s[i+1]+tree.size(a[i]-1)*tree.size(b[i]-1);
    tree.unite(a[i]-1,b[i]-1);
  }


  for(int i=1;i<m+1;i++)cout << n*(n-1)/2-s[i] << endl; 

}

Measured memory_bytes: 4480
// 0bd35dc5e428754fa574049b6be8efe0

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = (int) 1e5;

int n;

vector<int> adj[MAXN + 5];

inline void input()
{
	n = read<int>();
	for(int i = 2; i <= n; ++i)
	{
		int fa = read<int>();
		adj[fa].push_back(i);
	}
}

int f[MAXN + 5];

inline void dfs(int u)
{
	for(auto v : adj[u]) dfs(v);

	sort(ALL(adj[u]), [&](int p, int q) { return f[p] > f[q]; });
	f[u] = 0;
	for(int i = 0; i < SZ(adj[u]); ++i) chkmax(f[u], f[adj[u][i]] + i + 1);
}

inline void solve()
{
	dfs(1);
	printf("%d\n", f[1]);
}

int main()
{
#ifndef ONLINE_JUDGE
//	freopen("B.in", "r", stdin);
//	freopen("B.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 10240
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B; cin >> A >> B;
  int kaibun = 0;
  for (int i = A; i <= B; i++) {
  	int man = i / 10000;
    int sen = i % 10000 / 1000;
    int ju = i % 100 / 10;
    int ichi = i % 10;
    if (man == ichi && sen == ju) {
      kaibun++;
    }
  }
  cout << kaibun << endl;
}

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

using namespace std;

int main()
{
    long long n; cin >> n;
    int a = 0, b = 0;

    for (int i = sqrt(n); i >= 1; i--) {
        a = i;
        if (n % a == 0) {
            b = n / a;
            break;
        }
    }

    int ret = max(int(log10(a)) + 1, int(log10(b)) + 1);

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string S;
	cin >> S;
	string m = "0123456789";


	if (S[5] == m[1]) {
		cout << "TBD";
	}
	else if (S[6] == m[4] || S[6] == m[3] || S[6] == m[2] || S[6] == m[1]) {
		cout << "Heisei";
	}
	else {
		cout << "TBD";
	}

}

Measured memory_bytes: 256
while (True):
    n,m=map(int,input().split())
    if n==m==0:
        exit()
    lst_a=[int(input()) for _ in range(n)]
    lst_b=[int(input()) for _ in range(m)]
    a_sum=sum(lst_a)
    b_sum=sum(lst_b)
    min_lst=[]
    
    for a in lst_a:
        keisan_a=a_sum
        keisan_b=b_sum
        for b in lst_b:
            if keisan_a -a+b == keisan_b +a-b:
                min_lst.append((a+b,a,b))
    
    
    if min_lst:
        ans=sorted(min_lst)    
        print(ans[0][1],ans[0][2])
                
    else:print(-1)



Measured memory_bytes: 6244
n = int(input())
a = list(map(int, input().split()))
c = [0]*(n+1)
for i in a:
  c[i] += 1
ans = 1
for i in range(n+1):
    if c[-1] == 0:
        c.pop()
    else:
        break

mod = 998244353
for i in range(len(c)-1):
    ans *= pow(c[i], c[i+1], mod)
    ans %= mod

if a[0] != 0:
    ans *= 0
if c[0] != 1:
    ans *= 0
print(ans)


Measured memory_bytes: 14396
# pythonでスタック、キューを実現するためにdequeをimport
from collections import deque

N, M = map(int, input().split())

# 辺集合EとグラフGの構築
G = [[] for _ in range(N)]
E = []
for _ in range(M):
    a, b = map(int, input().split())
    # 入力は1-indexedだがこれを扱いやすいように0-indexedに変更
    a -= 1
    b -= 1
    E.append((a, b))
    G[a].append(b)
    G[b].append(a)
# print(G)

# 橋を数えるための変数cntを用意
cnt = 0
for edge_to_remove in E:
    # 橋であるか判定したい辺を取り除いてみる
    i, j = edge_to_remove
    G[i].remove(j)
    G[j].remove(i)

    # 深さ優先探索
    seen = [False] * N
    todo = deque()
    # 適当な頂点から深さ優先探索をスタート（ここでは頂点0をスタートに選んだ）
    todo.append(0)
    seen[0] = True
    seen_nodes_num = 0
    while todo:
        here = todo.pop()
        seen_nodes_num += 1
        for neighbor in G[here]:
            if seen[neighbor] == False:
                seen[neighbor] = True
                todo.append(neighbor)
    # print(seen)
    # もし訪問できていない頂点があれば連結でないというなので今着目している辺は橋であった！
    if seen_nodes_num != N:
        cnt += 1

    # 次の辺について調べるために今取り除いた辺を再びGに戻しておく
    G[i].append(j)
    G[j].append(i)
print(cnt)


Measured memory_bytes: 39664
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()

    print('ABC' + str(n))

if __name__ == '__main__':
    main()


Measured memory_bytes: 77080