akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

    int N, M;
    cin >> N >> M;
    auto K = make_vec<int>(N);
    auto A = make_vec<int>(N, 0);
    REP(i, N) {
        cin >> K.at(i);
        REP(j, K[i]) {
            int tmp;
            cin >> tmp;
            tmp--;
            A[i].push_back(tmp);
        }
    }

    auto food = make_vec<int>(M);
    REP(i, N) {
        REP(j, K[i]) { food[A[i][j]]++; }
    }
    int ans = 0;
    REP(i, M) {
        if (food[i] == N) {
            //cout << "i:" << i << " food[i]:" << food[i] << endl;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    multiset<ll>st;
    ll ans = 0;
    int n;
    cin >> n;
    f1 (n) {
        ll x;
        cin >> x;
        st.insert(x);
    }
    while (1) {
        ll mx = *st.rbegin();
        multiset<ll>newst;
        if (mx < n) break;
        st.erase(st.find(mx));
        ll t = (mx - mx % n) / n;
        for (auto &i : st) {
            newst.insert(i + t);
        }
        newst.insert(mx % n);
        st = newst;
        ans += t;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main { 
	public static void main(String[] args){
		String str;
                int[] arr = new int[5];
                int i, j, temp;
 
                // 5????????°??????????????????
                Scanner scan = new Scanner(System.in);
                str = scan.next();
                arr[0] = Integer.parseInt(str);
                str = scan.next();
                arr[1] = Integer.parseInt(str);
                str = scan.next();
                arr[2] = Integer.parseInt(str);
                str = scan.next();
                arr[3] = Integer.parseInt(str);
                str = scan.next();
                arr[4] = Integer.parseInt(str);

                // 
                if(arr[2]-arr[4]>=0 && arr[3]-arr[4]>=0 && arr[2]+arr[4]<=arr[0] && arr[3]+arr[4]<=arr[1])
                        System.out.println("Yes");
                else
                        System.out.println("No");
	}
}

Measured memory_bytes: 17320
implicit none
integer :: n
integer :: i
integer, allocatable :: a(:)
logical :: p

read *,n
allocate(a(n))
read *,(a(i),i=1,n)

p = .false.
do i = 1, n
   if (mod(a(i),2) == 1) then
      p = .not. p
   endif
enddo

if (p) then
   print '(a)','NO'
else
   print '(a)','YES'
endif
end

Measured memory_bytes: 1280
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#2311
#import numpy as np

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



def main():
	n,m=MI()
	li=[]
	for _ in range(m):
		a,b=MI()
		a-=1
		b-=1
		li.append([a,b])
	#print(li)

	ans=0

	for i in range(m):
		UF=UnionFind(n)
		for j in range(m):
			if i==j:
				continue
			UF.union(li[j][0],li[j][1])
		ans+=(UF.group_count()==1)
	print(m-ans)


if __name__ == "__main__":
	main()

Measured memory_bytes: 40944
#include<iostream>
using namespace std;
int main(void)
{
  int x,y;
  
  while(true)
    {
      cin>>x;
      cin>>y;
      if(x==0 && y==0)break;
      else if(x>y)
	{
	  int tmp=x;
	  x=y;
	  y=tmp;
	}
      cout<<x<<" "<<y<<endl;
    }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  rep (i, n) cin >> a[i] >> b[i];
  vector<pair<int, int>> ba(n);
  rep (i, n) ba[i] = {b[i], a[i]};
  sort(all(ba), greater<pair<int, int>>());
  set<int> still;
  rep (i, m) still.insert(still.end(), i);
  lint sum = 0;
  rep (i, n) {
    if (still.empty()) break;
    auto p = ba[i];
    if (m < p.second) continue;
    auto fitr = still.find(m - p.second), lbitr = still.lower_bound(m - p.second);
    if (fitr == still.end()) {
      if (lbitr != still.begin()) {
        fitr = --lbitr;
      } else {
        continue;
      }
    }
    still.erase(fitr);
    sum += p.first;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 6528
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
int n,m,cnt;
string s[1234];
int valid(int x,int y){
	if(x<0 || x>=n || y<0 || y>=m)
		return 0;
	if(s[x][y]=='#')
		cnt++;
	return 0;
}
int main(){
    std::ios::sync_with_stdio(false);
    //int n,m;
    int i,j,p,q;
    cin>>n>>m;
    rep(i,n){
    	cin>>s[i];
    }
    rep(i,n){
    	rep(j,m){
    		if(s[i][j]=='#'){

    			cout<<s[i][j];
    			continue;
    		}
    		cnt=0;
    		f(p,-1,2){
    			f(q,-1,2){
    				valid(i+p,j+q);
    			}
    		}
    		cout<<cnt;
    	}
    	cout<<endl;
    }
    
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
using namespace std;

using int64 = long long;

#define repeat(i, n) for (auto i = decltype(n)(); (i) < (n); (i)++)

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

  int n;
  cin >> n;
  string a, b, c;
  cin >> a >> b >> c;

  int ans = 0;
  repeat (i, n) {
    int counter[26] = {0};
    counter[a[i] - 'a']++;
    counter[b[i] - 'a']++;
    counter[c[i] - 'a']++;

    int max_c = 0;
    repeat (j, 26) if (counter[j] > counter[max_c]) max_c = j;

    char ch = (char)('a' + max_c);
    if (a[i] != ch) ans++;
    if (b[i] != ch) ans++;
    if (c[i] != ch) ans++;
  }
  cout << ans << endl;

  return 0;
}



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

ll sum[400000];

int main(){
    ll n,d,a; cin >> n >> d >> a;
    vector<pair<ll,ll>> v;
    for(ll i=0;i<n;i++){
        ll xx,hh; cin >> xx >> hh;
        v.push_back({xx,hh}); 
    }
    sort(v.begin(),v.end());
    vector<ll> x,h;
    for(ll i=0;i<n;i++){
        x.push_back(v[i].first);
        h.push_back(v[i].second);
    }
    //
    ll c=0;
    ll ans=0;
    for(ll i=0;i<n;i++){
        c+=sum[i];
        ll b=(h[i]-c)/a;
        if((h[i]-c)%a!=0) b++;
        if((h[i]-c)<=0) b=0;
        //cout << h[i]-c << endl;
        sum[i+1]+=b*a;
        ans+=b;
         
        ll ub=n,lb=0;
        while(ub-lb>1){
            ll mid=(ub+lb)/2;
            if(x[mid]>x[i]+d*2){
                ub=mid;
            }else{
                lb=mid;
            }
        }
        ll dd=lb;

        sum[dd+1]+=-b*a;
        //cout << sum[i] << " " << sum[i+1] << " " << sum[i+2] << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10476
#include <iostream>
using namespace std;
int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    if(a > b){
        int d = a;
        a = b;
        b = d;
    }
    if((a <= c) && (c <= b)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    A.sort()
    le, ri = A[-1], A[-1]
    # print(le, ri)
    from collections import deque
    A = deque(A[:N-1])
    ans = 0
    for i in range(N-1):
        cur = [abs(A[0] - le), abs(A[-1] - ri),
               abs(A[-1] - le), abs(A[0] - ri)]
        #print(le, ri, cur)
        if max(cur) == cur[0]:
            c = A.popleft()
            ans += abs(c - le)
            le = c
        elif max(cur) == cur[1]:
            c = A.pop()
            ans += abs(c - ri)
            ri = c
        elif max(cur) == cur[2]:
            c = A.pop()
            ans += abs(c - le)
            le = c
        else:
            c = A.popleft()
            ans += abs(c - ri)
            ri = c
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 58840
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value)
#define fillvector(v, value) fill((v).begin(), (v).end(), value)
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
    system("pause");
#endif
}
char s[5];

inline void solve()
{
    scanf("%s", s + 1);
    int ans = 0;
    if(s[1]=='R'&&s[2]=='R'&&s[3]=='R')
        ans = 3;
    else if((s[1]=='R' && s[2]=='R') || (s[2]=='R'&&s[3]=='R'))
        ans = 2;
    else if(s[1]=='S' && s[2]==s[1] && s[3]==s[1])
        ans = 0;
    else
        ans = 1;
    cout << ans << endl;
}

int main()
{
    TIME__START = clock();
    int Test = 1;
    // scanf("%d", &Test);
    while (Test--)
        solve();
    TIME__END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n, C, K; cin >> n >> C >> K;
    vi T(n); for(auto& e : T) cin >> e;

    sort(_all(T));
    int res = 0;
    int cur = -1;
    int cnt = 0;
    rep(i, n){
        int t = T[i];
        
        if(t <= cur and cur <= t + K and cnt < C){
            cnt++;
        }
        else {
            cur = t + K;
            cnt = 1;
            res++;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()	
{
	int n,sum=0;
	ll ans=0,b[5],c,d;
	string s;
	set<string>S[5];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		if(s[0]=='M')S[0].insert(s);
		else if(s[0]=='A')S[1].insert(s);
		else if(s[0]=='R')S[2].insert(s);
		else if(s[0]=='C')S[3].insert(s);
		else if(s[0]=='H')S[4].insert(s);
	}
	for(int i=0;i<5;i++)
	{
		if(S[i].size())sum++;
		b[i]=S[i].size();
	}
	if(sum<3)cout<<0<<endl;
	else
	{
		for(int bit=0;bit<(1<<5);bit++)
		{	
			c=1,d=0;
			for(int i=0;i<5;i++)
			{
				if(bit&(1<<i))
				{
					c*=b[i];
					d++;
				}
			}
			if(d==3)ans+=c;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 9600
W = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
S = input()
i = W.index(S) + 1
ans = 1
while W[i % len(W)] != 'SUN':
    i += 1
    ans+=1
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  ll N,K;

  cin>>N>>K;

  vector<pair<int,int>> ve;

  rep(i,N){
    int a,b;
    cin>>a>>b;
    ve.emplace_back(a,b);
  }

  SORT(ve);

  ll now=0;

  rep(i,N){
    now+=ve[i].second;
    if(now>=K){
      cout<< ve[i].first<<"\n";
      return;
    }
  }
}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 1400
#include<iostream>
#include<stdio.h>//printf("%.9f\n",*********);
#include<vector>//文字列.erase(n)
#include<algorithm>//next_permutation
#include<set>
#include<string>//char(小文字-32=大文字) to_string
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define str string
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int SED(int n) { //Sum of each digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {

	int n, m;
	cin >> n >> m;
	vint ans(n, 0);

	rep(i, m) {
		int a, b;
		cin >> a >> b;
		ans[a-1]++;
		ans[b-1]++;
	}

	rep(i, n) {
		cout << ans[i] << rt;
	}

	please AC;
}

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


int main(){
  vector<int> a(3);
  for(int i=0;i<3;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  if(a.at(0)==5&&a.at(1)==5&&a.at(2)==7){
    cout << "YES" << endl;
  }
  else{
    cout <<"NO" << endl;
  }
}


Measured memory_bytes: 256
/*
ID: jerrywcy
TASK: AtCoder ABC 105 Problem B
LINK: https://abc105.contest.atcoder.jp/tasks/abc105_b
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int n;
bool f[110];

int main()
{
	cin>>n;
	if (n<4){
		cout<<"No"<<endl;
		return 0;
	}
	int i,j;
	f[0]=1;
	for (i=4;i<=n;i++){
		if (f[i-4])f[i]=1;
	}
	for (i=7;i<=n;i++){
		if (f[i-7])f[i]=1;
	}
	
	if (f[n])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}



Measured memory_bytes: 256
use proconio::input;
fn main() {
    input!(n: usize, m: usize);
    let mut g: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..m {
        input!(a: usize, b: usize);
        g[a - 1].push(b - 1);
        g[b - 1].push(a - 1);
    }

    let res = bfs_dist(n, &g, 0);
    println!("Yes");
    for i in 1..n {
        println!("{}", res[i] + 1);
    }
}

//単一視点から目的のノードまでの最短距離、ただし全ての辺の重みが等しいグラフに限る
fn bfs_dist(n: usize, g: &Vec<Vec<usize>>, start: usize) -> Vec<usize> {
    use std::collections::VecDeque;
    let mut visit = vec![false; n];
    let mut q = VecDeque::new();
    let mut res = vec![0; n];

    //init
    visit[start] = true;
    q.push_back(start);

    while let Some(now) = q.pop_front() {
        for &e in &g[now] {
            if !visit[e] {
                res[e] = now;
                visit[e] = true;
                q.push_back(e);
            }
        }
    }
    res
}


Measured memory_bytes: 14384
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <iomanip>
using ll = long long;
using namespace std;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r) { return l.second < r.second; }
bool greaterPair(const ipair& l, const ipair& r) { return l.second > r.second; }

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define irep(i, n) for (int i = 0; i <= (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rirep(i, n) for (int i = n; i >= 0; --i)
int factorical(int n) {
	int sum = 1;
	for (int i = 1; i <= n; ++i)
	{
		sum *= i;
	}
	return sum;
}

vector<int> divisors(int n) {
	vector<int> res;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}
vector<ll> divisors_ll(ll n) {
	vector<ll> res;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}


void printVector(const vector<int>& vec) {
	for (int value : vec) {
		cout << value << " ";
	}
	cout << endl;
}

bool pal(string s) {
	int n = s.length() / 2;
			rep(i, n) {
			if (s[i] != s[s.length() - 1 - i]) return false;
		}
			return true;
}

int euclidean_gcd(int a, int b) {
	if (a < b) return euclidean_gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

vector <string> vec_sort_and_del(vector<string> s) {
	std::sort(s.begin(), s.end());
	s.erase(std::unique(s.begin(), s.end()), s.end());
	return s;
}

int main() {
	ll n, k, nk, ans;
	cin >> n >> k;
	nk = n % k;
	ans = k - nk;
	if (ans < 0)ans = 0;
	cout << min(ans, nk) << endl;
	return 0;
}




Measured memory_bytes: 256
# ABC 134, C -

n = int(input())

A = []
for i in range(n):
    A.append(int(input()))

B = sorted(A)



m = B[len(B)-1]
m_ind = A.index(m)

m2 = B[len(B)-2]
for i in range(n):
    if m != m2:
        if i == m_ind:
            print(m2)
        else:
            print(m)
    else:
        print(m)



Measured memory_bytes: 14108
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double N = sc.nextInt();
        double topM = 0;
        double topA = 0;
        double topR = 0;
        double topC = 0;
        double topH = 0;
        for (int i=0;i<N;i++){
            String name = sc.next();
            if (name.startsWith("M")){
                topM += 1;
            }else if (name.startsWith("A")){
                topA += 1;
            }else if (name.startsWith("R")){
                topR += 1;
            }else if (name.startsWith("C")){
                topC += 1;
            }else if (name.startsWith("H")){
                topH += 1;
            }
        }
        List<Double> names = new ArrayList<>();
        names.add(topM); names.add(topA);
        names.add(topR); names.add(topC);
        names.add(topH);
        double result = 0;
        for (int i=0;i<5;i++){
            for (int j=i+1;j<5;j++){
                for (int k=j+1;k<5;k++){
                    result += names.get(i) * names.get(j) * names.get(k);
                }
            }
        }
        System.out.printf("%.0f", result);
    }
}

Measured memory_bytes: 44040
#include <stdio.h>
#define N 100000
#define T 50000

main()
{

  int i,j;
  int A[N],B[T];
  int n,t,left,right,mid,key=0,f=0;
  
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&t);
  
  for(j = 0; j < t; j++){
    scanf("%d",&B[j]);
    
    left = 0;
    right = n;
    
    while(left < right){
      mid = (left + right)/2;
      
      if(B[j] == A[mid]){
	f++;
	break;
      }
      
      if(B[j] > A[mid]){
	left = mid + 1;
      }
      
      else if(B[j] < A[mid]){
	right = mid;
      }
    }
  }
  
  
  
  printf("%d\n",f);
  
  return 0;
  
}

Measured memory_bytes: 1184
from queue import Queue

n, m = map(int, input().split())
to = {}
for i in range(m):
    a, b = map(int, input().split())
    from_a = to.get(a, set())
    from_a.add(b)
    to[a] = from_a
    from_b = to.get(b, set())
    from_b.add(a)
    to[b] = from_b
ans = [0] * (n + 1)
ans[1] = 1
nx = Queue()
nx.put(1)
while not nx.empty():
    cur = nx.get()
    nxts = to.get(cur, [])
    for nxt in nxts:
        if ans[nxt] != 0:
            continue
        ans[nxt] = cur
        nx.put(nxt)
if 0 in ans[2:]:
    print('No')
else:
    print('Yes')
    [print(i) for i in ans[2:]]


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

pll A[30];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i].first;
    }
    REP(i, N) {
        cin >> A[i].second;
    }

    ll ans = 0;
    REP(b, pow(2LL, N)) {
        pll p(0, 0);
        REP(i, N) {
            if ((b >> i) & 1) {
                p.first += A[i].first;
                p.second += A[i].second;
            }
        }
        ans = std::max(ans, p.first - p.second);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
N, K = map(int, input().split())
A = list(map(int, input().split()))

p_score = 0
score = 0
tmp = []

for n in range(K-1, N):
    if n > K-1:
        score -= A[n-K]
        score += A[n]
        if score > p_score:
            print('Yes')
        else:
            print('No')
    else:
        tmp = A[n-(K-1):n+1]
        # print(tmp)
        score = sum(tmp)
    p_score = score


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

inline int ws (int n) {
	int s = 0;
	while (n) {
		++s;
		n /= 10;
	}
	return s;
}

int main () {
	int n, i, ans = 0;
	scanf ("%d", &n);
	for (i = 1; i <= n; ++i) {
		if (ws (i) & 1) ++ans;
	}
	printf ("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
#include<list>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<stack>
#include<iostream>

using namespace std;

int main()
{
 int n,a[105],swp,tmp,i,j,mn;
 while(scanf("%d",&n)==1)
 {
     for(i=0;i<n;i++)
     {
         scanf("%d",&a[i]);
     }
     swp=0;
     for(i=0;i<n-1;i++)
     {
         mn=i;
         for(j=i+1;j<n;j++)
         {
             if(a[j]<a[mn])
             {
                 mn=j;
             }
         }

         if(mn!=i)
         {
             swp++;
             swap(a[i],a[mn]);

         }
     }
     printf("%d",a[0]);

     for(i=1;i<=n-1;i++)
     {
         printf(" %d",a[i]);

     }
     printf("\n");
     printf("%d\n",swp);
 }
 return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define int long long
#define N 11
#define H (1e18)
#define W 76
using namespace std;
typedef pair<int,int> P;
const int INF = 1LL<<55;
const int mod = (1e9)+9;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
typedef vector<int> vec;
typedef vector<vec> mat;
int w,h,n;

mat mul(const mat &a,const mat &b){
  mat res(w,vec(w,0));
  for(int i=0;i<w;i++)
    for(int j=0;j<w;j++)
      for(int k=0;k<w;k++) res[i][j] = (res[i][j] + a[i][k]*b[k][j]%mod)%mod;
  
  return res;
}

vec calc(const mat &a,const vec &b){
  vec res(w,0);
  for(int i=0;i<w;i++)
    for(int j=0;j<w;j++) res[i] = (res[i] + b[j]*a[j][i]%mod)%mod;
  return res;
}

mat doubling(mat x,int y){
  mat res(w,vec(w,0));
  for(int i=0;i<w;i++) res[i][i] = 1;
  
  while(y){
    if(y%2) res = mul(res,x);
    y/=2;
    x = mul(x,x);
  }
  return res;
}


signed main(){
  int t = 0;
  while(1){
    cin>>w>>h>>n;
    if(w == 0 && h == 0 && n == 0) break;
    priority_queue <P,vector<P>,greater<P> > ng;
    int flg = 0 ;
    for(int i=0;i<n;i++){
      int x,y;
      cin>>x>>y;   x--,y--;
      flg |= (x == w-1) && (y == h-1);
      flg |= (x == 0) && (y == 0);
      if(y >= h) i--,n--;
      else if(y == 0) i--,n--;
      else ng.push(P(y,x));
    }
    ng.push(P(h-1,-1));
    
    vector<int> ans(w,0);   ans[0] = flg == 0;
    
    int height = 0;
    mat num(w,vec(w,0));
    for(int i=0;i<w;i++)
      for(int j=i-1;j<=i+1;j++)if(j>=0 && j<w) num[i][j] = 1;

    while(!ng.empty()){
      int nheight = ng.top().first;
      int d = nheight - height;
      mat res = doubling(num,d);
      ans = calc(res,ans);
      height = nheight;
      
      while(!ng.empty() && nheight == ng.top().first) {
        if(ng.top().second>=0) ans[ng.top().second] = 0; 
        ng.pop();
      }
    }
    
    assert(height == h-1);
    cout<<"Case "<<++t<<": "<<ans[w-1]<<endl;
  }
  return 0;
}

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

using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    int a;
    cin >> a;
    int z = (int) sqrt(a);
    int temp = z;
    while(a%temp)
        temp--;
    int b = a/temp;
    cout << temp + b - 2 << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
    long long int N, M;
    scanf("%lld %lld", &M, &N);
    int p, q;
    if(N == 1 && M == 1){
        printf("1\n");
    }else if(N == 1){
        printf("%lld\n", M - 2);
    }else if(M == 1){
        printf("%lld\n", N - 2);
    }else{
        printf("%lld\n", (M-2)*(N-2));
    }

    return 0;
}

//4角は4回, 上下左右は6回, それ以外は9回これが裏

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


int main(void) {
  int n;
  cin >> n;
  ll ans = 0;
  rep(i, n) {
    ll l, r;
    cin >> l >> r;
    ans = ans + r - l + 1;
  }

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

Measured memory_bytes: 3600
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int a, b, c;
	int lmin;

	scanf("%d %d %d", &a, &b, &c);

	lmin = a + b < b + c ? a + b : b + c;
	lmin = lmin < c + a ? lmin : c + a;

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

	return 0;
}

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

main () {
  int n, q;
  scanf("%d %d", &n, &q);

  char s[100000+1];
  scanf("%s", s);

  int ans[100000];
  ans[0] = 0;
  for (int i=1; s[i]; i++) {
    ans[i] = ans[i-1] + ((s[i-1] == 'A') && (s[i] == 'C'));
  }

  rep(i, q) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--; r--;
    printf("%d\n", ans[r] - (l ? ans[l] : 0));
  }

  return 0;
}


Measured memory_bytes: 1280
s = input()
n = len(s)
mod = 2019

cum = [0]*n
cum[n-1] = int(s[-1]) % mod
d = [1]*n
for i in range(n-1)[::-1]:
    d[i] = d[i+1]*10%mod

for i in range(0, n-1)[::-1]:
    a = int(s[i]) * d[i] % mod
    cum[i] = (cum[i+1]+a) % mod
cnt = [0]*mod

ans = 0
for i in cum[::-1]:
    ans += cnt[i]
    cnt[i] += 1
    if i == 0:
        ans += 1
print(ans)

Measured memory_bytes: 24940
#include <stdio.h>
int main(void)
{
  int n, p[20], i, count=0;
  
  scanf("%d", &n);
  for(i=0; i<n; i++)
    scanf("%d", &p[i]);
  
  for(i=1; i<n-1; i++){
    if(p[i-1]<p[i]&&p[i]<p[i+1])
      count++;
    else if(p[i-1]>p[i]&&p[i]>p[i+1])
      count++;
  }
  printf("%d", count);
  
  return 0;
}

Measured memory_bytes: 128
# ABC145B - Echo
def main():
    N = int(input())
    S = input().rstrip()
    if N % 2 == 1:
        flg = False
    else:
        flg = S[: N // 2] == S[N // 2 :]
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

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

int main() {
    int n;
    cin >> n;
    vector <int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i); 
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            cnt += vec.at(i) * vec.at(j);
        }
    }
    cout << cnt << endl;
    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn=1e6+10;
int main()
{
    string s;
    cin>>s;
    int a[100]={0};
    for(int i=0;i<3;i++){
        a[s[i]-'a']++;
    }
    if(a[0]==1 && a[1]==1 && a[2]==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 110
stack<char> st;

int main(){
	string str;
	cin >> str;
	while(!st.empty()) st.pop();
	for(int i=0;i<str.length();i++){
		if(str[i]=='C'&&st.empty()==1){
			st.push(str[i]);
		}
		else if(str[i]=='F'&&!st.empty()){
			if(st.top()=='C'){
				st.push(str[i]);
			}
		}
		if(st.size()==2) {
			cout << "Yes" << endl;
			break;
		}
	}
	if(st.size()!=2) cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lr = []
    for i in range(n):
        s, r = rl()
        lr.append((s, -int(r), i+1))
    lr.sort()
    for r in lr:
        print(r[2])



if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define ctoi(x) (x - '0')
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

int n, ans;
vi v(200010);
unordered_map<int, int> M;

int main() {
	fastio;
	cin >> n;
	FOR(i, n) {
		cin >> v[i + 1];
		M[v[i + 1]]++;
	}
	for (int i = 1; i <= n; i++) {
		int flag = 1;
		for (ll j = 1; j * j <= v[i]; j++) {
			if (v[i] % j == 0) {
				//v[i]/j, j
				if (j == v[i] && M[j] >= 2 || j != v[i] && M[j] >= 1 || v[i]/j == v[i] && M[v[i]/j] >= 2 || v[i]/j != v[i] && M[v[i]/j] >= 1) {
					flag = 0;
					break;
				}
			}
		}
		if (flag) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 32544
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return int(stdin.readline())

a = li()
b = li()
c = li()
d = li()
e = li()
k = li()
if e - a > k:
    print(":(")
else:
    print("Yay!")


Measured memory_bytes: 2940
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n,m;
	cin>>n>>m;
	vint v(n);
	rep(i,n) cin>>v[i];
	vint cnt(3*n+1);
	int geta = 2*n;
	vint p(n+1);
	rep(i,n){
		p[i+1] = i+1;
	}
	int ans = n;
	rep(i,n){
		cnt[p[v[i]]+geta]++;
		if(p[v[i]]>0&&cnt[p[v[i]]+geta]==1) ans--; 
		p[v[i]]--;
	}
	rep(i,m){
		// rep(j,3*n+1){
		// 	cout<<cnt[j]<<" ";
		// }
		// cout<<endl;
		int x,y;
		cin>>x>>y;
		x--;
		// cout<<"v[x] "<<v[x]<<" "<<p[v[x]]<<endl;
		p[v[x]]++;
		cnt[p[v[x]]+geta]--;
		if(p[v[x]]>0&&cnt[p[v[x]]+geta]==0) ans++;
		v[x] = y;
		// cout<<"y  "<<v[x]<<" "<<p[v[x]]<<endl;
		cnt[p[v[x]]+geta]++;
		if(p[v[x]]>0&&cnt[p[v[x]]+geta]==1) ans--;
		// ans += cnt[p[v[x]]+geta] > 1;
		p[v[x]]--;	
		cout<<ans<<endl;
	}
}


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

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

#define LL long long
#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define MID(l, r) (((l)+(r))>>1)

const int maxn = (int) 2e5 + 20;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const double eps = 1e-8;


template < typename T > inline void read(T &x)
{
    static bool f;
    static char ch;

    f = 0;
    x = 0;
    ch = getchar();

    while(ch < '0' || '9' < ch) {if(ch == '-') f = 1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = (x << 3) + (x << 1) + (ch & 15); ch = getchar();}

    if(f) x = -x;
}

LL gcd(LL a, LL b) {if(!b) return a; return gcd(b, a % b);}
LL fp(LL a, LL n, LL m = MOD) {LL res; for(res = 1; n; a = a * a % m, n >>= 1) if(n & 1) res = res * a % m; return res;}

int n, k;
int a[maxn];
set<int> s;

void work()
{
    cin >>n >>k;
    for(int i = 1; i <= n; i++) cin >>a[i];

    int sum = 0, flag = 0, ans = 1;

    for(int i = 2; i <= k; i++) sum += (a[i - 1] < a[i]);
    if(sum == k - 1) flag = 1;

    for(int i = 1; i <= k; i++) s.insert(a[i]);

    for(int i = k + 1; i <= n; i++)
    {
        s.insert(a[i]);
        sum += (a[i - 1] < a[i]);
        sum -= (a[i - k] < a[i - k + 1]);

        int pre = *s.begin();
        int bak = *s.rbegin();

//        cout <<pre <<" " <<bak <<" " <<sum <<endl;
        if(pre == a[i - k] && bak == a[i])
        {
            ;
        }
        else
        {
            if(sum == k - 1)
            {
                if(flag == 0)
                {
                    ans++;
                    flag = 1;
                }
            }
            else
            {
                ans++;
            }
        }

        s.erase(a[i - k]);
    }

    cout <<ans <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
#endif // yukihana0416

    int tc = 1;
//    read(tc);

    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 10368
### subroutines

def point(gls, ti, ops)
  win = glp = glm = 0

  for op in ops
    gli = gls[ti][op]
    glo = gls[op][ti]

    if gli > glo
      win += 3
    elsif gli == glo
      win += 1
    end

    glp += gli
    glm += glo
  end

  win * 10000 + (glp - glm + 32) * 100 + glp
end

def check_order(gls, tis)
  return [tis] if tis.length <= 1

  phash = {}

  for i in (0...tis.length)
    ti = tis[i]
    ops = tis.clone
    ops.delete_at(i)
    pt = point(gls, ti, ops)
    #p [tis[i], pt]

    phash[pt] = [] if phash[pt].nil?
    phash[pt] << ti
  end

  mtis = phash.keys.sort{|a, b| b <=> a}.map{|pt| [phash[pt]]}.inject(:+)
  return mtis if mtis.length == 1

  mtis.map{|tis0| check_order(gls, tis0)}.inject(:+)
end

### main

fact = [1]
(1..8).each{|n| fact[n] = n * fact[n - 1]}
#p fact

prbs = []
for k in (0..8)
  prbs[k] =
    Rational(fact[8], fact[k] * fact[8 - k]) *
    (Rational(1, 4) ** k) *
    (Rational(3, 4) ** (8 - k))
end
#p prbs
#p prbs.inject(:+)

n = gets.to_i

n.times do
  lines = []
  5.times do
    str = gets.strip
    line = []
    (0..4).each{|i| line[i] = str[5 * i, 4]}
    lines << line
  end
  #p lines

  teams = []
  thash = {}
  oid = nil

  for i in (0...4)
    team = lines[0][i + 1]
    teams << team
    thash[team] = i
    oid = i if team =~ /^\*/
  end
  #p teams
  #p thash
  #p oid

  gls = 4.times.map{4.times.map{nil}}
  ops = []

  for i in (0...4)
    for j in ((i + 1)...4)
      gl = lines[i + 1][j + 1]
      #p [i, j, wl]
      if gl[1] != '_'
        gls[i][j] = gl[1].to_i
        gls[j][i] = gl[3].to_i
      else
        ops[i] = j
        ops[j] = i
      end
    end
  end
  #p gls
  #p ops

  sump = 0

  for cnt in (0...9 ** 4)
    cnt0 = cnt
    scs = []
    for i in (0...4)
      scs << cnt0 % 9
      cnt0 /= 9
    end
    #p scs

    for i in (0...4)
      gls[i][ops[i]] = scs[i]
    end
    #p gls

    mtis = check_order(gls, (0...4).to_a)

    r0 = r1 = 0
    for tis in mtis
      r0 = r1
      r1 = r0 + tis.length

      if tis.include?(oid)
        break if r0 >= 2

        pr = scs.map{|sc| prbs[sc]}.inject(:*)
        if r1 <= 2
          sump += pr
        else
          sump += pr * Rational(2 - r0, r1 - r0)
        end
      end
    end
  end

  puts "%.7f" % sump.to_f
end

Measured memory_bytes: 6188
using System;
using System.Text;

namespace ALDS1_9_C_PriorityQueue
{
	class Program
	{
		static void Main ( string[] args )
		{
			PriorityQueue priorityQueue = new PriorityQueue (1500000);
			string inputStr;
			StringBuilder output = new StringBuilder (10000);

			while ((inputStr = Console.ReadLine ()) != "end")
			{
				string[] split = inputStr.Split (' ');

				if (split[0] == "insert")
				{
					priorityQueue.Insert (int.Parse (split[1]));
				}
				else
				{
					int result = priorityQueue.ExtractMax ();
					output.AppendLine (result.ToString ());
				}
			}

			Console.Write (output);
		}
	}

	class PriorityQueue
	{
		public PriorityQueue ( int capacity )
		{
			this.NumArray = new int[capacity + 1];
			this.ArrayIndex = 0;
		}

		private int[] NumArray { set; get; }
		private int ArrayIndex { set; get; }
		private const int Infty = int.MinValue;

		public void Insert ( int value )
		{
			ArrayIndex++;

			if (NumArray.Length <= ArrayIndex)
			{
				int[] tmp = new int[NumArray.Length];
				NumArray.CopyTo (tmp, 0);
				NumArray = new int[NumArray.Length + 1];
				tmp.CopyTo (NumArray, 0);
			}

			NumArray[ArrayIndex] = Infty;
			IncreaseKey (ArrayIndex, value);
		}

		public int ExtractMax ()
		{
			if (ArrayIndex < 1)
			{
				return Infty;
			}

			int max = NumArray[1];

			NumArray[1] = NumArray[ArrayIndex];
			ArrayIndex--;

			MaxHeapify (1);

			return max;
		}

		private void IncreaseKey ( int index, int value )
		{
			if (value < NumArray[index])
			{
				return;
			}

			NumArray[index] = value;

			while (1 < index && NumArray[ParentKey (index)] < NumArray[index])
			{
				int p = ParentKey (index);

				var tmp = NumArray[p];
				NumArray[p] = NumArray[index];
				NumArray[index] = tmp;

				index = p;
			}
		}

		private void MaxHeapify ( int index )
		{
			int leftIndex = LeftKey (index);
			int rightindex = RightKey (index);
			int maxIndex;

			if (leftIndex <= ArrayIndex && NumArray[index] < NumArray[leftIndex])
			{
				maxIndex = leftIndex;
			}
			else
			{
				maxIndex = index;
			}

			if (rightindex <= ArrayIndex && NumArray[maxIndex] < NumArray[rightindex])
			{
				maxIndex = rightindex;
			}

			if (maxIndex != index)
			{
				var tmp = NumArray[index];
				NumArray[index] = NumArray[maxIndex];
				NumArray[maxIndex] = tmp;

				MaxHeapify (maxIndex);
			}
		}

		private int ParentKey ( int index )
		{
			return index / 2;
		}
		private int LeftKey ( int index )
		{
			return index * 2;
		}
		private int RightKey ( int index )
		{
			return index * 2 + 1;
		}
	}
}

Measured memory_bytes: 30852
#include <stdio.h>
#define INF 1e9

int main(void){
    int i,j,l,b,idx,cnt=0,m=INF;
    scanf("%d", &l);
    int ary[l];
    for(i=0;i<l;i++) scanf("%d", &ary[i]);
    for(i=0;i<l-1;i++,m=INF){
        for(j=i+1;j<l;j++){if (m>ary[j]){m=ary[j],idx=j;}}
        if (ary[i]>m){b=ary[i],ary[i]=ary[idx],ary[idx]=b,cnt++;}
    }
    for(i=0;i<l;i++){(i<l-1)? printf("%d ",ary[i]) : printf("%d\n", ary[i]);}
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 2104