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

int N, M;

vector<int> G[8];
int used[8];

int dfs(int s) {
	used[s] = 1;
	int res = 0;
	for (int v : G[s]) {
		if (!used[v]) {
			res += dfs(v);
		}
	}
	if (res == 0) {
		bool f = true;
		for (int i = 0; i < N; i++) {
			if (!used[i]) {
				f = false;
				break;
			}
		}
		if (f) {
			res = 1;
		}
	}
	used[s] = 0;
	return res;
}

int main()
{
	cin >> N >> M;
	for (int i = 0, a, b; i < M; i++) {
		cin >> a >> b;
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
	}
	cout << dfs(0) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <queue>
#include <vector>

#define testin freopen("1.txt","r",stdin);
#define testout freopen("out.txt","w",stdout);
#define ll long long

using namespace std;

const int maxn=(int)1e5+10;

struct job{
    int reward;
    int days;
    void getdata(){
        cin>>days>>reward;
    }
}s[maxn];

struct cmp_queue{
    bool operator()(int &a,int &b){
        return a>b;
    }
};

int cmp(struct job a,struct job b){
    return a.days>b.days;
}

priority_queue<int,vector<int>,cmp_queue> q;

int main(){
    int n,m;
    ll ans=0;
    int cnt=0;
    cin>>n>>m;
    for(int i=0;i<n;i++) s[i].getdata();
    sort(s,s+n,cmp);
    int i=0;
    while(s[i].days>m) i++;
    for(;i<n;i++){
        if(m-s[i].days+1>cnt){
            cnt++;
            q.push(s[i].reward);
            ans+=s[i].reward;
        }else{
            if(s[i].reward>q.top()){
                int temp=q.top();
                q.pop();
                q.push(s[i].reward);
                ans+=s[i].reward-temp;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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






int X;
//-----------------------------------------------------------------------------------
int main() {
	cin >> X;

	int ans = 0, x = 0;
	while (x < X) {
		ans++;
		x += ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();
    sc.close();

    if ((X + Y) % 3 != 0) {
      System.out.println(0);
      return;
    }

    int x = (2 * X - Y) / 3;
    int y = (2 * Y - X) / 3;
    if (x < 0 || y < 0) {
      System.out.println(0);
      return;
    }
    
    int mod = 1000000000 + 7;
    long[] cmb = modCmb(x + y, y, mod);
    long ans = 0;
    for (int i = 0; i < cmb.length; i++) ans = (ans + cmb[i]) % mod;
    System.out.println(ans);
  }

  private static long[] modCmb(int n, int k, long mod) {
    long[] cmb = new long[n - k + 1];
    cmb[0] = 1;
    for (int i = 1; i <= n - k; i++)
      cmb[i] = modDiv(cmb[i - 1] * (k + i - 1), i, mod);
    return cmb;
  }

  private static long modDiv(long a, long b, long mod) {
    return (a % mod) * modInv(b, mod) % mod;
  }

  private static long modInv(long x, long mod) {
    return modPow(x, mod - 2, mod);
  }

  private static long modPow(long b, long e, long mod) {
    long ans = 1;
    long x = b % mod;
    for (long y = e; y != 0; y >>= 1) {
      if ((y & 1) == 1) ans = (ans * x) % mod;
      x = (x * x) % mod;
    }
    return ans;
  }
}

Measured memory_bytes: 24020
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

struct Node {
    parent: u64,
    size: u64,
}

fn findParent(n: u64, nodes: &mut Vec<Node>) -> u64 {
    let p = nodes[n as usize].parent;
    if p == 0 {
        n
    } else {
        let tmp = findParent(p, nodes);
        nodes[n as usize].parent = tmp;
        tmp
    }
}

fn union(a: u64, b: u64, nodes: &mut Vec<Node>) -> u64 {
    let pa = findParent(a, nodes);
    let pb = findParent(b, nodes);
    if pa == pb {
        0
    } else {
        let sa = nodes[pa as usize].size;
        let sb = nodes[pb as usize].size;
        if sa > sb {
            nodes[pb as usize].parent = pa;
            nodes[pa as usize].size = sa + sb;
        } else {
            nodes[pa as usize].parent = pb;
            nodes[pb as usize].size = sa + sb;
        }
        sa * sb
    }
}

fn main() {
    let v: Vec<u32> = read::<String>()
        .split('/')
        .map(|e| e.parse().ok().unwrap())
        .collect();

    if v[1] <= 4 {
        println!("Heisei");
    } else {
        println!("TBD");
    }
}


Measured memory_bytes: 4352
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const ll inv2 = (mod+1)/2;
int n, q, a[3011];
int dp[3011][3011];
void upd(int &x, int v) {x=x+v>=mod?x+v-mod:x+v;}
void SWAP(int x, int y)
{
	int tmp = (dp[x][y]+dp[y][x])%mod*inv2%mod;
	dp[x][y] = dp[y][x] = tmp;
	for (int i=1; i<=n; i++)
	{
		if (i==x||i==y) continue;
		int tmp;
		tmp = (dp[x][i]+dp[y][i])%mod*inv2%mod;
		dp[x][i] = dp[y][i] = tmp;
		tmp = (dp[i][x]+dp[i][y])%mod*inv2%mod;
		dp[i][x] = dp[i][y] = tmp;
	}
}
int main()
{
	getii(n, q);
	for (int i=1; i<=n; i++) geti(a[i]);
	for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) dp[i][j] = a[i]>a[j];
	for (int i=1; i<=q; i++)
	{
		int x, y;
		getii(x, y);
		SWAP(x, y);
	}
	int ans = 0;
	for (int i=1; i<=n; i++) for (int j=i+1; j<=n; j++) upd(ans, dp[i][j]);
	cout<<ans*qpow(2,q)%mod<<endl;
	return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    vector<string> ans; //答えになりうる文字列の配列
    int l = s.size() - t.size() + 1;

    for (int i = 0; i < max(0, l); i++) { //文字列の比較位置
        string tmp = s;
        for (int j = 0; j < t.length(); j++) { //部分文字列の比較位置
            if (i + j > s.size() - 1) break; //そもそも部分文字列の方が長かったらunrestorable
            if (tmp[i + j] == '?' || tmp[i + j] == t[j]) //文字列のi+j番目が?もしくは、tのj番目と同じだったら
                tmp[i + j] = t[j]; //文字列のi+j番目をtのj番目にする
            else
                break;
            if (j == t.length() - 1) { //?が埋まらなかった場合の処理
                for (int k = 0; k < tmp.length(); k++) {
                    if (tmp[k] == '?') tmp[k] = 'a'; //辞書順なので?だったらaを入れる
                }
                ans.push_back(tmp); //配列に追加
            }
        }
    }

    // 選べる区間は |𝑆| − |𝑇| + 1 個あるので, それらの区間すべてに対して 「選んだ区間が決定している 状態での辞書順最小」 を求め, その中での辞書順最小なものが, 全部の中の辞書順最小となります。
    sort(ans.begin(), ans.end()); //辞書順で一番小さな答えになりえる文字列をans[0]にする
    cout << (ans.size() > 0 ? ans[0] : "UNRESTORABLE") << endl;
    return 0;
}

Measured memory_bytes: 3656
using System;
using System.Linq;

class C
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int n = h[0], k = h[1], s = h[2], M = 1000000000;

		var a = Enumerable.Repeat(s, k).Concat(Enumerable.Repeat(s == M ? 1 : M, n - k));
		Console.WriteLine(string.Join(" ", a));
	}
}


Measured memory_bytes: 24796
module S = Set.Make(struct
  type t = int * int
  let compare (p, b) (q, d) = q - p
end)

let parse s =
  let arr = Array.init (String.length s) (fun i -> s.[i]) in
  Array.fold_left (fun (p, b) c ->
    if c = '(' then (p+1, b) else (p-1, min b (p-1))) (0, 0) arr

let solve () =
  Scanf.scanf "%d" @@ fun n ->
  let s = List.init n (fun _ -> Scanf.scanf " %s" parse) in

  let ls = s |> List.filter (fun (p, b) -> p >= 0) |> Array.of_list in
  let rs = s |> List.filter (fun (p, b) -> p < 0) |> Array.of_list in

  Array.sort (fun (p, b) (q, c) -> if b <> c then c-b else q-b) ls;
  Array.sort (fun (p, b) (q, c) -> if b-p <> c-q then (c-q) - (b-p) else q-p) rs;

  let pl, bl =
    Array.fold_left (fun (pl, bl) (p, b) -> (pl + p, min bl (pl + b))) (0, 0) ls in

  let pr, br =
    Array.fold_left (fun (pr, br) (p, b) -> (pr - p, min br (pr + (b-p)))) (0, 0) rs in

  if min bl br = 0 && pl = pr then "Yes" else "No"

let () = solve () |> print_endline


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

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a, b;
    cin >> a >> b;
    ll gc = __gcd(a, b);
    vector<ll> fac;
    int ans = 0;
    for (ll i = 2; i * i <= gc; i++) {
        if (gc % i == 0) ans++;
        while (gc % i == 0) {
            gc /= i;
        }
    }
    ans++;
    if (gc != 1) ans++;
    cout << ans << '\n';
    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, T; cin >> N >> T;
  LL prv = 0;
  LL ans = 0;
  REP(i,N){
	LL crt; cin >> crt;
	if(crt - prv < T)
	  ans += crt - prv;
	else
	  ans += T;
	prv = crt;
  }
  cout << ans+T << endl;

  return 0;
}


Measured memory_bytes: 256
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

void solve() {
	int k;
	cin >> k;
	for (int i = 0; i < k; i++)
		cout << "ACL";
}

int32_t main() {
	int t = 1;
//	cin >> t;
	while (t--) {
		solve();
	}
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
 
const int N = 1e5 + 7;
 
int a[N];
 
int32_t main() {
		
		    	
		
 
    	ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
    	int n, m; cin >> n >> m;
    	for(int i = 1; i <= n; i++) cin >> a[i], a[i] /= 2;
    	int lcm = 1;
    	for(int i = 1; i <= n; i++) {
    		lcm = (lcm * a[i]) / __gcd(a[i], lcm);
    		if(lcm > m) {
    			cout << 0 << endl;
    			return 0;
    		}
    	}

    	for(int i = 1; i <= n; i++) if((lcm / a[i]) % 2 == 0) {
    		cout << 0 << endl;
    		return 0;
    	}
    	cout << m / lcm - (m / (lcm * 2)) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  vector<int> A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  int ans = A[K - 1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
S = list(input())
size = len(S)
K = int(input())
for i in range(size):
    if S[i] == "1" and K == 1 :
        print("1")
        exit()
    else :
        if S[i] == "1":
            K -= 1
        else : 
            print(S[i])
            exit()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a,b,c,d,i;
  cin >> n;
string str[n];
a=0;
  b=0;
  c=0;
  d=0;
  for(i=0;i<n;++i)
  {
  cin >> str[i];
  if(str[i]=="AC") a++;
   if(str[i]=="WA") b++; 
   if(str[i]=="TLE") c++;
    if(str[i]=="RE") d++;
  }
  
  cout << "AC x "<< a << endl;

  cout << "WA x "<< b << endl;
  cout << "TLE x "<< c << endl;
  cout << "RE x "<< d << endl;
return 0;
}

Measured memory_bytes: 6724
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }





int main() {
	vci p, s;
	
	int p_, s_; char c;
	int sum = 0, avg = 0, n = 0;
	while (cin >> p_ >> c >> s_) {
		sum += p_*s_; avg += s_; n++;
	}
	
	cout << sum << endl;
	cout << (int)((double)avg/(double)n + 0.5) << endl;
	
	return 0;
}

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

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final int[] scores = new int[N];
		for(int i=0; i<N; i++){
			scores[i] = sc.nextInt();
		}
		sc.close();
		
		Arrays.sort(scores);
		int ans = 0;
		for(int s: scores){
			ans += s;
		}
		for(int i=0; i<N; i++){
			if(ans%10!=0){
				break;
			}
			if(scores[i]%10!=0){
				ans = ans-scores[i];
			}
		}
		ans = ans % 10 == 0 ? 0 : ans;
		System.out.println(ans);

	}

}

