akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    string s;
    cin >> s;
    vector<char> a(s.size());
    rep(i,s.size()){
        a.at(i)=s.at(i);
    }
    sort(a.begin(),a.end());
    bool flag=true;
    rep(i,s.size()-1){
        if(a.at(i)==a.at(i+1))flag=false;
    }
    if(flag) cout << "yes" << endl;
    else cout << "no" << endl;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i,n){
		cin >> p[i];
	}
	int ans = 0;
	int minimum = p[0];
	rep(i,n){
		if(p[i] <= minimum) {
			ans++;
			minimum = p[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4024
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

vector<size_t> factors(size_t n) {
  vector<size_t> result;
  for (size_t d = 1; d * d <= n; d++) {
    if (n % d == 0) {
      result.push_back(d);
      if (n / d != d) {
        result.push_back(n / d);
      }
    }
  }
  return result;
}

int main() {
  int64_t N;
  cin >> N;
  vector<size_t> fs = factors(N);

  int64_t result = 0;
  for (int64_t q : fs) {
    int64_t m = N / q - 1;
    if (q < m) {
      result += m;
    }
  }
  cout << result << endl;

  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll N;
ll a[20][20];
ll dp[1ll<<16];

ll rec(ll mask){
	if(dp[mask]>=0) return dp[mask];
	if(__builtin_popcountll(mask)==1) return 0;

	ll res = 0;
	REP(i, N){
		REP(j, N){
			if((mask >> i & 1) && (mask >> j & 1) && (i<j)){
				res += a[i][j];
			}
		}
	}

	for(ll T=mask;T>0;T=(T-1)&mask){
		if(T==mask) continue;
		ll S = mask ^ T;
		ll tmp = 0;
		tmp += rec(T);
		tmp += rec(S);
		res = max(res, tmp);
	}

	dp[mask] = res;
	return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, (1ll<<16)) dp[i] = -1;

    cin >> N;
    REP(i, N){
    	REP(j, N){
    		cin >> a[i][j];
    	}
    }

    cout << rec((1ll<<N)-1) << endl;

    /*
    REP(i, (1ll<<N)){
    	cout << dp[i] << endl;
    }
    */
    return 0;
}

Measured memory_bytes: 768
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    vector<ll> H(N);
    for (ll i = 0; i < N; i++) {
        cin >> H[i];
    }

    ll ans = 0, h = 0;
    for (ll i = 0; i < N; i++) {
        if (H[i] >= h) {
            ans++;
            h = H[i];
        }
    }

    cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    int a,b,c;
    cin >>a>>b>>c;
    cout << max(b+c-a,0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  string ans = "";
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '0') {
      ans += "0";
    }
    else if (S[i] == '1') {
      ans += "1";
    }
    else {
      if (ans.size() != 0) {
        ans = ans.substr(0,ans.size() - 1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int main(void)
{
    double s[1000],t1,t2;
    int n,i;
    while(1){
        scanf("%d",&n);
        if(n==0)break;
        t1=0;
        for(i=0;i<n;i++){
            scanf("%lf",&s[i]);
            t1+=s[i];
        }
        t1/=n;
        t2=0;
        for(i=0;i<n;i++)t2+=pow(s[i]-t1,2);
        printf("%.5f\n",sqrt(t2/n));
    }
    return 0;
}


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

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

int main(void){
    long long int N; cin >> N;
    vector<long long int> a(N);
    rep(i, N) cin >> a[i];

    int index = 1;
    int sum = 0;
    rep(i, N){
        if(index == a[i]){
            index++;
        }else{
            sum++;
        }
    }
    if(sum == N) sum = -1;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//Bellman Ford法
struct edge {
	ll to;
	ll cost;
};
typedef pair<ll, ll> P;

bool bellman_f(int s, vector<vector<edge>>& g, vector<ll>& d) {
	d = vector<ll>(g.size(), INF_LL);
	d[s] = 0;
	for (int i = 0; i < g.size(); i++) {
		for (int j = 0; j < g.size(); j++) {
			for (int k = 0; k < g[j].size(); k++) {
				auto e = g[j][k];
				if (d[j] != INF_LL && d[e.to] > d[j] + e.cost) {
					d[e.to] = d[j] + e.cost;
					if (i == g.size() - 1)return true;
				}
			}
		}
	}
	return false;
}

bool bfs(int pos, vector<bool>& used, vector<vector<edge>>& g) {
	if (pos == g.size() - 1)return true;
	used[pos] = true;
	bool ret = false;
	for (int i = 0; i < g[pos].size(); i++) {
		if (used[g[pos][i].to])continue;
		ret |= bfs(g[pos][i].to, used, g);
	}
	return ret;
}

int main() {
	io_init;
	int N, M, P;
	cin >> N >> M >> P;
	vector<vector<edge>> g(N+1),par(N+1);
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		par[b].push_back({ a,P - c });
		g[a].push_back({ b,P - c });
	}
	for (int i = 1; i <= N; i++) {
		vector<bool> used(N + 1, 0);
		if (!bfs(i, used, g)) {
			for (int j = 0; j < par[i].size(); j++) {
				for (int k = 0; k < g[par[i][j].to].size(); k++) {
					if (g[par[i][j].to][k].to == i)g[par[i][j].to][k].to = 0;
				}
			}
		}
	}
	vector<ll> d;
	bool f = bellman_f(1, g, d);
	if (f)cout << -1 << endl;
	else {
		if (d[N] >= 0)d[N] = 0;
		cout << -d[N] << endl;
	}
}

Measured memory_bytes: 768
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.trim_right();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let (n, m) = parse_line!(usize, usize);
    let mut aa = parse_vec!(usize);

    let mut sum = 0;
    for &a in aa.iter() {
        sum += a;
    }

    aa.sort();
    aa.reverse();

    if aa[m - 1] < (sum / (4 * m)) || (sum % (4 * m) != 0 && aa[m - 1] == sum / (4 * m)) {
        println!("No");
    } else {
        println!("Yes");
    }
}


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

int main(){
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (r > x || r > y){
		cout << "No" << endl;
	}
	else{
		if (x + r > W || y + r > H){
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
	return 0;
}

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

int main() {
	int r, g, b, n;
	scanf("%d%d%d%d", &r, &g, &b, &n);
	int res = 0;
	for(int i = 0; i <= n / r; i++)
		for(int j = 0; j <= n / g; j++) {
			int val = r * i + g * j;
			if(val > n) continue;
			if((n - val) % b == 0) res++;
		}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
#define GG return printf("Impossible\n"),0
int a[N],num[N];
int main()
{
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]),num[a[i]]++;
    sort(a+1,a+n+1);
    if(a[n]!=a[n-1])GG;
    if(a[1]!=(a[n]+1)/2)GG;
    for(int i=a[1]+1;i<a[n];i++)if(num[i]<=1)GG;
    if(!(a[n]&1)){if(num[a[1]]>=2)GG;}
    else {if(num[a[1]]>=3)GG;}
    printf("Possible\n");
}


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

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int a , b;
    cin >> a >> b;

    for (int i = 1; i < 1001; ++i) {
        int x = i * 0.08;
        int y = i * 0.1;
        if(x == a && y == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define MOD 1000000007
typedef pair<li, li> PI;

li h[111];

int main(void)
{
	li n;
	cin >> n;
	li res = 0;
	li ma = 0;
	rep(i, n) {
		cin >> h[i];
		if (ma <= h[i]) {
			res++;
		}
		ma = max(ma, h[i]);
	}
	cout << res << endl;



	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int n,ans=0;
    scanf("%d",&n);
    for (int i=1; i<=n; i++){
        if (i%2!=0){
            int count=0;
            for (int j=1; j<=i; j++){
                if (i%j==0){
                    count++;
                }
            }
            if (count==8){
                ans++;
            }
        }
    }
    printf("%d\n",ans);
	return 0 ;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

int main() {
    ll V,E;
    cin >> V>>E;
    vector<vector<ll>> dp(V,vector<ll>(V,INF));
    rep(i,E){
        ll s,t,d;
        cin >> s>> t>>d;
        //s--;
        //t--;
        dp[s][t] = d;

    }
    rep(i,V){
        dp[i][i] = 0;
    }
    rep(k,V){
        rep(i,V){
            rep(j,V){
                chmin(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
    
    rep(i,V){
        if(dp[i][i] <0){
            cout << "NEGATIVE CYCLE"<<endl;
            return 0;
        }
    }
    rep(i,V){
        rep(j,V){
            if(dp[i][j] > INF/2){
                cout << "INF";
            }else{
                cout << dp[i][j];
            }
            if(j!=V-1){
                cout <<" ";
            }
        }
        cout <<endl;
    }
    
    
    return 0;
    

}



Measured memory_bytes: 3224
#include<bits/stdc++.h>
using lint=long long;
void debug_impl(){std::cerr<<'\n';}
template<class Head,class...Tail>void debug_impl(Head head, Tail... tail){std::cerr << " " << head;debug_impl(tail...);}
    template<class Container,class Value=typename Container::value_type,std::enable_if_t<!std::is_same<Container,std::string>::value,std::nullptr_t> = nullptr>
std::ostream&operator<<(std::ostream&os,Container const&v)
{os<<"{";for(auto it=v.begin();it!=v.end();it++){os<<(it!=v.begin()?",":"")<<*it;}return os<<"}";}
    template<template<class...>class Tuple,class...Args,std::size_t...Inds,std::size_t=std::tuple_size<Tuple<Args...>>::value>
std::ostream&tuple_output_impl(std::ostream&os,const Tuple<Args...>&tuple,std::integer_sequence<std::size_t,Inds...>)
{os<<"(";(void)std::initializer_list<int>{((void)(os<<(Inds>0?",":"")<<std::get<Inds>(tuple)),0)...};return os<<")";}
    template<template<class...>class Tuple,class...Args,std::size_t=std::tuple_size<Tuple<Args...>>::value>
std::ostream&operator<<(std::ostream&os,const Tuple<Args...>&tuple)
{return tuple_output_impl(os,tuple,std::index_sequence_for<Args...>());}
#define DEBUG 1
#if DEBUG
#define debug(...)do{std::cerr<<std::boolalpha<<"["<<#__VA_ARGS__<<"]:";debug_impl(__VA_ARGS__);std::cerr<<std::noboolalpha;}while(false)
#else
#define debug(...) {}
#endif
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    if(n==3){
        std::cout<<61<<'\n';
        return 0;
    }
    std::vector<lint>ok(256,1);
    for(lint i=0;i<256;i++){
        std::vector<lint>a;
        for(lint j=i;j;j/=4)a.push_back(j%4);
        a.resize(4);
        std::reverse(a.begin(),a.end());
        for(lint j=0;j<4;j++){
            ok.at(i)&=!(
                a.at(0)==0&&a.at(1)==1&&a.at(2)==2||
                a.at(1)==0&&a.at(2)==1&&a.at(3)==2);
            if(j==3)break;
            if(j)std::swap(a.at(j-1),a.at(j));
            std::swap(a.at(j),a.at(j+1));
        }
    }
    auto dp=ok;
    lint mod=1'000'000'007;
    auto add_eq=[mod](lint&x,lint y){x+=y;if(mod<=x)x-=mod;};
    for(n-=4;n;n--){
        std::vector<lint>new_dp(256);
        for(lint i=0;i<256;i++){
            for(lint j=0;j<4;j++){
                lint k=i%64*4+j;
                if(!ok.at(k))continue;
                add_eq(new_dp.at(k),dp.at(i));
            }
        }
        new_dp.swap(dp);
    }
    lint ans=0;
    for(lint i=0;i<256;i++){
        ans=(ans+dp.at(i))%mod;
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, m;
    cin >> n >> m;
    vector<string> image1(n);
    REP(i, n) cin >> image1.at(i);
    vector<string> image2(m);
    REP(i, m) cin >> image2.at(i);

    REP(i, n - m + 1) {
        REP(j, n - m + 1) {
            bool flag = true;
            REP(k, m) {
                if (image1.at(i + k).substr(j, m) != image2.at(k)) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

class LCA{
  public:
    int N;
    int bitlen = 1;
    vector<vector<int>> edges;
    vector<int> d; //depth
    vector<vector<int>> anc; // bitlen * N
    // the number of vertexs
    LCA(int _N):N(_N){
        init(N);
    }
    LCA(int _N, vector< vector<int>> G):N(_N){
        init(N, G);
    }
    void init(int n){
        while((1 << bitlen) < n){
            bitlen++;
        }
        d.assign(n, 0);
        anc.assign(bitlen, vector<int>(n,-1));
        dfs();
    }
    void init(int n, vector<vector<int>> G){
        edges = G;
        init(n);
    }
    void dfs(int v = 0, int p = -1){
        anc[0][v] = p;
        for(int i = 0; i+1 < bitlen; ++i){
            anc[i+1][v] = (anc[i][v] >= 0) ? anc[i][anc[i][v]] : -1;
        }
        for(auto nv: edges[v]) if(nv != p){
            d[nv] = d[v]+1;
            dfs(nv, v);
        }
    }
    int lca(int u, int v){
        if(d[u] > d[v]) swap(u, v);
        for(int i = 0; i < bitlen;i++){
            if((d[v] - d[u]) & (1<<i)){
                v = anc[i][v];
            }
        }
        if(u == v) return u;
        for(int i = bitlen-1; i >= 0;i--){
            if(anc[i][u] != anc[i][v]){
                u = anc[i][u];
                v = anc[i][v];
            }
        }
        return anc[0][u];
    }
    void debug(){
        print(d);
        for(int i = 0;i < bitlen;i++){
            cerr << i << ": ";print(anc[i]);
        }
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    vvec<int> g(N);
    rep(i,N){
        int k;
        cin >> k;
        rep(j,k){
            int a;
            cin >> a;
            g[i].push_back(a);
            g[a].push_back(i);
        }
    }
    LCA G(N, g);
    //G.debug();
    int Q;
    cin >> Q;
    while(Q--){
        int a, b;
        cin >> a >> b;
        cout << G.lca(a, b) << endl;
    }
}


Measured memory_bytes: 35048
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/

#define max(a,b) ((a>b)?a:b)
#define ABS(a) (((a)>(0))?a:-(a))

//ABC 144 A

int main(void)
{
  int N;
  int M;

  scanf("%d%d", &N, &M);
  if(N > 9 || M > 9) printf("-1\n" );
  else printf("%d\n", N * M);
  return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())
UF = [-1] * (N+1)
def find(x):
    global UF
    if UF[x] == -1:
        return x
    else:
        UF[x] = find(UF[x])
        return UF[x]
def union(x,y):
    global UF
    xx = find(x)
    yy = find(y)
    if UF[x] == UF[y] == -1:
        UF[y] = xx
        return
    elif xx == yy:
        return 
    else:
        UF[yy] = xx
        return 
    
for _ in range(M):
    x, y, z = map(int, input().split())
    union(x,y)
    
print(sum([i < 0 for i in UF[1:]]))

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

using namespace std;

const int N = 100005;
char s[N];

int no, so, ea, we;

int main()
{
  scanf("%s", s);
  
  int n = strlen(s);
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'N') no = 1;
    else if (s[i] == 'S') so = 1;
    else if (s[i] == 'W') we = 1;
    else if (s[i] == 'E') ea = 1;
  }
  
  if ((so ^ no) || (we ^ ea)) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }
  return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)

using namespace std;

const int N=1e5+100;
int n,m,cnt[N],a[N],ans;

int main(){
	scanf("%d%d",&n,&m);
	a[1]=1;
	rep (i,1,n) cnt[i]=1;
	rep (i,1,m){
		int x,y; scanf("%d%d",&x,&y);
		a[y]|=a[x]; cnt[y]++,cnt[x]--;
		if (!cnt[x]) a[x]=0;
	}
	rep (i,1,n) ans+=a[i];
	printf("%d\n",ans);
	return 0;
}

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

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

int main(void) {
    int a, b, k;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> k;
    FOR(i, a, min(b, a + k - 1) + 1) {
        cout << i << "\n";
    }
    FOR(i, max(b - k + 1, a + k), b + 1) {
        cout << i << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
struct edge {
	int to, cost;
};
// other libs
int gcd(int a, int b) {
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

class dijkstra {
  private:
	int V;
	int d[100002];
	priority_queue<P, vector<P>, greater<>> que;

  public:
	dijkstra(int v, int s, vector<edge> G[]) {
		V = v;
		update(s, G);
	}

	void update(int s, vector<edge> G[]) {
		fill(d, d + V + 1, 100000000000ll);
		d[s] = 0;
		que.push(make_pair(0, s));
		while (!que.empty()) {
			P p = que.top();
			que.pop();
			int v = p.second;
			if (d[v] < p.first) continue;
			rep(i, G[v].size()) {
				edge e = G[v][i];
				if (d[e.to] > d[v] + e.cost) {
					d[e.to] = d[v] + e.cost;
					que.push(make_pair(d[e.to], e.to));
				}
			}
		}
	}

	int find(int e) {
		return d[e];
	}
};
template<typename T>
class Union_Find {
  private:
	vector<T> t, s;

  public:
	Union_Find(T max_length) {
		rep(i, max_length + 1) {
			t.push_back(i);
			s.push_back(1);
		}
	}

	void Union(T x, T y) {
		if (same(x, y)) return;
		T tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}
	T Find(T n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}

	bool same(T x, T y) {
		return Find(x) == Find(y);
	}

	T get_Size(size_t a) {
		return s[a];
	}
};
bool ifPrime(int n) {
	if (n == 1) return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) return false;
	}
	return true;
}

set<int> prime_num_factor(int n) {
	if (n < 2) return set<int>();
	set<int> prime;
	prime.insert(2);
	for (int i = 3; i <= n; i++) {
		for (int it : prime) {
			if (it * it > i) {
				prime.insert(i);
				break;
			}
			if (i % it == 0) break;
		}
	}
	return prime;
}
vector<int> makeDivisors(int n) {
	vector<int> re;
	REP(i, 1, sqrt(n) + 1) {
		if (n % i == 0) {
			re.push_back(i);
			if (i != n / i) re.push_back(n / i);
		}
	}
	return re;
}
int modPow(int a, int n, int mod) {
	int ret = 1;
	while (n) {
		if (n & 1) ret = ret * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ret;
}
signed main(signed argc, char* argv[]) {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	cout<<n*n<<endl;
}


Measured memory_bytes: 256
def resolve():
    s = input()
    t = input()
    ls = len(s)
    lt = len(t)
    c = []
    for i in range(ls - lt + 1):
        count = 0
        for j in range(lt):
            if s[i+j] == t[j]:
                count += 1
        c.append(count)
    print(lt - max(c))
resolve()    

Measured memory_bytes: 8984
#include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define pb push_back
#define sz(x) (int)x.size()
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define F first
#define S second
#define watch(x) cerr << "\n" << (#x) << " = " << (x) << "\n"
using namespace std;

long long fact[2001];			
long long inverseFact[2001];   

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

ll modInverse(ll A, ll M){
	return modularExponentiation(A, M - 2, M);
}

void precalculate_factorials(){
	fact[0] = 1;
	inverseFact[0] = 1;
	for(int i = 1; i <= 2000; i++){
		fact[i] = (fact[i - 1] * i) % mod;
		inverseFact[i] = modInverse(fact[i], mod);
	}
}
 
ll nCr(ll n, ll r){
	long long ans = fact[n];
	ans = (ans * inverseFact[r]) % mod;
	ans = (ans * inverseFact[n - r]) % mod;
	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0); 
    cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	precalculate_factorials();
	//cout << nCr(5, 0) << " " << nCr(10, 4) << "\n";
	ll s;
	cin >> s;
	ll ans = 0;
	int j = 3, k = 0;
	while(s - j >= 0 && (s - j >= k)){
		ll x = nCr(s - j, k);
		//cout << x << " ";
		ans = (ans + x) % mod;
		k++;
		j += 2;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3672
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const int INF = 10000;



int main(){
	int Q;
	cin>>Q;
	REP(T,Q){
		long N;
		cin>>N;
		int cnt=0;
		set<long>st;
		while(N>=10){
			string str=toString(N);
			long nN=0;
			FOR(i,1,SZ(str)){
				nN=max(nN,toLong(str.substr(0,i))*toLong(str.substr(i)));
			}
			if(st.find(nN)!=st.end()){
				cnt=-1;break;
			}
			st.insert(nN);
			N=nN;
			cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
  int a,b;
  cin>>a>>b;
  int count=0;
  for(int i=1;i<=a;i++){
    for(int j=1;j<=b;j++){
      int c=j/10;
      int d=j%10;
      if(c>=2&&d>=2&&i==c*d){
        count++;
      }
    }
  }
  cout<<count<<endl;

}


Measured memory_bytes: 256
from heapq import heappop, heappush

x,y,z,k = map(int, input().split())
abc = [sorted(list(map(int, input().split())), reverse=True) for i in range(3)]
heap = [[-sum(abc[i][0] for i in range(3)), (0,0,0)]]


cnt = 0
used = set()
while cnt < k:
    score, (a,b,c) = heappop(heap)
    if (a,b,c) in used:
        continue
    print(-score)
    used.add((a,b,c))
    cnt += 1
    for i in range(3):
        na = a+int(i==0)
        nb = b+int(i==1)
        nc = c+int(i==2)
        if 0<=na<x and 0<=nb<y and 0<=nc<z:
            nscore = 0
            for ind, j in enumerate([na,nb,nc]):
                nscore -= abc[ind][j]
            heappush(heap,[nscore, (na,nb,nc)])


Measured memory_bytes: 4708
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
int n;

int main()
{
    cin>>n;
    if (n%2==0)
    {
        cout<<n*(n-2)/2<<endl;
        for (int i=1; i<=n; ++i)
            for (int j=1; j<=n; ++j)
                if (i<j && i+j!=n+1)
                {
                    cout<<i<<' '<<j<<endl;
                }
    }else
    {
        cout<<n-1+(n-1)*(n-3)/2<<endl;
        for (int i=1; i<=n-1; ++i)
            for (int j=1; j<=n-1; ++j)
                if (i<j && i+j!=n)
                {
                    cout<<i<<' '<<j<<endl;
                }
        for (int i=1; i<=n-1; ++i)
            cout<<i<<' '<<n<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}


int main(){
    ll k,a,b;
    cin >> k >> a >> b;
    for (ll i=a;i<=b;i++){
        if (i%k==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef long double ld;
using namespace std;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    vector<int> d(m - 1);
    for(int i = 0; i < m; i++)
    {
        cin >> x[i];
    }
    if(m == 1)
    {
        cout << 0;
        return 0;
    }
    sort(x.begin(), x.end());
    for(int i = 0; i < m - 1; i++)
    {
        d[i] = abs(x[i + 1] - x[i]);
    }
    sort(d.begin(), d.end());
    int ans = 0;
    for(int i = 0; i < m - n; i++)
    {
        ans += d[i];
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INF = 2147483647;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	ll h, w;
	cin >> h >> w;
	if (h == 1 && w == 1) cout << 1 << endl;
	else if (h == 1) cout << w - 2 << endl;
	else if (w == 1) cout << h - 2 << endl;
	else cout << h*w - 2 * (h + w) + 4 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int L, R, d;
	cin >> L >> R >> d;

	int ans = 0;
	for (int i = L; i <= R; i++) {
		if (i % d == 0)
			ans++;
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
    int n; cin >> n;
    set<string> S;
    for (int i = 0; i < n; ++i) {
        string s; cin >> s;
        S.insert(s);
    }
    cout << S.size() << endl;
    return 0;
}


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

const int mod = 998244353;
typedef long long LL;
void reduce(int & x) { x += x >> 31 & mod; }
int mul(int a, int b) { return (LL) a * b % mod; }
int fastpow(int a, int b, int res = 1) {
	for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a);
	return res;
}
int remod(LL x) { x %= mod; return x + (x >> 63 & mod); }
const int MAXN = 1 << 18;
int n, A[MAXN], tar[MAXN];
void FWT(int * A, int typ) {
	const int U = 1 << n;
	for (int mid = 1; mid != U; mid <<= 1)
		for (int k = 0; k != U; k += mid << 1)
			for (int l = 0; l != mid; ++l) {
				const int X = A[l + k], Y = A[l + k + mid];
				reduce(A[l + k] += Y - mod);
				reduce(A[l + k + mid] = X - Y);
			}
	if (typ == -1) {
		const int liminv = fastpow(U, mod - 2);
		for (int i = 0; i != U; ++i) A[i] = mul(A[i], liminv);
	}
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	const int U = 1 << n;
	tar[0] = U;
	for (int i = 0; i != U; ++i) reduce(tar[i] -= 1);
	for (int i = 0; i != U; ++i) std::cin >> A[i];
	int sa = fastpow(std::accumulate(A, A + U, 0ll) % mod, mod - 2);
	for (int i = 0; i != U; ++i) A[i] = mul(A[i], sa);
	reduce(A[0] -= 1);
	FWT(A, 1); FWT(tar, 1);
	for (int i = 0; i != U; ++i)
		A[i] = fastpow(A[i], mod - 2, tar[i]);
	FWT(A, -1);
	for (int i = U - 1; ~i; --i) reduce(A[i] -= A[0]);
	for (int i = 0; i != U; ++i)
		std::cout << A[i] << '\n';
	return 0;
}


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

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

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

    int max = 0;
    int id = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] > max) {
            max = p[i];
            id = i;
        }
    }

    int a = 0;
    for (int i = 0; i < n; i++) {
        if (i == id) {
            a += p[i] / 2;
        } else {
            a += p[i];
        }
    }

    cout << a << endl;
}

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

int main(){
    string S; cin >> S;
    int ans = 0;
    
    if (S.find("RRR") != string::npos) {
        ans = 3;
    }else if(S.find("RR") != string::npos){
        ans = 2;
    }else if(S.find("R") != string::npos){
        ans = 1;
    }

    cout << ans << endl;
}



Measured memory_bytes: 3620
n, q = map(int, input().split())

s = list()
process = 0
t = list()
for i in range(n):
    name, time = map(str, input().split())
    s.append([name, int(time)])

flag = True
while s:
    diff = s[0][1] - q
    if diff <= 0:
        process += s[0][1]
        t.append([s[0][0], process])
        s.pop(0)
    else:
        process += q
        s.append([s[0][0], diff])
        s.pop(0)
for i in t:
    print(i[0], i[1])

Measured memory_bytes: 17616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
#define REP(i,a,b) \
for(int i=int(a);i<=int(b);i++)
#define DEP(i,a,b) \
for(int i=int(a);i>=int(b);i--)
#define TR(c, it) \
for (auto it = (c).begin(); it != (c).end(); it++)

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int T,n,m,x;
	cin>>n>>m;
	int a[m];
	int sum=0;
	REP(T,0,m-1)
	{
		cin>>x;
		sum+=x;
	}
    if(sum>n)
    	cout<<"-1";
    else
    	cout<<n-sum;
	return 0;
}


Measured memory_bytes: 3616
#include <array>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <utility>
#include <tuple>
#include <algorithm>
#include <limits>
#include <fstream>
#include <numeric>

namespace
{
	template<int N>
	std::array<int, N> GetValue(std::istream& stream)
	{
		std::string buf;
		std::getline(stream, buf);

		std::stringstream sstr(buf);
		std::array<int, N> retval;

		for (int i = 0; i < N; ++i)
		{
			std::getline(sstr, buf, ' ');
			retval[i] = std::stoi(buf);
		}

		return retval;
	}

	std::vector<int> GetValue(std::istream& stream, int num, char delim)
	{
		std::string buf;
		std::vector<int> retval;
		retval.reserve(num);

		for (int i = 0; i < num; ++i)
		{
			std::getline(stream, buf, delim);
			retval.push_back(std::stoi(buf));
		}

		return retval;
	}

	int GetValue(std::istream& stream)
	{
		int in;
		stream >> in;

		return in;
	}
}

int main(int argc, char* argv[])
{
	auto file = (argc == 1) ? std::ifstream() : std::ifstream(argv[1]);
	std::istream& stream = (argc == 1) ? std::cin : file;

	int num = GetValue<1>(stream)[0];
	std::vector<int> values = GetValue(stream, num, ' ');
	int count = 0;

	for (int i = 0; i < num - 1; ++i)
	{
		int min_index = i;

		for (int j = i; j < num - 1; ++j)
		{
			if (values[min_index] > values[j + 1])
			{
				min_index = j + 1;
			}
		}

		if (i != min_index)
		{
			++count;
			std::swap(values[i], values[min_index]);
		}
	}

	std::cout << values[0];
	for (size_t i = 1; i < values.size(); ++i)
	{
		std::cout << ' ' << values[i];
	}

	std::cout << '\n' << count << std::endl;
}



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

int main() {
int N,K,Q;
  cin >> N >> K >> Q;
  vector<int>A(Q);
  vector<int>B(N);
  vector<string>C(N);
  
  for(int i=0;i<N;i++){
   
    B.at(i)=B.at(i)+K-Q;
    C.at(i)="Yes";
    
  }
  for(int i=0;i<Q;i++){
     cin >> A.at(i);
    B.at(A.at(i)-1)++;
  }
  for(int i=0;i<N;i++){
    if(B.at(i)<=0){
      C.at(i)="No";
    }
    cout << C.at(i) <<endl;
  }

}



Measured memory_bytes: 6912
// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/


#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define inf 1000000000000000001
#define pii pair<int, int>
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll

void solve() {
    
    int n ,m;
    cin >> n >> m;
    map<int,int> pe;
    set<int> win;
    int penal = 0;
    for(int i = 0 ; i < m ; i++) {
        int p;
        string s;
        cin >> p >> s;
        if(s == "AC") {
            if(win.find(p) == win.end()) {
                win.insert(p);
                penal += pe[p];
            }
        }
        else {
            pe[p]++;
        }

    }
    cout << win.size() << ' ';
    cout << penal << endl;


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

Measured memory_bytes: 11264
class RollingHash2D:
    def __init__(self, s, n, m, b=1007, c=2009, mod=10**9 + 7):
        self.s = s
        self.n = n
        self.m = m
        self.b = b
        self.c = c
        self.mod = mod

        # preprocess
        self.hash_cs = [[0] * (self.m + 1) for _ in range(self.n + 1)]
        self.b_pow = [1] * (self.n + 1)  # base_pow[i] = base ** i
        self.c_pow = [1] * (self.m + 1)  # base_pow[i] = base ** i
        for i in range(self.n):
            self.b_pow[i + 1] = (self.b_pow[i] * self.b) % mod
        for i in range(self.m):
            self.c_pow[i + 1] = (self.c_pow[i] * self.c) % mod

        for i in range(self.n):
            for j in range(self.m):
                self.hash_cs[i + 1][j + 1] = \
                    self.hash_cs[i + 1][j] * self.c \
                    + self.hash_cs[i][j + 1] * self.b \
                    - self.hash_cs[i][j] * self.b * self.c \
                    + self.s[i][j]
                self.hash_cs[i + 1][j + 1] %= self.mod

    def calc_rolling_hash(self, il: int, ir: int, jl: int, jr: int) -> int:
        hash_val = \
            self.hash_cs[ir][jr] \
             - self.hash_cs[ir][jl] * self.c_pow[jr-jl] \
             - self.hash_cs[il][jr] * self.b_pow[ir-il] \
             + self.hash_cs[il][jl] * self.b_pow[ir-il] * self.c_pow[jr-jl]
        hash_val %= self.mod
        return hash_val

    def calc_hash(self, t, nt, mt):
        h = 0
        for i in range(nt):
            for j in range(mt):
                h += t[i][j] * self.b_pow[nt - i - 1] * self.c_pow[mt - j - 1]
                h %= self.mod
        return h


n, m = map(int, input().split())
a = [list(map(ord, list(input()))) for _ in range(n)]
b = [list(map(ord, list(input()))) for _ in range(m)]

rh = RollingHash2D(a, n, n)
b_hash = rh.calc_hash(b, m, m)
flag = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        if rh.calc_rolling_hash(i, i + m, j, j + m) == b_hash:
            flag = True
            break
    if flag:
        break

ans = 'Yes' if flag else 'No'
print(ans)


Measured memory_bytes: 39664
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(int argc,char** argv){
  int n;
  cin >> n;
  int v[n],c[n];
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  for(int i = 0; i < n; i++){
    cin >> c[i];
  }
  long long ret = 0;
  for(int i = 0; i < n; i++){
    if(v[i] > c[i]){
      ret += v[i] - c[i];
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifndef DBG
#define dbg(...)
#else
#define dbg(...) {cerr << "\033[1;96m"; ostream& cout = cerr; \
(void)(cout); __VA_ARGS__; cerr << "\033[0m";} 
#endif
#define bgn(...) begin(__VA_ARGS__)
#define rsz(...) resize(__VA_ARGS__)
#define emp(...) emplace_back(__VA_ARGS__)
#define psh(...) push_back(__VA_ARGS__)
#define ddmp(...) dbg(dmp(__VA_ARGS__))
#define prt(...) print(cout, __VA_ARGS__)
#define dprt(...) dbg(print(cerr, __VA_ARGS__))
#define dmp(...) print(cerr, #__VA_ARGS__, '=', __VA_ARGS__)
#define all(...) bgn(__VA_ARGS__), end(__VA_ARGS__)
#define siz(...) static_cast< int >((__VA_ARGS__).size())
using namespace std; using ll = long long;
template< typename... t > using V = vector< t... >;
template< typename... t > using outit = ostream_iterator< t... >;
template< typename t > void print(ostream& os, const t& a)
{os << a <<  '\n';} template< typename t, typename... v >
void print(ostream& os, const t& a, v&&... b){os << a << ' '; print(os, b...);}

int foo(int v)
{
    int s = 0;
    while (v > 0)
        s += v % 10, v /= 10;
    return s;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int res = 1e9;
    
    int n; cin >> n;

    for (int i = 1; i < n; ++i)
        res = min(res, foo(i) + foo(n - i));

    prt(res);

}

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

signed main() {
  int N;
  cin >> N;
  
  vector<int> A(3*N);
  for( int i = 0; i < 3*N; i++ ) cin >> A.at(i);
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  
  int ans = 0;
  for( int i = 0; i < 3*N-N; i++ ){
    if( i % 2 == 1 ) ans += A.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560