akhauriyash/Code-Regression huggingface dataset:
n, q = gets.split.map(&:to_i)
s = gets.chomp.chars
spells = Array.new(q) { gets.chomp.split }

s = ["@"] + s + ["@"]

# i番目（先頭は1）のゴーレムの最終位置
query = ->i {
  spells.each do |t, d|
    if t == s[i]
      d == "L" ? i -= 1 : i += 1
    end
  end
  i
}

hi = (0..n + 1).bsearch { |i| query[i] == n + 1 } # 右に落ちる
lo = n + 1 - (0..n + 1).bsearch { |i| query[n + 1 - i] == 0 } # 左に落ちる

ans = hi - 1 - lo
puts ans

Measured memory_bytes: 79200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	vector<int> cnt(9,0);
	int n;
	cin>>n;
	rep(i,n){
		int a;
		cin>>a;
		chmin(a,3200);
		cnt[a/400]++;
	}
	int ans=0;
	rep(i,8){
		if(cnt[i]) ans++;
	}
	cout<<max(1,ans)<<' '<<ans+cnt[8]<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#define int long long
typedef long long ll;
const int Maxn=100000;
ll n;
int x,m;
int t;
int a[Maxn+5];
int vis[Maxn+5];
signed main(){
	scanf("%lld%lld%lld",&n,&x,&m);
	a[1]=x;
	vis[x]=1;
	for(int i=2;;i++){
		a[i]=1ll*a[i-1]*a[i-1]%m;
		if(vis[a[i]]){
			t=i;
			break;
		}
		vis[a[i]]=i;
	}
	int sum=0;
	for(int i=1;i<vis[a[t]];i++){
		sum+=a[i];
	}
	n-=vis[a[t]]-1;
	int len=t-vis[a[t]];
	int s=0;
	for(int i=vis[a[t]];i<t;i++){
		s+=a[i];
	}
	sum=(sum+1ll*(n/len)*s);
	int last=n%len;
	for(int i=vis[a[t]];last>0;i++,last--){
		sum+=a[i];
	}
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 2904
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	s = readline()|>chomp
	flg = 0
	for i in 2:4
		if s[i] == s[i-1]
			flg = 1
			break
		end
	end
	println(flg==0?"Good":"Bad")
end

main()

Measured memory_bytes: 167388
#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>;

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
inline ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

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

  vector<ll> T(N);
  rep(i, N) { cin >> T.at(i); }
  ll ans = T[0];
  rep(i, N - 1) {ans = lcm(ans, T[i + 1]);}
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

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

using namespace std;

int n, m;
int x[30];

int main(){
    scanf("%d%d", &n, &m);
    rep(i, n){
        int k;
        scanf("%d", &k);
        rep(j, k){
            int a;
            scanf("%d", &a);
            ++x[a-1];
        }
    }
    int ans = 0;
    rep(i, m){
        ans += (x[i] == n);
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 128
from collections import deque
N, M, P = map(int, input().split())
G = [[] for i in range(N)]
RG = [[] for i in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    G[a-1].append((b-1, P-c))
    RG[b-1].append((a-1, P-c))

def chk(s, G):
    P = [0]*N
    que = deque([s])
    used = [0]*N
    used[s] = 1
    while que:
        v = que.popleft()
        P[v] = 1
        for w, c in G[v]:
            if used[w]:
                continue
            que.append(w)
            used[w] = 1
    return P
P0 = chk(0, G); P1 = chk(N-1, RG)
I = [i for i in range(N) if P0[i] == P1[i] == 1]

dist = [10**18]*N
dist[0] = 0
L = len(I)
for i in range(L+1):
    update = 0
    for v in I:
        d = dist[v]
        for w, c in G[v]:
            if d + c < dist[w]:
                dist[w] = d + c
                update = 1
    if not update:
        break
else:
    print("-1")
    exit(0)

print(max(-dist[N-1], 0))

Measured memory_bytes: 53464
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] a = new int[N];
        HashMap<Integer, Integer> count = new HashMap<>();
        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt();
            int c = count.getOrDefault(a[i], 0);
            count.put(a[i], ++c);
        }
        long allpair = 0;
        for (int i : count.values()) {
            if (i > 0) {
                allpair += (long) i * ((long) i - 1) / 2;
            }
        }
        for (int i = 0; i < N; i++) {
            int num = a[i];
            long ans = allpair;
            if (count.get(num) > 1) {
                ans -= (count.get(num) - 1);
            }
            System.out.println(ans);
        }
    }
}

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