Measured memory_bytes: 22608
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var a = Math.min(one[0], one[1]);
  var b = Math.max(one[0], one[1]);
  var output = "";
  for(var i = 0; i < b; i++){
    output += a.toString();
  }
  myout(output);
}


Measured memory_bytes: 29976
#include <stdio.h>
int main(void)
{
    int i, a, p = 0;
    scanf("%d", &a);
    for (i = 0; i < 3; i++)
    {
        if (a % 2 == 1)
        {
            p++;
        }
        a = a / 10;
    }
    printf("%d\n", p);
    return 0;
}

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

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

typedef long long ll;
const int maxn = 17, mod = 1e9 + 7;

int n, m;
int f[1 << maxn], g[1 << maxn], e[1 << maxn], pow2[maxn * maxn];

int main()
{
	n = gi(); m = gi();
	for (int i = 0; i < m; ++i) ++e[(1 << (gi() - 1)) | (1 << (gi() - 1))];
	
	for (int i = 0; i < n; ++i)
		for (int s = 0; s < (1 << n); ++s)
			if ((s >> i) & 1) e[s] += e[s ^ (1 << i)];

	pow2[0] = 1;
	for (int i = 1; i <= m; ++i) pow2[i] = pow2[i - 1] * 2 % mod;
	
	for (int s = 1; s < (1 << n); ++s) {
		if (~s & 1) continue;
		for (int t = (s - 1) & s; t; t = (t - 1) & s)
			f[s] = (f[s] + (ll)f[t] * pow2[e[s ^ t]]) % mod;
		f[s] = (pow2[e[s]] + mod - f[s]) % mod;
	}
		
	for (int s = 1; s < (1 << n); ++s) {
		if ((s & 2) == 0) continue;
		for (int t = (s - 1) & s; t; t = (t - 1) & s)
			g[s] = (g[s] + (ll)g[t] * pow2[e[s ^ t]]) % mod;
		g[s] = (pow2[e[s]] + mod - g[s]) % mod;
	}

	int ans = 0;
	for (int s = 0; s < (1 << n); ++s)
		for (int s2 = s; s2; s2 = (s2 - 1) & s) {
			if ((s2 & 2) == 0) continue;
			int s1 = ((1 << n) - 1) ^ s;
			if ((s1 & 1) == 0) continue;
			if (e[s1 | s2] == e[s1] + e[s2])
				ans = (ans + (ll)pow2[e[((1 << n) - 1) ^ s1 ^ s2]] * f[s1] % mod * g[s2]) % mod;
		}

	ans = (pow2[m] + mod - ans) % mod;
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

vector<int> factorization[10000];
int reslcm[1000000];
vector<int> primes;

bool prime_factors(int n)  
{  
    // Print the number of 2s that divide n
  if (n == 2)
    return true;
  
  while (n % 2 == 0)  
  {
    return false;
    n = n/2; 
  }

  // n must be odd at this point. So we can skip  
  // one element (Note i = i +2)  
  for (int i = 3; i <= sqrt(n); i = i + 2)  
  {  
      // While i divides n, print i and divide n
    while (n % i == 0)  
    {  
      n = n/i;  
      return false;
      if(find(primes.begin(), primes.end(), i) == primes.end())
        primes.push_back(i);
    }
  }  

  // This condition is to handle the case when n  
  // is a prime number greater than 2  
  if (n > 2)  
  {
    if(find(primes.begin(), primes.end(), n) == primes.end())
      return true;
  }
  
  return false;
}

int main()
{
  int x;
  scanf("%d", &x);
  
  primes.push_back(2);
  
  int temp = 2;
  
  while(!prime_factors(temp) || temp < x)
    temp++;
  
  printf("%d\n", temp);
  
  return 0;
}


Measured memory_bytes: 2304
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug { 
    ($($a: expr),*) => { 
        println!(concat!($(stringify!($a)," = {:?}, "),*), $($a),*);
    } 
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(u64);
    let s = get!(String);
    let mut count = 0u64;
    for c in s.chars() {
        if c == 'R' {
            count += 1;
        }
    }
    if 2*count > n {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 8572
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  bool b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = false;
  }
  for (int i = 0, count = 1;; count++) {
    if (a[i] == 2) {
      cout << count << endl;
      return 0;
    }
    if (b[a[i] - 1]) {
      cout << "-1" << endl;
      return 0;
    }
    b[a[i] - 1] = true;
    i = a[i] - 1;
  }
  return 0;
}


Measured memory_bytes: 768
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, a, b;
  cin >> n >> a >> b;
  if ((b - a) % 2) {
    cout << "Borys\n";
  } else {
    cout << "Alice\n";
  }
}



Measured memory_bytes: 256
d,e=[list(map(int,input().split()))for _ in range(2)];e[3],e[4]=e[4],e[3]
t=0
for p in('012345','152304','215043','310542','402351','513240'):
 f=[d[int(j)]for j in p];f[3],f[4]=f[4],f[3]
 if f[0]==e[0]:
  f=f[1:5]*2
  for j in range(4):
   if f[j:j+4]==e[1:5]:t=1
print(('No','Yes')[t])


Measured memory_bytes: 5604
n = list(input())
n = [int(i) for i in n] 
if n[0]>n[1] or (n[0]==n[1] and n[0]>=n[2]):
    print(str(n[0])*3)
elif n[0]<n[1] or (n[0]==n[1] and n[0]<n[2]):
    print(str(n[0]+1)*3)

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
const int MAXN = 1e5+5;
char  S[MAXN];
int out[MAXN];
int M, N;
int K;

// Greedily take largest possible steps from N -> 0
// Range [head, tail) are Game Over squares

void display() {
  for (int i = 0; i < K; ++i) {
    printf("%d ", out[i]);
  }
  putchar('\n');
}

bool solve() {
  M = std::min(N, M);
  K = 0;
  int head = N;
  int tail = N;
  while (tail > 0) {
    int src = tail - std::min(M, tail);
    auto is_valid = [](char c) { return (c == '0'); };
    auto itr = std::find_if(S+src, S+head, is_valid);
    int next = itr - S;
    if (next == head) {
      return false;
    }
    head = src;
    out[K++] = (tail - next);
    tail = next;
  }
  std::reverse(out, out+K);
  return true;
}