int main(){
  int n; cin>>n;
  long long mod=1e9+7;

  if(n==1)cout<<1<<endl;
  else{
    vector<int> p={2};
    for(int i=3; i<=1000; i+=2){
      bool flg=true;
      for(int j=2; j<=sqrt(i); ++j){
        if(i%j==0){flg=false; break;}
      }
      if(flg)p.push_back(i);
    }
    int x=p.size();
    vector<long long> qq(x,1);
    long long ans=1LL;

    for(int m=2; m<=n; ++m){
      vector<long long> q(x,0);
      int k=m;
      for(int i=0; i<x; ++i){
        while(k!=1){
          if(k%p[i]!=0)break;
          if(k%p[i]==0){++q[i]; k/=p[i];}
        }
      }
      for(int i=0; i<x; ++i)qq[i]+=q[i];
    }
    
    for(int i=0; i<x; ++i){
      ans=ans*qq[i];
      ans%=mod;
    } 
    cout<<ans<<endl;
  }
}


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

int main() {
  int num, alice = 0, bob = 0;
  cin >> num;
  vector<int> vec(num);
  
  for(int i = 0; i < num; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for(int i = 0; i < num; i++){
    if(i%2 == 0) alice += vec.at(i);
    if(i%2 == 1) bob += vec.at(i);
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 256
# include<iostream>
using namespace std;
static const int MAX = 100;

void output(int A[],int N){
    for(int i=0;i<N;i++){
        cout << A[i];
        if(i == N-1){
            cout << endl;
        }else{
            cout << " ";
        }
    }
}

int bubbleSort(int A[],int N){
    int flag,temp,count;
    count =0;
    flag = 1;
    while(flag){
        flag = 0;
        for(int j=N-1;j>0;j--){
            if(A[j]<A[j-1]){
                temp = A[j];
                A[j] = A[j-1];
                A[j-1] = temp;
                flag =1;
                count++;
            }
        }
    }
    return count;
}

int main(){
    int N,count;
    int A[MAX];
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    count = bubbleSort(A,N);
    output(A,N);
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 998244353;
Int INF = 1e18;
double EPS = 0.00000001;

int main() {
    Int n;
    cin >> n;
    double x = 0.0;
    for (Int i = 0; i < n; i++) {
        double y;
        cin >> y;
        x += 1.0 / y;
    }
    printf("%.12lf\n", 1.0 / x);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by dezhonger on 2019/4/13
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = scanner.nextInt();

        int max = Integer.MIN_VALUE;
        int r = 0;
        for (int i = 0; i < n ;i++) {
            max = Math.max(max, a[i]);
            if (max == a[i]) r++;
        }
        System.out.println(r);
    }
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int n;
int head[N],ver[N],nxt[N],tot;
void add(int a,int b)
{
    tot++;nxt[tot]=head[a];head[a]=tot;ver[tot]=b;return ;
}
int f[N];
vector<int>v[N];
bool cmp(int x,int y)
{
    return x>y;
}
void dfs(int x)
{
    for(int i=head[x];i;i=nxt[i])
    {
        dfs(ver[i]);
        v[x].push_back(f[ver[i]]);
    }
    sort(v[x].begin(),v[x].end(),cmp);
    for(int i=0;i<v[x].size();i++)
    {
        f[x]=max(f[x],i+v[x][i]+1);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
    {
        int tmp;scanf("%d",&tmp);
        add(tmp,i);
    }
    dfs(1);
   // cout<<f[2]<<endl;
    cout<<f[1]<<endl;
    return 0;
}


Measured memory_bytes: 14976
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#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>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

vector< vector<int> > a(9);
vector<bool> used(9, false);
int n;
int answer;

void dfs(int p) { 
    int ret = 0;
    bool flag = true;
    for(int i=1;i<=n;i++) {
        if(!used[i]) flag = false;
    }
    //if(flag) return 1;
    if(flag) answer++;
    for(int i=0;i<a[p].size();i++) {
        if(!used[a[p][i]]) {
            used[a[p][i]] = true;
            //ret += dfs(a[p][i]);
            dfs(a[p][i]);
            used[a[p][i]] = false;
        }
    }
    //return ret;
}
int main(){
    int m;
    answer = 0;
    cin >> n >> m;
    for(int i=0;i<m;i++) {
        int ai, bi;
        cin >> ai >> bi;
        a[ai].push_back(bi);
        a[bi].push_back(ai);
    }
    int ans = 0;
    for(int i=1;i<=1;i++) {
        if(!a[i].empty()) {
            used[i] = true;
            //ans += dfs(i);
            dfs(i);
            for(int j=0;j<used.size();j++) used[j]=false;
        }
    }
    cout << answer<< endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()

const int mod=1e9+7;


int main(){
    int h,w,k;
    cin>>h>>w>>k;
    if(w==1){
        cout<<1<<endl;
        return 0;
    }
    vector<int> p(w,0),q(w);
    p[0]=1;
    rep(i,h){
        rep(j,w) q[j]=p[j];
        rep(j,w) p[j]=0;
        rep(j,1<<(w-1)){
            vector<int> mar(w-1,0);
            bool ok=true;
            rep(k,w-1){
                if(j>>k&1) mar[k]=1;
            }
            rep(k,w-2){
                if(mar[k]==1 && mar[k+1]==1) ok=false;
            }
            if(!ok) continue;
            rep(k,w-1){
                if(mar[k]==1){
                    p[k]+=q[k+1];
                    p[k]%=mod;
                    p[k+1]+=q[k];
                    p[k+1]%=mod;
                }
            }
            rep(k,w){
                if(k==0){
                    if(mar[0]==0) p[0]+=q[0];
                }
                else if(k==w-1){
                    if(mar[w-2]==0) p[w-1]+=q[w-1];
                }
                else{
                    if(mar[k-1]==0 && mar[k]==0) p[k]+=q[k];
                }
            }
            rep(k,w) p[k]%=mod;
        }
    }
    cout<<p[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

void dfs(ll k,ll pts,ll n,vector<vector<ll> > &G,vector<ll> &cnt,vector<ll> &ans,vector<bool> &is_visited){
    ans[k] = pts;

    rep(i,0,G[k].size()){
        if(!is_visited[G[k][i]]){
            is_visited[G[k][i]] = true;
            dfs(G[k][i],pts+cnt[G[k][i]],n,G,cnt,ans,is_visited);
        }
    }

    return;
}

int main(){
    ll n,q;
    cin >> n >> q;
    vector<ll> ans(n);
    vector<ll> cnt(n);
    vector<bool> is_visited(n);
    vector<vector<ll> > G(n);

    fill(is_visited.begin(),is_visited.end(),false);
    fill(cnt.begin(),cnt.end(),0);

    rep(i,0,n-1){
        ll a,b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }    
    
    rep(i,0,q){
        ll p,x;
        cin >> p >> x;
        cnt[p-1] += x;
    }

    is_visited[0] = true;
    dfs(0,cnt[0],n,G,cnt,ans,is_visited);

    rep(i,0,n){
        cout << ans[i] << (i-n-1?" ":"");
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 38400
import java.util.*;

public class Main{
	public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
	    int x=sc.nextInt()/200;
	    int ans=0;
	     switch(x) {
	     case 2: 
	    	 ans=8;
	    	 break;
	     case 3:
	    	 ans=7;
	    	 break;
	     case 4:
	    	 ans=6;
	    	 break;
	     case 5:
	    	 ans=5;
	    	 break;
	     case 6:
	    	 ans=4;
	    	 break;
	     case 7:
	    	 ans=3;
	    	 break;
	     case 8:
	    	 ans=2;
	    	 break;
	     case 9:
	    	 ans=1;
	    	 break;
	    	 
	     }
	   System.out.println(ans);

	    
	}
}


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

int main() {
    int n;
    cin >> n;
    long long x, y, m, z;
    vector<vector<long long>> a(2, vector<long long>(n));
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        a[0][i] = x+y;
        a[1][i] = x-y;
    }
    long long ans = 0;
    for (int i =0; i < 2; i++) {
        m = *min_element(a[i].begin(), a[i].end());
        z = *max_element(a[i].begin(), a[i].end());
        ans = max(ans, z-m);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8028
#include<stdio.h>
#include<stdbool.h>

int main(void){

	int N, M;
	int H[100001];
	int A[100001];
	int B[100001];
	bool t[100001];
	int ans = 0;

	scanf("%d %d", &N, &M);
	for(int i = 0; i < N; i++){
		scanf("%d", &H[i]);
	}
	for(int i = 0; i < M; i++){
		scanf("%d %d", &A[i], &B[i]);
	}

	for(int i = 0; i < N; i++){
		t[i] = true;
	}




	for(int i = 0; i < M; i++){
		if(H[A[i] - 1] <= H[B[i] - 1]){
			t[A[i] - 1] = false;
		}
		if(H[A[i] - 1] >= H[B[i] - 1])
			t[B[i] - 1] = false;
	}

	for(int i = 0; i < N; i++){
		if(t[i])
			ans++;
	}

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

	return 0;

}

Measured memory_bytes: 2972
#include <iostream>
#include <list>
#include <algorithm>

using namespace std;
int main() {
	int n;
	cin >> n;
	list<int> links;
	string command;
	int key;
	for(int i=0; i<n; i++){
		cin >> command;
		if(command[0] == 'i'){
			cin >> key;
			links.push_front(key);
		}else if(command[0] == 'd'){
			if(command.length()>6){
				if(command[6] == 'F'){
					links.pop_front();
				}else if(command[6] == 'L'){
					links.pop_back();
				}
			}else{
				cin >> key;
				for(list<int>::iterator it = links.begin(); it != links.end(); it++){
					if(*it == key){
						links.erase(it);
						break;
					}
				}
			}
		}
	}
	int i=0;
	for(list<int>::iterator it = links.begin(); it != links.end(); it++){
		if(i++) cout << " ";
		cout << *it;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 34472
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; //10^9
const ll MOD = 1e9 + 7;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }

int main()
{
    int k;
    cin >> k;
    ll ans = 0;

    for (ll a = 1; a <= k; a++)
    {
        for (ll b = 1; b <= k; b++)
        {
            for (ll c = 1; c <= k; c++)
            {
                ans += gcd(gcd(a, b), c);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define pan(i,n) for(int i=0;i<n;i++)
#define pans(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define vi vector<ll>
#define vl vector<ll>
#define pb push_back
#define INF 1000000007
#define PI 3.141592653
#define inf 100007
#define pll pair<ll,ll>
#define pii pair<int,int>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }


int main(){
    ll n,ans=1;
    cin>>n;
    string s;
    cin>>s;
    vi a(26,0);
    pan(i,n) a[s[i]-'a']++;
    pan(i,26){
        ans=((ans)%INF*(a[i]+1)%INF+INF)%INF;
    }
    cout<<(ans-1+INF)%INF;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> B(N - 1);
  
  for(int i = 0; i < N - 1; i++) cin >> B.at(i);
  
  int cnt = B.at(0) + B.at(N - 2);
  
  for(int i = 0; i < N - 2; i++) cnt += min(B.at(i), B.at(i + 1));
    
  cout << cnt << endl;
    
}

Measured memory_bytes: 256
//package hiougyf;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		 Scanner sc =new Scanner(System.in);
	int t=sc.nextInt();
	 int a=t%1000;
	 if(a!=0)System.out.println(1000-a);
	 else System.out.println("0");		
	}
	
}
	

Measured memory_bytes: 35716
//
// Created by Abhishek Bansal on 9/02/2020.
//
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

    char c; ll ans = 0;

    while (true) {
        scanf("%c", &c);
        if (c == '\n') break;
        ans += ((c-'0'))%9;
    }
    ans % 9 == 0? cout << "Yes" : cout << "No";
    return 0;
}

Measured memory_bytes: 3708
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		String s = sc.next();
		String t = sc.next();
		
		// 計算
		//int result = 0;
		
		
		// 出力
		for(int i = 0; i < n; i++){
		    System.out.print(s.charAt(i));
		    System.out.print(t.charAt(i));
		}
		//System.out.println(result);
	}
}




Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1e9+7;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

int main(){
    int N,M;
    cin>>N>>M;
    vpi temp(M);
    F0R(i,M){
        cin>>temp[i].first>>temp[i].second;
    }
    vi res(N,-1);
    F0R(i,M){
        if(res[temp[i].first-1]==-1){
            res[temp[i].first-1]=temp[i].second;
        }else if(res[temp[i].first-1]!=temp[i].second){
            cout<<-1<<endl;
            return 0;
        }
    }
    F0R(i,N){
        if(res[i]==-1&&i!=0){
            res[i]=0;
        }
        if(res[0]==0&&N>1){
            cout<<-1<<endl;
            return 0;
        }
        if(i==0&&N>1){
            if(res[i]==-1){
                res[i]=1;
            }
        }else if(i==0&&N==1){
            if(res[i]==-1){
                res[i]=0;
            }
        }
    }
    cout<<endl;
    int ans=0;
    F0Rd(i,N){
        ans+=res[i]*((int)(pow(10,N-1-i)+0.5));
    }
    cout<<ans<<endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int c = 0;
  bool isFailed = 0;
  while (1) {
    for (int i = 0; i < N; i++) {
      if (A.at(i) % 2 != 0 | A.at(i) == 0) {
        isFailed = 1;
        break;
      }
      A.at(i) /= 2;
    }
    if (isFailed) {
      break;
    }
    c++;
  }
  cout << c << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, c = 0;
	string s;
	cin >> n >> s;
	for (auto ch : s) {
		if (ch == 'R') c++;
	}

	if (c > n - c) cout << "Yes\n";
	else cout << "No\n";


	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  char s[3];
  char t[3];
  
  scanf("%s", s);
  scanf("%s", t);
  int count = 0;
  for(int i; i<3; i++){
    if(s[i]==t[i])count++;
  }
  printf("%d", count);

  return 0;
}

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

int main() {
std::cout<<std::fixed<<std::setprecision(6);
	double a, b, x;
	cin >> a >> b >> x;
	if (a*a*b/2>x)//水が少ない
	{
		double t = x / a / b * 2;
		cout << acos(t / sqrt(t * t + b * b))*180/3.1415926535;
	}
	else {
		double t = (a * a * b - x) / a / a * 2;

		cout << 90-acos(t / sqrt(t * t +a * a)) * 180 / 3.1415926535;
	}
}

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

int main(){
	// sengen
	int n,x,t;
	// nyuryoku
	cin >> n >> x >> t;
	// keisan
	int multi = n/x;
	if(n%x != 0){
		multi++;
	}
	// syutsuryoku
	cout << t*multi << endl;
}

Measured memory_bytes: 3628
n = $stdin.read.split("\n")
s = n[0]
w = n[1].to_i

i = w - 1
result = [s[0]]
while true
  if i+1 >= s.length - 1
    result << s[i+1]
    break
  end
  result << s[i+1]
  i+=w
end
puts result.join

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

struct Dice {
  int s[6];
  void turnN() {
    int tmp = s[0];
    s[0] = s[1]; s[1] = s[5]; s[5] = s[4]; s[4] = tmp;
  }
  void turnS() {
    int tmp = s[0];
    s[0] = s[4]; s[4] = s[5]; s[5] = s[1]; s[1] = tmp;
  }
  void turnW() {
    int tmp = s[0];
    s[0] = s[2]; s[2] = s[5]; s[5] = s[3]; s[3] = tmp;
  }
  void turnE() {
    int tmp = s[0];
    s[0] = s[3]; s[3] = s[5]; s[5] = s[2]; s[2] = tmp;
  }
};

int main() {
  
  Dice a; Dice b;
  
  for (int i = 0; i < 6; i++) cin >> a.s[i];
  
  for (int i = 0; i < 6; i++) cin >> b.s[i];
  
  for (int i = 0; i < 10000; i++) {
    
    int r = rand();
      
    if (r % 4 == 0) a.turnN();
    if (r % 4 == 1) a.turnS();
    if (r % 4 == 2) a.turnW();
    if (r % 4 == 3) a.turnE();
    
    for (int i = 0; i < 6; i++) {
      if (a.s[i] != b.s[i]) break;
      if (i == 5) {
        cout << "Yes" << endl;
        return 0;
      }
    }
    
  }
  
  cout << "No" << endl;
  
}


Measured memory_bytes: 3104
import java.util.Scanner;

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

		int i;
		double sum = 0;
		for(i = 0; i < n; i++) {
			sum += 1 / scan.nextDouble();
		}
		System.out.println(1 / sum);
	}
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

vector<string> day={"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main(){
    string S; 
    cin >> S;
    int res;
    for(int i=0; i<7; i++){
        if(S == day[i]){
            res=7-i;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3580
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main() {
  val (n, m) = readIs()
  val g = mutableMapOf<Int, MutableList<Int>>()
  repeat(m) {
    val (a, b) = readIs()
    g.computeIfAbsent(a) { mutableListOf() }.add(b)
    g.computeIfAbsent(b) { mutableListOf() }.add(a)
  }
  val s = ArrayDeque<Int>()
  val c = BooleanArray(n + 1)
  var x = 0
  for (i in 1..n) {
    if (c[i]) continue
    s.push(i)
    var y = 0
    while (s.isNotEmpty()) {
      val j = s.pop()
      if (c[j]) continue
      c[j] = true
      y++
      val h = g[j] ?: continue
      for (e in h) {
        s.push(e)
      }
    }
    x = max(x, y)
  }
  println(x)
}


Measured memory_bytes: 98328
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>

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

int main()
{
    int a, b;
    cin >> a >> b;

    int n = b - a;
    cout << n * (n + 1) / 2 - b << endl;
}


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

#pragma warning(disable:4996)
using namespace std;
using ld = long double;
struct Edge {
	int src;
	int dst;
	long long int A;
	long long int B;
};
struct aa {
	int now;
	long long int cost;
};
bool operator <(const aa&l, const aa&r) {
	return l.cost>r.cost;
}
long long int ce(long long int a,long long  int b) {
	return (a-1)/b+1;
}
int main() {
	int N;cin>>N;
	vector<int>valids(N,true),need_next(N),need_pre(N);
	vector<int>l_cnts(N);
	for (int i = 0; i < N; ++i) {
		int K;cin>>K;
		vector<int>v;
		for (int k = 0; k < K; ++k) {
			int a;cin>>a;
			a--;
			v.push_back(a);
			if (a == i) {
				valids[i]=false;
			}
			if (a == i - 1) {
				need_pre[i]=true;
			}
			else if (a == i + 1) {
				need_next[i]=true;
			}
		}
		sort(v.begin(),v.end());
		v.erase(unique(v.begin(),v.end()),v.end());
		auto it=lower_bound(v.begin(),v.end(),i);
			
	
		l_cnts[i]=it==v.begin()?30000000:i-*prev(it);
	}
	vector<int>dp(N+1);
	for (int i = 0; i < N; ++i) {

		dp[i + 1] = max(dp[i+1],dp[i]);
		if (!valids[i]) {
		}
		else {
			if (need_next[i]) {
				int k=i+1;
				int sum=1;
				while (true) {
					if (l_cnts[k]<=sum) {
						dp[k+1]=max(dp[k+1],dp[i]+sum);
						break;
					}
					else {
						if (valids[k]) {
							if (need_next[k]) {
								dp[k+1]=max(dp[k+1],dp[i]+sum);
								k++;
								sum++;
								continue;
							}
							else {
								if (l_cnts[k] > sum) {

									dp[k + 1] = max(dp[k + 1],dp[i]+ sum + 1);
								}
								else {
									assert(false);
									dp[k+1]=max(dp[k+1],dp[i]+sum);
								}
								break;
							}
						}
						else {
							dp[k+1]=max(dp[k+1],dp[i]+sum);
							break;
						}
					}
				}
			}
			else {
				dp[i+1]=max(dp[i]+1,dp[i+1]);
			}
		}
	}
	cout<<N-dp[N]<<endl;
	return 0;
}


Measured memory_bytes: 4728
function Main(input){
  var In = input.split(' ');
  var N = parseInt(In[0], 10);
  var D = parseInt(In[1], 10);
  var count = 0;
  for(var i = 0 ;i<=N; i += 2*D + 1){
    if(i == N){
      break;
    }
    count += 1;
  }
  
  console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

const ll MOD=1e9+7;

string S;
int cnt[26];

int main(){
 
cin>>S;

for(int i=0; i<S.size(); i++){
    int x=S[i]-'a';
    cnt[x]++;
}

for(int i=0; i<26; i++){
    if(cnt[i]>=2){
        puts("no"); return 0;
    }
}

puts("yes");

}

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

#define FOR(a, n, i) for(ll i = a; i < n; i++)
#define FORR(a, n, i) for(ll i = n - 1; i >= a; i--)
#define FORIT(a, n, it) for (auto it = a; it != n; it++)
#define FORE(e, container) for (auto e : container)
#define FORIN(n, v) vll v(n); FOR(0, n, i) cin >> v[i];
#define FORINP(n, v) vpl v(n); FOR(0, n, i) cin >> v[i].ff >> v[i].ss;
#define WHT(t) int t; cin >> t; while(t--)
#define REP(n, i) FOR(0, n, i)

#define bb begin()
#define ee end()
#define sz size()
#define ff first
#define ss second
#define pb push_back
#define in insert
#define ct count

#define MODF(x) (((x) % MOD) + MOD) % MOD
#define MP(a, b) make_pair(a, b)
#define ALL(container) container.bb, container.ee

using namespace std;

typedef long long ll;
typedef double dd;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvl; 
typedef vector<pll> vpl;
typedef set<ll> sll;
typedef set<pll> spl;
typedef map<ll, ll> mll;
typedef map<pll, ll> mpl;


const ll inf = numeric_limits<ll>::max(), 
         MAX = 1e6, 
         MOD = 1e9 + 7;

///////////////////////////////////////////////////////////
////////////////////    AUXILARY    ///////////////////////
///////////////////////////////////////////////////////////



///////////////////////////////////////////////////////////
//////////////////////    MAIN    /////////////////////////
///////////////////////////////////////////////////////////



int main() {
    ll n, m; cin >> n >> m;
    FORR(1, m/n + 1, i) {
        if (m % i == 0) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
  
  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s = r.readLine();
    String[] sl = s.split("[\\s]+");
    int a = Integer.parseInt(sl[0]);
    int b = Integer.parseInt(sl[1]);
    int z = 0;
    for(Integer i = a; i <= b; i++)
    {
      String ss = i.toString();
      if (ss.charAt(0) == ss.charAt(4) && ss.charAt(1) == ss.charAt(3))
      {
        z++;
      }
    }
    
    System.out.println(z);
  }
  
}

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

int main()
{
	string S, T;
	cin >> S;
	int N = S.size();
	for (int i = 0; i < N; i++) {
		if (S[i] != 'x') {
			T.push_back(S[i]);
		}
	}
	auto rT = T;
	reverse(rT.begin(), rT.end());
	if (T != rT) {
		cout << -1 << endl;
		return 0;
	}
	int sz = T.size();
	vector<int> f((sz + 1) / 2), b((sz + 1) / 2);
	int tmp = 0;
	for (int i = 0, j = 0; i < N && j < (sz + 1) / 2; i++) {
		if (S[i] == 'x') {
			tmp++;
		}
		else {
			f[j++] = tmp;
			tmp = 0;
		}
	}
	reverse(S.begin(), S.end());
	tmp = 0;
	for (int i = 0, j = 0; i < N && j < (sz + 1) / 2; i++) {
		if (S[i] == 'x') {
			tmp++;
		}
		else {
			b[j++] = tmp;
			tmp = 0;
		}
	}
	int res = 0;
	for (int i = 0; i < (sz + 1) / 2; i++) {
		res += max(f[i], b[i]) - min(f[i], b[i]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
"""
~~ Author : Bhaskar
~~ Dated : 07~06~2020
"""

import sys
from bisect import *
from math import floor,sqrt,ceil,factorial as F,gcd,pi,log
from itertools import chain,combinations,permutations,accumulate
from collections import Counter,defaultdict,OrderedDict,deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
mod = 1000000007
ch = "abcdefghijklmnopqrstuvwxyz"
lcm = lambda a,b : (a*b)//gcd(a,b)
setbit = lambda x : bin(x)[2:].count("1")

def solve():
    nn = int(sys.stdin.readline())
    a = list(map(int,sys.stdin.readline().split()))
    tra = Counter(a)
    s = dict()
    n = len(a)
    max_ele = INT_MIN
    for i in range(n):
        s[a[i]] = 1
        max_ele = max(max_ele,a[i])

    res = dict()
    for i in range(n):
        if a[i] !=0 :
            for j in range(a[i]*2,max_ele+1,a[i]):
                if j in s.keys():
                    res[j]  = 1
    # print(res)
    c =0
    for k,v in tra.items():
        if k not in res:
            if v == 1:
                c += 1


    print( c)

if __name__ == "__main__":
    # try:
    #     sys.stdin = open("input.txt","r")
    # except :
    #     pass
    solve()


Measured memory_bytes: 64660
#include <bits/stdc++.h>
#include <vector>
#include <cstdlib>

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; }

const long long INF = 1LL << 60;
const int MAX = 100000;
long long h[MAX], dp[MAX];

void solve() {
  int N;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> h[i];
    dp[i] = INF;
  }
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  for(int i=0; i<N-1;i++){
    // dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    if(i != N-2) chmin(dp[i+2], dp[i] + abs(h[i+2]-h[i]));
    chmin(dp[i+1], dp[i] + abs(h[i+1]-h[i]));
    // chmin(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
    // chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
  }
  cout << dp[N-1]<<endl;
  return;
}
 
int main() {
    solve();
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

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

int main(){

  ll n;cin>>n;
  ll a[n];rep(i,0,n)cin>>a[i];

  ll ans=0;
  rep(i,0,n){
    if(i+1==a[a[i]-1])ans++;
  }

  out(ans/2);


  return 0;
}


Measured memory_bytes: 1024
n = int(input())
s = [int(input()) for _ in range(n)]
sum = 0
for i in range(n):
    sum += s[i]
if sum % 10 != 0:
    print(sum)
else:
    s = sorted(s)
    for j in range(n):
        if s[j] % 10 != 0:
            sum = sum - s[j]
            print(sum)
            break
    if sum % 10 == 0:
        print(0)


Measured memory_bytes: 9072
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a := iScan()
	b := iScan()
	k := iScan()
	ans := []int{}
	for i := 1; i <= 100; i++ {
		if a%i == 0 && b%i == 0 {
			ans = append(ans, i)
		}
	}
	fmt.Println(ans[len(ans)-k])
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    ll n, k; cin >> n >> k;
    ll ans = 0;
    for(int b = 1; b <= n; b++){
        ans += max((b - k), 0LL) * (n / b) + max(n % b - k + 1, 0LL);
    }
    if(k == 0) ans = n * n;
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
n,m=map(int,input().split())
S=list(map(int,list(input())))
if m > n:
    m = n
idx = n
ans=[]
while idx > 0:
    for i in range(1,m+1)[::-1]:
        #print(i,idx,idx-i,S[idx-i])
        if S[idx-i] == 0 and idx-i>=0:
            idx -= i
            ans.append(i)
            break
    else:
        print(-1)
        sys.exit()
print(*ans[::-1])

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

using namespace std;
const int inf = 1e9;
int n, m;
struct node{
	int x, y;
};
node a[1010];
int dp[1010][5000] = {0};
void inin(){
	for (int i = 0; i <= m; i++){
		for (int j = 0; j <= (1<<n)-1; j++){
			dp[i][j] = inf;
		}
	}
}
int main(){
	scanf("%d%d",&n, &m);
	for (int i = 0; i < m; i++){
		scanf("%d", &a[i].x);
		int mm;
		scanf("%d", &mm);
		a[i].y = 0;
		for (int j = 1; j <= mm; j++) {
			int y;
			scanf("%d", &y);
			a[i].y |= (1<<(y-1));
		}
	}
	inin();
	dp[0][0] = 0;
	int r = (1<<n) - 1;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j <= r; j++) {
			if (dp[i][j] == inf) continue;
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			if ((j|a[i].y) >= j)
				dp[i+1][j|a[i].y] = min(dp[i+1][j|a[i].y], dp[i][j]+a[i].x);
		}
	}
	if (dp[m][r] == inf) dp[m][r] = -1;
	printf("%d\n", dp[m][r]);
	return 0;
}

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

class UnionFind {
private:
    VI par;
    VI sizes;

public:
    UnionFind(int n) : par(n), sizes(n, 1) {
        REP(i, n) par[i] = i;
    }

    int root(int x) {
        if(par[x] == x) return x;
        else return par[x] = this->root(par[x]);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        
        if(x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        
        par[y] = x;
        sizes[x] += sizes[y];
    }

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

    int size(int x) {
        return sizes[root(x)];
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    REP(i, m) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        uf.unite(x, y);
    }

    set<int> ans_root;
    REP(i, n) ans_root.insert(uf.root(i));
    cout << ans_root.size() << ln;
    return 0;
}


Measured memory_bytes: 5760
//AAAAAAAAAAAAAAAAAAAAAAAAAAgneyan
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define pb(x) push_back(x)
#define HAYAKU_HAYAKU ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    HAYAKU_HAYAKU; 
    int a;
    cin>>a;
    ll sum;
    sum = a + (a*a) + (a*a*a);
    cout<<sum;
}

Measured memory_bytes: 3620
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple{
    private int N;
    private int[] A;
    void Solve(){
        //input
        N = io.Int;
        A = new int[N];
        for(int i = 0; i < N; ++i) A[i] = io.Int;
        //cal
        var dict=new Dictionary<int,int>();
        foreach(var v in A){
            if(!dict.ContainsKey(v)) dict[v] = 0;
            dict[v]++;
        }
        var keyNum = dict.Keys.Count;
        var ans = ((keyNum & 1) == 1) ? keyNum : keyNum - 1;
        //ret
        Console.WriteLine(ans);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream(){
        Solve();
        io.writeFlush();
    }
}
class SimpleIO{
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[]{' '};
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
    public SimpleIO(){
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next(){
        if(BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while(st == "") st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int a, b;
	cin >> a >> b;
	string s = "", t = "";
	rep (i, a) s += ('0' + b);
	rep (i, b) t += ('0' + a);
	cout << min(s, t) << endl;

    return 0;
}



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

using namespace atcoder;

constexpr int N = 2e5;

int fl[N][20], fr[N][20];
int64_t sl[N][20], sr[N][20];

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    std::memset(fl, -1, sizeof(fl));
    std::memset(fr, -1, sizeof(fr));
    
    int n, k;
    std::cin >> n >> k;
    std::vector<int> x(n);
    for (int i = 0; i < n; ++i)
        std::cin >> x[i];
    
    for (int i = n - 1, j = i; x[i] - x[0] >= k; --i) {
        while (x[i] - x[j] < k)
            --j;
        fl[i][0] = j;
        sl[i][0] = j;
    }
    for (int i = 0, j = 0; x[n - 1] - x[i] >= k; ++i) {
        while (x[j] - x[i] < k)
            ++j;
        fr[i][0] = j;
        sr[i][0] = -j;
    }
    
    for (int i = 0; i < n; ++i) {
        for (int j = 1; j < 20; ++j) {
            int p = fl[i][j - 1];
            if (p == -1)
                break;
            fl[i][j] = fl[p][j - 1];
            sl[i][j] = sl[i][j - 1] + sl[p][j - 1];
        }
    }
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 1; j < 20; ++j) {
            int p = fr[i][j - 1];
            if (p == -1)
                break;
            fr[i][j] = fr[p][j - 1];
            sr[i][j] = sr[i][j - 1] + sr[p][j - 1];
        }
    }
    
    int q;
    std::cin >> q;
    while (q--) {
        int l, r;
        std::cin >> l >> r;
        --l;
        --r;
        int x = l, t = 1;
        int64_t ans = 0;
        for (int i = 19; i >= 0; --i) {
            if (fr[x][i] != -1 && fr[x][i] <= r) {
                ans += sr[x][i];
                x = fr[x][i];
                t += 1 << i;
            }
        }
        ans += 1ll * (r + 1) * t - l;
        x = r;
        for (int i = 19; i >= 0; --i) {
            if (fl[x][i] != -1 && fl[x][i] >= l) {
                ans += sl[x][i];
                x = fl[x][i];
            }
        }
        ans += r - 1ll * (l - 1) * t;
        ans -= 1ll * t * (r - l + 1);
        std::cout << ans << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 97716
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

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

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
const int MOD = 1000 * 1000 * 1000 + 7;

const int MAX = 111*1000;

PII A[MAX];

int main()
{
    int n;
    scanf("%d", &n);
    FOR(i, 0, n)
    {
        scanf("%d", &A[i].first);
        A[i].second = i;
    }
    sort(A, A + n);
    int ans = 0;
    FOR(i, 0, n)
    {
        if (!(i & 1) && (A[i].second & 1))
            ans++;
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    Map<String, Integer> map = new HashMap<>();

    for (int i = 0; i < N; i++) {
      String key = sc.next();
      map.computeIfPresent(key, (k, v) -> (v + 1));
      map.putIfAbsent(key, 1);
    }

    List<Integer> list = new ArrayList<>();
    map.entrySet().forEach(e -> list.add(e.getValue()));
    Collections.sort(list, Comparator.reverseOrder());
    int ans = list.stream().skip(K).mapToInt(n -> n).sum();
    System.out.println(ans);
    sc.close();
  }
}


Measured memory_bytes: 75312