int main() {
  scanf(" %d%d%s", &N, &M, S);
  if (solve()) {
    display();
  } else {
    puts("-1");
  }
  return 0;
}

Measured memory_bytes: 896
using System.Collections.Generic;
using System;

public class P
{
    public string mmdd { get; set; }
    public string id { get; set; }
    public int a { get; set; }
    public int b { get; set; }
}

public class P2
{
    public string mmdd { get; set; }
    public int s { get; set; }
    public int t { get; set; }
}

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var d = new Dictionary<string, int>();
            var pg = new List<P>();
            var god = new List<P2>();
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ', ':');
                var mmdd = line[0];
                var hh = int.Parse(line[1]);
                var mm = int.Parse(line[2]);
                var io = line[3];
                var id = line[4];
                var hm = 60 * hh + mm;
                if (io == "I") d[id] = hm;
                else
                    if (id == "000") god.Add(new P2 { mmdd = mmdd, s = d[id], t = hm });
                    else
                    {
                        pg.Add(new P { mmdd = mmdd, id = id, a = d[id], b = hm });
                        d[id] = 0;
                    }
            }
            Console.WriteLine(getAns(d,pg,god));
        }
    }
    public static int getAns (Dictionary<string,int> d , List<P> pg, List<P2 > god)
    {
        var ans = 0;
        foreach (var x in pg)
            foreach (var y in god)
                if (x.mmdd == y.mmdd)
                {
                    if (x.a > y.t | x.b < y.s) continue;
                    var sd = x.a >= y.s ? x.a : y.s;
                    var td = x.b <= y.t ? x.b : y.t;
                    d[x.id] += td - sd;
                    ans = Math.Max(ans, d[x.id]);
                }
        return ans;
    }
}




Measured memory_bytes: 19972
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;

int main() {
    int X, Y;
    cin>>X>>Y;
    ll ans;
    if((2*Y-X)%3!=0) ans = 0;
    else{
        ll a = (2*Y - X)/3;
        ll b = (2*X - Y)/3;
        if((a<0) | (b<0)) ans = 0;
        else{
            ll ue = 1;
            ll shita1 = 1;
            ll shita2 = 1;
            for(ll i=1;i<=a+b;++i){
                ue *= i;
                ue %= mod;
            }
            for(ll i=1;i<=a;++i){
                shita1 *= i;
                shita1 %= mod;
            }
            for(ll i=1;i<=b;++i){
                shita2 *= i;
                shita2 %= mod;
            }
            ll h;
            ll shita11 = 1, shita22 = 1;
            ll tmpshita;
            ll two;
            h = mod - 2;
            while(h>0){
                tmpshita = shita1;
                two = 1;
                while(2*two <= h){
                    two *= 2;
                    tmpshita *= tmpshita;
                    tmpshita %= mod;
                }
                h -= two;
                shita11 *= tmpshita;
                shita11 %= mod;
            }
            h = mod - 2;
            while(h>0){
                tmpshita = shita2;
                two = 1;
                while(2*two <= h){
                    two *= 2;
                    tmpshita *= tmpshita;
                    tmpshita %= mod;
                }
                h -= two;
                shita22 *= tmpshita;
                shita22 %= mod;
            }
            ans = ue * shita11 % mod * shita22 % mod;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
n=int(input())
h=[int(i) for i in input().split()]
h.append(10000)
dp=[float('inf') for i in range(n+1)]
dp[0]=0
for i in range(n-1):
    dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]))
    if(i<n-2):
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]))
print(dp[n-1])

Measured memory_bytes: 13976
/**
 * @author derrick20
 */
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt();
        int M = sc.nextInt();
        adjList = new ArrayList[N];
        for (int i = 0; i < N; i++) {
            adjList[i] = new ArrayList<>();
        }
        for (int i = 0; i < M; i++) {
            int u = sc.nextInt() - 1;
            int v = sc.nextInt() - 1;
            adjList[u].add(v);
        }
        maxDist = new int[N];
        Arrays.fill(maxDist, -1);
        for (int i = 0; i < N; i++) {
            dfs(i);
        }
        out.println(ans);
        out.close();
    }

    static ArrayList<Integer>[] adjList;
    static int[] maxDist;
    static int ans;

    // Return the longest path we can get starting from this node
    static int dfs(int node) {
        if (maxDist[node] != -1) {
            // Memoizing!
            return maxDist[node];
        }
        else {
            int max = 0;
            for (int adj : adjList[node]) {
                max = Math.max(max, 1 + dfs(adj));
            }
            ans = Math.max(ans, max);
            return maxDist[node] = max;
        }
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        FastScanner(FileReader s) {
            br = new BufferedReader(s);
        }

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

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

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

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

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

Measured memory_bytes: 59760
#include<set>
#include<queue>
#include<cstdio>

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

using namespace std;

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

struct data{
	int S;
	int x,y;
	bool operator<(const data &D)const{
		if(S!=D.S) return S<D.S;
		if(x!=D.x) return x<D.x;
		return y<D.y;
	}
};

int n;

data next_state(int S,int x,int y){
	S|=1<<y*n+x;
	int T=0;
	rep(i,n) rep(j,n) {
		int cnt=0;
		rep(k,8){
			int yy=i+dy[k],xx=j+dx[k];
			if(0<=yy && yy<n && 0<=xx && xx<n && S&(1<<yy*n+xx)) cnt++;
		}
		if(S&(1<<i*n+j)){
			if(cnt==2 || cnt==3) T|=1<<i*n+j;
		}
		else{
			if(cnt==3) T|=1<<i*n+j;
		}
	}
	T&=~(1<<y*n+x);
	return (data){T,x,y};
}

int main(){
	for(;scanf("%d",&n),n;){
		data ini={};
		rep(i,n){
			char s[6]; scanf("%s",s);
			rep(j,n){
				if(s[j]=='#') ini.S|=1<<(i*n+j);
				if(s[j]=='@') ini.x=j, ini.y=i;
			}
		}

		int ans=-1;
		set<data> Vis;
		queue< pair<int,data> > Q; Q.push(make_pair(0,ini));
		while(!Q.empty()){
			int t=Q.front().first;
			data D=Q.front().second; Q.pop();

			if(t>20) break;

			if(Vis.count(D)>0) continue;
			Vis.insert(D);

			if(D.S==0){ ans=t; break; }

			rep(k,8){
				int yy=D.y+dy[k],xx=D.x+dx[k];
				if(0<=yy && yy<n && 0<=xx && xx<n && (D.S&(1<<yy*n+xx))==0){
					Q.push(make_pair(t+1,next_state(D.S,xx,yy)));
				}
			}
		}

		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 0
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1 for _ in range(n+1)]

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    


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

bridge = [tuple(map(int, input().split())) for _ in range(M)]

ins = UnionFind(N)

for i in range(M):
    ins.union(bridge[M-1-i][0],bridge[M-1-i][1])

ans = 0

for i in range(1,N+1):
    if ins.find(i) == i:
        ans = ans + 1

print(ans)


Measured memory_bytes: 22948
//深度优先搜索 ,递归实现 
#include <iostream>

using namespace std;

const int N = 100;

const int NIL = -1;

int n;
bool graph[N+1][N+1] = {false}; //关系矩阵图 
char *color;//标记点的状态 B代表访问结束，W代表未访问，G代表正在访问 
int *d; //首次发现该点的时间 
int *f;  //结束访问该点的时间 

int mtime = 0; //当前的时间 


//递归的深度优先搜索 
void dfs(int u) {
	color[u] = 'G';
	d[u] = ++mtime;
	for (int j = 1;j<=n;j++) {
		if (graph[u][j] && color[j] == 'W') {
			dfs(j);
		}
	}
	color[u] = 'B';
	f[u] = ++mtime;
} 

int main() {
	cin >> n;
	color = new char[n+1]; 
	d = new int[n+1];
	f = new int[n+1];
	
	//初始化 
	for (int i = 1;i<=n;i++) {
		color[i] = 'W';
		d[i] = 0;
		f[i] = 0;
	}
	
	for (int i=0;i<n;i++) {
		int x,k;
		cin >> x >> k;
		for (int j = 0;j<k;j++) {
			int y;
			cin >> y;
			graph[x][y] = true; 
		}
	}
	
	for (int i = 1;i<=n;i++) {
		if (color[i] == 'W') {
			dfs(i);
		}
	}
	
	for (int i = 1;i<=n;i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
	
	delete[] color;
	delete[] d;
	delete[] f;
}


Measured memory_bytes: 3116
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

int N;
bool IsY()
{
	char ch;
	cin >> ch;
	return ch == 'Y';
}

void Ans(int n)
{
	cout << "! " << n << endl;
	exit(0);
}

signed main()
{
	int a = 1000000000;
	int keta = 0;
	for (int k = 0; k < 9; k++)
	{
		cout << "? " << a << endl;
		if (IsY())
		{
			keta = 9 - k;
			break;
		}
		a /= 10;
	}
	if (keta == 9)
	{
		int b = 200000000;
		keta = 0;
		for (int k = 0; k < 9; k++)
		{
			cout << "? " << b << endl;
			if (!IsY())
			{
				keta = 9 - k;
				break;
			}
			b /= 10;
		}
	}

	int max = (int)pow(10, keta + 1) - 1;
	int min = (int)pow(10, keta);

	while (true)
	{
		int n = (max - min) / 2 + min;

		cout << "? " << (n * 10) << endl;
		if (IsY())
		{
			max = n;
		}
		else
		{
			min = n;
		}

		if (max - min <= 1)
		{
			cout << "? " << (min * 10) << endl;
			if (IsY())
			{
				Ans(min);
			}
			else
			{
				Ans(max);
			}
			break;
		}
	}
}

Measured memory_bytes: 596
#include <stdio.h>

int T[105];
int P[105];
int X[105];

int main(){

	int N;
	scanf("%d",&N);

	int sum=0;

	int i;
	for(i=0;i<N;i++){
	scanf(" %d",&T[i]);
	sum+=T[i];
	}

	int M;

	scanf("%d",&M);

	for(i=0;i<M;i++){
	scanf("%d %d",&P[i],&X[i]);
	printf("%d\n",sum+X[i]-T[P[i]-1]);
	}

	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, K, a, b, wc, r int
	fmt.Scan(&N, &K)
	m := map[int]int{}
	for i := 0; i < N; i++ {
		fmt.Scan(&a, &b)
		m[a] += b
	}
	var arr []int
	for k, _ := range m {
		arr = append(arr, k)
	}
	sort.Sort(sort.IntSlice(arr))
	for i := 0; i < len(arr); i++ {
		wc += m[arr[i]]
		if K <= wc {
			r = arr[i]
			break
		}
	}
	fmt.Println(r)
}

Measured memory_bytes: 7936
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	cout << (N - 2) * 180 << endl;

	return 0;
}

Measured memory_bytes: 256
#54 文字のカウント

cnt = [0 for i in range(26)]
while True:
        try:
                s = input()
        except:
                break
        for i in range(len(s)):
                m = ord(s[i])-ord('A')
                if (m >= 0 and m < 26):
                        cnt[m]+=1
                m = ord(s[i])-ord('a')
                if(m >= 0 and m < 26):
                        cnt[m]+=1
for i in range(26):
        print(chr(i+ord('a')),":",cnt[i])


Measured memory_bytes: 5564
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include <numeric>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 99999999

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}


int main() {
	int N;
	map<ll, int>mp;
	cin >> N;
	REP(i, N) {
		ll a;
		cin >> a;
		mp[a]++;
	}
	ll h=0, w=0;
	bool ok1 = false, ok2 = false;
	for (auto x : mp) {
		if (x.second >= 2) {
			h = max(h, x.first);
			ok1 = true;
		}
	}
	mp[h] -= 2;
	for (auto x : mp) {
		if (x.second >= 2) {
			w = max(w, x.first);
			ok2 = true;
		}
	}
	if (!ok1 || !ok2) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = h * w;
	cout << ans << endl;
}

Measured memory_bytes: 6528
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
K = [0] * N
A = []
popular = [1] * M
count = 0

for i in range(N):
	tmp = list(map(int, input().split()))
	K[i] = tmp[0]
	A.append(tmp[1:])
	
for i in range(N):
	dislike = [1] * M
	for j in range(K[i]):
		dislike[A[i][j] - 1] = 0
		
	for k in range(M):
		if dislike[k] == 1:
			popular[k] = 0

for i in range(M):
	if popular[i] == 1:
		count += 1
		
print(count)

Measured memory_bytes: 38384
using System;
using System.Collections.Generic;

class ABC
{
    public static void Main()
    {
        int count = 0;
        int size = int.Parse(Console.ReadLine());
        string[] strs = Console.ReadLine().Split(' ');
        for(int i = 1; i <= size; ++i)
        {
            if(int.Parse(strs[i - 1]) != i)
            {
                count++;
            }
        }
        if(count == 0 || count == 2)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 13140
import * as fs from 'fs';

const input: string = fs.readFileSync('/dev/stdin', 'utf8');
const args: string[][] =
  input.split('\n').map(l => l.split(' '));

const [n, k] = args[0].map(x => parseInt(x));
const x = args[1].map(x => parseInt(x));

type Interval = {
  left: number
  right: number
}

const intervals: Interval[] = [];
for (let i = 0; i + k - 1 < n; i++) {
  intervals.push({
    left: x[i],
    right: x[i + k - 1]
  });
}

const time = intervals.map(getTime).reduce((x, y) => Math.min(x, y));

console.log(time);

function getTime(interval: Interval): number {
  const l = interval.left;
  const r = interval.right;
  if (l * r >= 0) {
    return Math.max(Math.abs(l), Math.abs(r))
  } else {
    if (Math.abs(l) < Math.abs(r)) {
      return 2 * Math.abs(l) + Math.abs(r)
    } else {
      return Math.abs(l) + 2 * Math.abs(r)
    }
  }
}


Measured memory_bytes: 28484
#include <stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int a[n];
    int i=0;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=n-1;i>0;i--){
        printf("%d ",a[i]);
    }
    printf("%d\n",a[0]);


    return 0;
}


Measured memory_bytes: 2100
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
type I = usize;

fn main() {
    input!{
      r: usize,
      g: usize,
      b: usize,
      n: usize,
    }
    let mut ans = 0;
    for rr in 0..n+1 {
        let r = r*rr;
        if r > n {
            break;
        }
        for gg in 0..n+1 {
            let g = g * gg;
            if r + g > n {
                break;
            }
            let bb = n - r - g;
            if bb % b != 0 {
                continue;
            }
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// #include <cstdio>
// int a;
// scanf("%d", &a);
// printf("%d\n", a);
//
// for (int i=0; i<n; ++i)
// 	scanf("%d", &a[i]);
//
// char c;
// scanf(" %c", &c);
//
// cout << "\n";

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

/*
ll	myPow(ll x, ll n) {
	if (0==n)
		return 1;
	if (0==n%2)
		return myPow(x*x%MOD, n/2);
	else
		return x*myPow(x, n-1)%MOD;
}
*/
ll	myPow(ll x, ll n) {
	ll r=1;
	while(n>0)
		if (0==n%2) {
			x *=x;
			x %=MOD;
			n /=2;
		} else {
			r *=x;
			r %=MOD;
			n--;
		}
	return r;
}

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int K, N;
	cin >>K >>N;
	vector<int> A(N, 0);
	Rep0(i, N)
		cin >>A.at(i);
	A.push_back(A.at(0)+K);
	vector<int> B(N, 0);
	Rep0(i, N)
		B.at(i)=A.at(i+1)-A.at(i);
	Sort(B);
	cout <<K-B.back() <<endl;
	return 0;
}



Measured memory_bytes: 1804
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = double.Parse(Console.ReadLine());
            Console.WriteLine(Math.Ceiling(n / 2) / (double) n);
        }

    }
}

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

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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;

int main(){
    int a, b;
    cin >> a >> b;
    int x = 1;
    if(b==1){
        cout << 0 << endl;
    } else {
        while(a*x-x+1 < b){
            x++;
        }
         cout << x << endl;
    }
   

}

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

count = 0
first = 0

while first < n:
    for i in range( n-1, first, -1 ):
        if a[i] < a[i-1]:
            t = a[i]
            a[i] = a[i-1]
            a[i-1] = t
            count += 1
    first += 1

print(*a)
print(count)

Measured memory_bytes: 7724
while True:
    n,m = map(int, input().split())
    if(n+m  ==0):
        break
    li = list()
    for i in range(m):
        line = [num for num in map(int, input().split())]
        li.append(line)
    ans = [0 for i in range(n)]
    for i in range(m):
        for j in range(n):
            ans[j] += li[i][j]
    print(max(ans))


Measured memory_bytes: 7568