akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <math.h>

using namespace std;

class prob{
    public:
    int worng = 0;
    int accep = 0;

};

int main(){
    int problems, queries;
    cin >> problems >> queries;
    vector<prob*> vec(problems);
    for(int i = 0; i < problems; i++){
        vec[i] = new prob();
    }
    int accepted = 0, wrong = 0;
    while(queries--){
        int p; cin >>p;
        p--;
        string str; cin >> str;
        if(str == "WA" && vec[p]->accep == 0){
            vec[p]->worng++;
        }
        else if(str == "AC" && vec[p]->accep == 0){
            vec[p]->accep = 1;
            wrong += vec[p]->worng;
            accepted++;
        }
    }
    cout << accepted << " " << wrong << endl;
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);

int main(){
    int n;
    cin >> n;
    vector<ll> A(n);
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    ll sum = 0;
    for(int i=0;i<n;i++){
        sum += A[i];
    }
    sum /= 2;
    ll temp = 0;
    for(int i=1;i<n;i++){
        if(i%2 == 1)temp+=A[i];
    }
    vector<ll> x(n,0);
    x[0] = sum - temp;
    for(int i=0;i<n-2;i++){
        x[i+1] = A[i] - x[i];
    }
    x[n-1] = A[n-1] - x[0];
    vector<ll> ans(n,0);
    for(int i=0;i<n;i++){
        ans[i] = x[i] * 2;
    }
    for(int i=0;i<n;i++){
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int mod=1e9+7;
void f(int n,vector<int>&a){
	if(n==1)return;
	for(int i=2;i<=n;i++){
		if(n%i==0){
			a[i]+=1;
			f(n/i,a);
			return;
		}
	}
	return;
}
int main(){
	int n;
	cin>>n;
	if(n==1){
		cout<<"1"<<endl;
		return 0;
	}
	vector<int>a(n+1,0);
	for(int i=2;i<=n;i++){
		f(i,a);
	}
	int fact=1;
	for(int i=2;i<n+1;i++){
		fact=(long long int)fact*(a[i]+1)%mod;
	}
	cout<<fact<<endl;
}

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


int main() {
	
	int N, M, cnt=0;
	cin >> N >> M;
	multiset<int> s;
	for(int i=0; i<N; i++){
		int k;
		cin >> k;
		for(int j=0; j<k; j++){
			int a;
			cin >> a;
			s.insert(a);
		}
	}
	for(int i=1; i<=M; i++){
		if(s.count(i)==N) cnt++;
	}
	cout << cnt << endl;
	
	
	return 0;
}

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

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) (((a) >> (b)) & 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

string aaa = "abcdefghijklmnopqrstuvwxyz";

signed main() {
  string s, tmp;
  cin >> s;
  tmp = s;
  sort(ALL(tmp));

  for (int i = 0; i < 26; i++) {
    if (tmp[i] != aaa[i]) {
      cout << s << aaa[i] << endl;
      return 0;
    }
  }

  tmp = s;
  reverse(ALL(tmp));

  if (s == "zyxwvutsrqponmlkjihgfedcba") {
    cout << -1 << endl;
    return 0;
  }

  int cont = 0;
  char c;
  for (int i = 0; i < s.size(); i++) {
    if (tmp[i + 1] < tmp[i]) {
      c = tmp[i + 1];
      break;
    } else {
      cont++;
    }
  }

  char last;
  for (int i = 0; i < s.size(); i++) {
    if (c < tmp[i]) {
      last = tmp[i];
      break;
    }
  }

  cout << s.substr(0, s.size() - cont - 2) << last << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(void){
	int N; cin >> N;
	vector<string> s(N);
	int i;
	bool flag = true;

	for (i = 0; i < N; i++) {
		cin >> s[i];
	}

	for (i = 0; i < N - 1; i++) {
		if (s[i].back() != s[i + 1].front()) {
			flag = false;
		}
	}


	for (i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i>=j) {
				continue;
			}
			if (s[i] == s[j]) {
				flag = false;
			}
		}
	}

	if (flag) {
		cout << "Yes" << endl;
	}
	else { cout << "No" << endl; }

	return 0;
}

Measured memory_bytes: 256
import bisect

def CS1D(lis): #listを渡す
    ret=[lis[0]]
    for i in range(1,len(lis)):
        ret.append(ret[i-1]+lis[i])
    return ret
  
N=int(input())
A=[int(a) for a in input().split()]
A.sort()
CS=CS1D(A)
ans=0
for i in range(N):
  w=CS[i]
  prev=-1
  while True:
    tmp=bisect.bisect(A,2*w)-1
    if tmp==N-1:
      ans+=1
      break
    if prev==tmp:
      break
    w=CS[tmp]
    prev=tmp
print(ans)
    
    

Measured memory_bytes: 14480
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll, ll>
#define pb push_back
#define rep0(i, n) for(ll i = 0;i<n;i++)
#define rep1(i, n) for(ll i = 1;i<n;i++)
#define all(v) v.begin(),v.end()
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;
const int N = 1e5 + 5;
void solve(){
    int d, t, s;
    cin >> d >> t >> s;
    if(t>=(d/(s*1.0))){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

int main()
{
    fast;
    solve();
    // int t;
    // cin >> t;
    // while(t--){
    //     solve();
    // }
    return 0;
}


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

int main() {
  long h,w,k,ans=99999999;
  cin >> h >> w >> k;
  vector<string> s(h);
  vector<vector<long>> aaa(h+1,vector<long>(w+1));
  vector<bool> cutdata(h-1,false);
  aaa[0][0]=0;
  for(long i=1;i<=h;i++) aaa[i][0]=0;
  for(long i=1;i<=w;i++) aaa[0][i]=0;
  for(long i=0;i<h;i++) cin >> s[i];

  for(long i=1;i<=h;i++) {
    for(long j=1;j<=w;j++) {
      aaa[i][j]=aaa[i-1][j]+aaa[i][j-1]-aaa[i-1][j-1];
      if(s[i-1][j-1]=='1') aaa[i][j]++;
    }
  }
  
  while(true) {
    long a;
    vector<long> cut;
    cut.push_back(0);
    for(long i=0;i<h-1;i++) {
      if(cutdata[i]) cut.push_back(i+1);
    };
    cut.push_back(h);
    a=cut.size()-2;
    long e=0;
    for(long i=0;i<w;i++) {
      for(long j=1;j<cut.size();j++) {
        if(aaa[cut[j]][i+1]-aaa[cut[j]][e]-aaa[cut[j-1]][i+1]+aaa[cut[j-1]][e]>k) {
          if(aaa[cut[j]][i+1]-aaa[cut[j]][i]-aaa[cut[j-1]][i+1]+aaa[cut[j-1]][i]>k) a=99999999;
          e=i;
          a++;
          break;
        }
      }
    }
    ans=min(a,ans);
    if(cut.size()==h+1) break;
    for(long i=0;true;i++) {
      cutdata[i]=!(cutdata[i]);
      if(cutdata[i]) break;
    }
  }
  cout << ans << endl;
}

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

char a;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a;
	if(a >= 'A' && a <= 'Z') cout << 'A' << endl;
	else cout << 'a' << endl;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define rint register int 
using namespace std;
int n,m,tong[1010100],f[1010000];
int main(){
	cin>>n>>m;
	for(rint i=1;i<=n;++i) tong[i]=1;
	f[1]=1;
	for(rint i=1;i<=m;++i) {
		int x,y;
		cin>>x>>y;
		tong[x]--;
		tong[y]++;
		if(f[x]) f[y]=1;
		if(tong[x]==0) f[x]=0;
	}
	int ans=0;
	for(rint i=1;i<=n;++i) ans+=f[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4424
n = int(input())
h = list(map(int,input().split()))
dp = [0]*(n)
for i in range(1,n):
    if i>1:
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))
    else:
        dp[i] = dp[i-1] + abs(h[i]-h[i-1])
print(dp[-1])

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

using namespace std;

const int INF = 1<<30;

struct EDGE
{
    int v,c,next;
}E[3000];

bool vise[3000];
int cur[400],pre[400],cnt[400],dis[400];
int head[400];
int n,m,S,T,tot,low;

void add(int u,int v,int c)
{
    E[tot].v=v;
    E[tot].c=c;
    E[tot].next=head[u];
    head[u]=tot++;
}

void addedge(int u,int v,int c)
{
    add(u,v,c);
    add(v,u,c);
}

void rebfs()
{
    for(int i=0;i<n;i++)
        cnt[i]=0,dis[i]=n;
    queue<int> q;
    dis[T]=0;
    cnt[0]=1;
    q.push(T);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(int e=head[u];e!=-1;e=E[e].next)
        {
            if(E[e^1].c==0||dis[E[e].v]<n) continue;
            dis[E[e].v]=dis[u]+1;
            cnt[dis[E[e].v]]++;
            q.push(E[e].v);
        }
    }
}

int ISAP()
{
    rebfs();
    for(int i=0;i<n;i++) cur[i]=head[i];
    int flow=0,u=S,v,e;
    low=INF;
    while(dis[S]<n)
    {
        for(e=cur[u];e!=-1;e=E[e].next)
            if(E[e].c&&dis[u]==dis[v=E[e].v]+1) break;
        if(e!=-1)
        {
            cur[u]=e;
            pre[v]=e;
            low=min(low,E[e].c);
            u=v;
            if(u==T)
            {
                for(;u!=S;u=E[pre[u]^1].v)
                {
                    E[pre[u]].c-=low;
                    E[pre[u]^1].c+=low;
                }
                flow+=low;
                low=INF;
            }
        }
        else
        {
            if(--cnt[dis[u]]==0) break;
            dis[u]=n;
            cur[u]=head[u];
            for(e=head[u];e!=-1;e=E[e].next)
                if(E[e].c>0&&dis[u]>dis[E[e].v]+1)
                    dis[u]=dis[E[e].v]+1;
            cnt[dis[u]]++;
            if(u!=S) u=E[pre[u]^1].v;
        }
    }
    return flow;
}

int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        tot=0;
        memset(head,-1,sizeof(head));
        memset(vise,0,sizeof(vise));
        int u,v;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&u,&v);
            addedge(--u,--v,1);
        }
        scanf("%d%d",&S,&T);
        S--;
        T--;
        printf("%d\n",ISAP());
        int ans=0;
        for(int i=0;i<tot;i++)
            if(E[i].c==0&&(i&1)==1)
                ans++;
        printf("%d\n",ans);
        for(int i=0;i<tot;i++)
            if(E[i].c==0&&(i&1)==1)
                printf("%d\n",i/2+1);
    }
    return 0;
}

/*
2 1
2 1
2 1

2 1
1 2
2 1

3 3
3 2
1 2
3 1
1 3

*/

Measured memory_bytes: 1224
#include<stdio.h>

int solve(int,int);

int A[2000];
int M[200];
int n=0,q=0;

int main(){

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

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M[i]);
  }
  for(i=0;i<q;i++){
    if(solve(0,M[i]) == 1){
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }
  return 0;
}

int solve(int p,int t){

  if(t==0){
    return 1;
  }else if(t<0){
    return 0;
  }else if(p>n){
    return 0;
  }else if(solve(p+1,t-A[p]) == 1){
    return 1;
  }else if(solve(p+1,t) == 1){
    return 1;
  }

}

Measured memory_bytes: 584
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    g = a[0]
    for i in range(1, n):
        g = fractions.gcd(g, a[i])
    if k <= max(a) and k % g == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    return 0

if __name__ == "__main__":
    solve()



Measured memory_bytes: 25128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int t2 = h2 * 60 + m2;
    int t1 = h1 * 60 + m1;
    cout << t2 - t1 - k << endl;
    
}

Measured memory_bytes: 3632
#from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    a,b,k = mi()

    if a-k>0:
        print(a-k,b)
    else:
        k-=a
        print(0,max(b-k,0))


main()




Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
int main(){
    int x,n;
    cin>>x>>n;
    vector<int> p(300);
    rep(i,n){
        int a;
        cin>>a;
        p[a]=1;
    }
    int y=0;

    while (1){
        if(p[x-y]!=1){
            cout<<x-y<<endl;
            return 0;
        }
        else if(p[x+y]!=1){
            cout<<x+y<<endl;
            return 0;
        }
        y++;
    }
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

class SegmentTree
{
private:
	const long long inf = 1e18;
	int n;
	vector<long long> dat;
public:
	SegmentTree(int n_) {
		n = 1;
		while (n < n_) {
			n *= 2;
		}

		dat.assign(n * 2 - 1, inf);
	};
	~SegmentTree() {
		dat.clear();
	};

	void update(int k, int a) {
		k += n - 1;
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k*2 + 1], dat[k*2 + 2]);
		}
	}

	long long query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) {
			return inf;
		}

		if (a <= l && r <= b) {
			return dat[k];
		} else {
			long long vl = query(a, b, k*2 + 1, l, (l+r)/2);
			long long vr = query(a, b, k*2 + 2, (l+r)/2, r);
			return min(vl, vr);
		}
	}

	long long query(int a, int b) {
		return query(a, b, 0, 0, n);
	}

	void show() {
		int i = 0;
		for (auto e: dat) {
			printf("%3d: %6lld\n", i, e);
			i++;
		}
	}
};

int main() {
	int n, t;

	cin >> n >> t;
	vector<int> a(n);
	SegmentTree st(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		st.update(i, a[i]);

	}

	int max_diff = 0;
	int count = 0;


	for (int i = 0; i < n; i++) {
		int val = a[i] - st.query(0, i+1);
// printf("i %d a %d query %d\n", i, a[i], st.query(0, i+1));
		if (val == max_diff) {
// printf("add\n");
			count++;
		} else if (val > max_diff) {
			max_diff = val;
			count = 1;
// printf("new %d\n", max_diff);
		}
		// printf("a[%2d] %4d, val %4d\n", i, a[i], val);
	}

	cout << count << endl;
	return 0;
}


Measured memory_bytes: 2688
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[500];
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",b+i);
	}
	std::sort(b,b+a);
	long long ret=0;
	for(int i=a-1;i>=0;i--){
		ret+=max(0,b[i]-(a-1-i)/4);
	}
	printf("%lld\n",ret+1);
}

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

const int mod = 1e9+7;

 
int p[1005], c[1005]; 
ll cnt;//因子个数 
const ll N = 1e6+10; 
ll prime[N] = {0},num_prime = 0;  //prime存放着小于N的素数   
int isNotPrime[N] = {1, 1};        // isNotPrime[i]如果i不是素数，则为1 
int Prime()    
{     
     	for(ll  i = 2 ; i < N ; i ++)       
       	{            
		if(! isNotPrime[i])               
	 		prime[num_prime ++]=i;  
	   //无论是否为素数都会下来     
		for(ll  j = 0 ; j < num_prime && i * prime[j] <  N ; j ++)
    		{               
		      	isNotPrime[i * prime[j]] = 1;  
	  		if( !(i % prime[j] ) )  //遇到i最小的素数因子
	  			//关键处1                  
				break;           
		}        
	}        
	return 0;   
}  
///与素数筛选一起用的质数分解
///将x分解为式n=（p1^α1）*（p2^α2）*（p3^α3）* ....... *（pk^αk）
///数组p和c求解保存底数p1或者指数α1
set<int> sett; 
void Dec(ll x)
{
	cnt = 0;
    for(int i=0; prime[i]*prime[i]<=x&&i<num_prime; i++)
    {
        if(x%prime[i]==0)
        {
             int num=0;
            while(x%prime[i]==0)
              {
              	num++;
              	 x /= prime[i];
              } 
				p[cnt]=prime[i];
				sett.insert(prime[i]);
				c[prime[i]]+=num;
        }
        if(x==1) break;
    }
    if(x > 1) {
		   p[cnt]=x;
		   sett.insert(x);
	       c[x]+=1;   
    }
      
}


int main()
{
	Prime();
	ll n;
	scanf("%lld",&n);
	for(int i=2;i<=n;i++) 
		Dec(i);
	ll ans=1;
	set<int>::iterator it;              
    for(it=sett.begin();it!=sett.end();it++)   
    {  
		ans=(ans%mod*(c[*it]+1)%mod)%mod;
    }  
    cout<<ans<<endl;
    return 0;
}


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

bool graph[8][8];

int dfs(int v, int N, bool visited[]) {
  bool all_visited = true;
  for (int i=0 ; i<N ; i++) {
    if (visited[i] == false) {
      all_visited = false;
    }
  }

  if (all_visited) return 1;

  int ret = 0;

  for (int i=0 ; i<N ; i++) {
    if (visited[i] == false && graph[v][i] == true) {
      visited[i] = true;
      ret += dfs(i, N, visited);
      visited[i] = false;
    }
  }

  return ret;
}

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

  for (int i=0 ; i<M ; i++){
    int A, B;
    cin >> A >> B;
    graph[A-1][B-1] = graph[B-1][A-1] = true;
  }

  bool visited[8];
  for (int i=0 ; i<8 ; i++) {
    visited[i] = false;
  }

  visited[0] = true;

  cout << dfs(0, N, visited) << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    long long int r, D, x2000;
    cin >> r >> D >> x2000;
    
    long long int now=x2000;
    
    for(int i=0; i<10; i++) {
        now *= r;
        now -= D;
        cout << now << endl;
    }

    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
int alpha[26]={};
int h,w;
bool solve(){
  if(h%2==0&&w%2==0){
    for(int i=0;i<26;i++){
      if(alpha[i]%4!=0)return false;
    }
    return true;
  }else if(h%2==1&&w%2==1){
    int odds=0;
    int notFourPair=0;
    for(int i=0;i<26;i++){
      if(alpha[i]%2==1){
	odds++;
	if(odds>=2)return false;
      }
      notFourPair+=alpha[i]-(alpha[i]/4)*4;
    }
    return notFourPair<=h+w-1;
  }else{
    int notFourPair=0;
    for(int i=0;i<26;i++){
      if(alpha[i]%2==1) return false;
      notFourPair+=alpha[i]-(alpha[i]/4)*4;
    }
    if(h%2==0)
      return notFourPair<=h;
    else//w%2==0
      return notFourPair<=w;
  }
}

int main(){ _;
  char c;
  cin>>h>>w;
  REP(i,h)REP(j,w){
    cin>>c;
    alpha[c-'a']++;
  }
  cout<<(solve()?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
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; }

#include <iomanip>
int main() {
    int N; cin >> N;
    vector<double> p(N + 1);
    for (int i = 1; i <= N; i++) cin >> p[i];

    vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0));
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int h = 0; h <= i; h++) {
            if (h - 1 >= 0) dp[i][h] += dp[i - 1][h - 1] * p[i];
            dp[i][h] += dp[i - 1][h] * (1 - p[i]);
        }
    }
    double res = 0.0;
    for (int h = 0; h <= N; h++) if (N - h < h) res += dp[N][h];
    cout << fixed << setprecision(10) << res << endl;
    return 0;
}

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

int main(void){
  int n;

  while(1){
    cin>>n;
    if(n==0) break;
    int max=0;
    int min=501;
    for(int i=0;i<n;i++){
      int sum = 0;
      for(int j=0;j<5;j++){
        int score;
        cin>>score;
        sum += score;
      }
      if(max < sum) max = sum;
      if(min > sum) min = sum;
    }
    cout<<max<<" "<<min<<endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>

int main(void)
{
	int len;
	char str[1005];
	
	scanf("%s", str);
	
	len = strlen(str);
	
	for (int i = 0; i < len; i++){
		
		str[i] -= 3;
		if (str[i] < 'A'){
			str[i] += 'Z' - 'A' + 1;
		}
	}
	printf("%s\n", str);
	
	return(0);
}

Measured memory_bytes: 948
fun main(args: Array<String>) {
    fun f(n: Int): Int {
        return if (n % 2 == 0) {
            1 + f(n / 2)
        } else {
            0
        }
    }
    
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { m -> f(m.toInt()) }.sum()
    
    println(a)
}

Measured memory_bytes: 42084
N, M = map(int, input().split())
A = {int(input()) for _ in range(M)}

MOD = 10 ** 9 + 7

dp = [1] + [0] * (N + 10)

for n in range(1, N + 1):
	if n in A:
		continue
	dp[n] = (dp[n - 1] + (dp[n - 2] if 2 <= n else 0)) % MOD

print(dp[N])


Measured memory_bytes: 11884
from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))

Measured memory_bytes: 88796
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main(){

  int sx, sy, tx, ty, x, y;
  cin >> sx >> sy >> tx >> ty;

  if(ty-sy>0){
    y=ty-sy;
    for(int i=0; i<y; i++){
      cout << 'U';
    }
  } else if(ty-sy<0){
    y=sy-ty;
    for(int i=0; i<y; i++){
      cout << 'D';
    }
  }

  if(tx-sx>0){
    x=tx-sx;
    for(int i=0; i<x; i++){
      cout << 'R';
    }
  } else if(tx-sx<0){
    x=sx-tx;
    for(int i=0; i<x; i++){
      cout << 'L';
    }
  }

  if(ty-sy>0){
    y=ty-sy;
    for(int i=0; i<y; i++){
      cout << 'D';
    }
  } else if(ty-sy<0){
    y=sy-ty;
    for(int i=0; i<y; i++){
      cout << 'U';
    }
  }

  if(tx-sx>0){
    x=tx-sx;
    for(int i=0; i<x; i++){
      cout << 'L';
    }
  } else if(tx-sx<0){
    x=sx-tx;
    for(int i=0; i<x; i++){
      cout << 'R';
    }
  }

  if(tx-sx>0){
    cout << 'L';
  } else if(tx-sx<0){
    cout << 'R';
  }

  if(ty-sy>0){
    y=ty-sy;
    for(int i=0; i<y+1; i++){
      cout << 'U';
    }
  } else if(ty-sy<0){
    y=sy-ty;
    for(int i=0; i<y+1; i++){
      cout << 'D';
    }
  }

  if(tx-sx>0){
    x=tx-sx;
    for(int i=0; i<x+1; i++){
      cout << 'R';
    }
  } else if(tx-sx<0){
    x=sx-tx;
    for(int i=0; i<x+1; i++){
      cout << 'L';
    }
  }

  if(ty-sy>0){
    cout << 'D';
  } else if(ty-sy<0){
    cout << 'U';
  }

  if(tx-sx>0){
    cout << 'R';
  } else if(tx-sx<0){
    cout << 'L';
  }

  if(ty-sy>0){
    y=ty-sy;
    for(int i=0; i<y+1; i++){
      cout << 'D';
    }
  } else if(ty-sy<0){
    y=sy-ty;
    for(int i=0; i<y+1; i++){
      cout << 'U';
    }
  }

  if(tx-sx>0){
    x=tx-sx;
    for(int i=0; i<x+1; i++){
      cout << 'L';
    }
  } else if(tx-sx<0){
    x=sx-tx;
    for(int i=0; i<x+1; i++){
      cout << 'R';
    }
  }

  if(ty-sy>0){
    cout << 'U';
  } else if(ty-sy<0){
    cout << 'D';
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,c,d,k;
    cin>>a>>b>>c>>k;
    if(k<=a){
        cout<<k;
    }else{
        k=k-a;
        if(k<=b){
            cout<<a;
        }else{
            k=k-b;
            cout<<a-k;
        }
    }

    return 0;
  
}


Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

void tolower(string& str) {
    for (auto& ch : str) {
        if (isupper(ch)) {
            ch = tolower(ch);
        }
    }
}

int main() {
    string w, t;
    cin >> w;
    tolower(w);

    int ans = 0;
    while (cin >> t) {
        if (t == "END_OF_TEXT") {
            break;
        }
        tolower(t);

        if (t == w) {
            ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

#define int long long

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

    int n;
    cin >> n;
    vector<int> vec(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> vec[i];
    vector<int> dp(n + 3, 1e12);
    dp[1] = 0;
    dp[2] = abs(vec[2] - vec[1]);
    for (int i = 3; i <= n; i++)
    {
        int a = dp[i - 1] + abs(vec[i - 1] - vec[i]);
        int b = dp[i - 2] + abs(vec[i - 2] - vec[i]);
        dp[i] = min(a, b);
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 1792
def main():
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a%b)

    n = int(input())
    a = [int(x) for x in input().split()]
    x = [0] * n
    y = [0] * n
    # x []   [0~1][0~2][0~3]...[0~n-1][0~n]
    # y [0~n][1~n][2~n][3~n]...[n]    []
    # yのrangeのとり方を工夫する
    for i in range(1,n):
        x[i] = gcd(x[i-1], a[i-1])
    for i in range(n-2, -1, -1):
        y[i] = gcd(y[i+1], a[i+1])
    ans = [gcd(x[i], y[i]) for i in range(n)]
    print(max(ans))

if __name__ == '__main__':
    main()

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

int main()
{
    int m, n;
    cin>>n>>m;
    int s;
    long long int sum = 0;
    for(int i = 0; i < m; i++)
    {
        cin>>s;
        sum = sum + s;
    }
    if(n >= sum){
        cout<<(n-sum);    }
    else
        cout<<"-1";
    return 0;
    
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

    int n; cin >> n;

    set<ll> st;
    int temp;
    vector<ll> p;
    for(int i=0; i<n; i++){
        cin >> temp;
        if(st.find(temp) == st.end()){
            st.insert(temp);
        }
        else{
            p.push_back(temp);
            st.erase(temp);
        }
    }

    if(p.size() < 2){
        cout << 0;
    }
    else{
        sort(p.begin(), p.end(), greater<ll>());

        cout << p[0]*p[1];
    }
    



    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		UL a = 0, b = 0;
		vector<pair<int, int>> Q(N);
		rep(i, N) {
			cin >> Q[i].first >> Q[i].second;
			if (Q[a].first < Q[i].first) a = i;
			if (Q[b].second > Q[i].second) b = i;
		}
		int ans = 0;
		{
			int ansbuf = 0; rep(i, N) ansbuf = max(ansbuf, Q[i].second - Q[i].first + 1);
			if (Q[a].first <= Q[b].second)
				ans = max(ans, ansbuf + (Q[b].second - Q[a].first + 1));
			else
				ans = max(ans, ansbuf);
			//cout << ans << endl;
		}
		sort(Q.rbegin(), Q.rend());
		vector<pair<int, int>> Q2;
		int p = 2000000000;
		rep(i, N) {
			if (p <= Q[i].second) continue;
			Q2.push_back(Q[i]);
			p = Q[i].second;
		}
		Q = move(Q2);
		reverse(Q.begin(), Q.end());
		for (UL i = 1; i < Q.size(); i++) {
			int A = max(0, Q.front().second - Q[i - 1].first + 1);
			int B = max(0, Q[i].second - Q.back().first + 1);
			//cout << A + B << " ";
			ans = max(ans, A + B);
		} //cout << endl;
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 2168
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		TreeSet<Integer> set = new TreeSet<>();
		for (int i = 0; i < n; i++) {
			set.add(sc.nextInt());
		}
		int ans1 = set.last(), ans2 = 0, diff = Integer.MAX_VALUE;

		Integer h = set.ceiling(ans1 / 2);
		Integer l = set.lower(ans1 / 2);
		if(h==ans1) {
			h = l;
		}
		if (ans1 % 2 == 0) {
			int base = ans1 / 2;
			if (h != null) {
				int d = Math.abs(base - h);
				if (d < diff) {
					diff = d;
					ans2 = h;
				}
			}
			if (l != null) {
				int d = Math.abs(base - l);
				if (d < diff) {
					diff = d;
					ans2 = l;
				}
			}
		} else {
			int base = ans1/2;
			int base2 = ans1/2+1;
			if (h != null) {
				int d = Math.abs(base2 - h);
				if (d < diff) {
					diff = d;
					ans2 = h;
				}
			}
			if (l != null) {
				int d = Math.abs(base - l);
				if (d < diff) {
					diff = d;
					ans2 = l;
				}
			}
		}

		System.out.println(ans1+" "+ans2);
	}
}

Measured memory_bytes: 65480
import java.util.*;

public class Main {
	class Process {
		String name;
		int time;
		Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
	}
	void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int q = scanner.nextInt();
		Queue<Process> que = new LinkedList<Process>();
		for (int i = 0; i < n; i++) {
			String name = scanner.next();
			int time = scanner.nextInt();
			que.add(new Process(name, time));
		}
		for (int time = 0; !que.isEmpty();) {
			Process p = que.poll();
			if (p.time - q <= 0) {
				time += p.time;
				System.out.println(p.name + " " + time);
			} else {
				p.time -= q;
				que.add(p);
				time += q;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 77800
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)n);i++)
#define rep1(i,n) for(int i=1;i<=((int)n);i++)
typedef long long ll;
ll a[50];
ll monkey[50];
ll monking[50];
int main()
{
    string temp="2019/04/30";
    string s;
    while(cin>>s)
    {
        if(s<=temp) cout<<"Heisei\n";
        else cout<<"TBD\n";
    }
	return 0;
}

Measured memory_bytes: 256
# Single Source Shortest Path 1
INF = 10**10
N = int(input())
W = [[INF]*(N) for _ in [0]*(N)]

for _ in [0]*N:
    v, k, *A = map(int, input().split())
    for u, c in zip(*[iter(A)]*2):
        W[v][u] = c

S = set()
d = [INF]*N

d[0] = 0
while len(S) < N:
    dmin = INF
    v = -1
    for i in range(N):
        if i not in S and d[i] < dmin:
            dmin = d[i]
            v = i

    S.add(v)
    for u, w in enumerate(W[v]):
        if d[v]+w < d[u]:
            d[u] = d[v]+w

for i in range(N):
    print(i, d[i])



Measured memory_bytes: 5744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define INF 1000000000000
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
char c;
cin>>c;
if(c&0x20)
{
	cout<<"a\n";
}
else
{
		cout<<"A\n";
}
return  0;
}






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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);


int main(void)
{
    ll a,b; cin>>a>>b;
    char c='x';
    if(a+b==15) c='+';
    if(a*b==15) c='*';
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 3592
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int a,b,c;
int main(){
	cin>>a>>b>>c;

	if(a==b && b==c)cout<<1<<endl;
	else if(a==b || b==c || c==a)cout<<2<<endl;
	else cout<<3<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>

using namespace std;

int main(void) {

	int a, b, c, d;

	cin >> a >> b >> c >> d;
	
	if (abs(c - a) <= d || (abs(c - b) <= d && abs(b - a) <= d))cout << "Yes\n";
	else cout << "No\n";


	return 0;
}

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

using namespace std;

int main()
{
    string n;

    cin >> n;

    int i;

    int sum=0;

    for(i=0;i<n.size();i++)
    {
        sum=sum+((int)n[i]-48);
    }

    if(sum%9==0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3720
from collections import deque

n, k = map(int, input().split())
ps = list(map(int, input().split()))
ps = [(p + 1)/2 for p in ps]
# print(ps)

d = deque()
vmax = 0
v = 0
for p in ps:

    if len(d) == k:
        old = d.popleft()
        new = p
        d.append(new)
        v = v + new - old
        if v > vmax:
            # print("v > vmax")
            vmax = v
    else:
        d.append(p)
        v += p
        vmax = v
    # print(vmax, v, d)

print(vmax)






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

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> x2 >> y1 >> y2;
    int x3 = x2 - (y2 - y1);
    int y3 = y2 - (x1 - y1);
    int x4 = x1 - (y2 - x2);
    int y4 = y1 - (x1 - x2);
    cout << x3 << " " << y3 << " " << x4 << " " << y4;
}


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

void solve(long long r, long long D, long long x){
	long long res = x;
	for (int i=1; i<=10; i++) {
		res = r*res-D;
		cout << res << endl;
	}
}

int main(){	
	long long x;
	long long D;
	long long r;
	scanf("%lld",&r);
	scanf("%lld",&D);
	scanf("%lld",&x);
	solve(r, D, x);
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int N,A[100100],B[200200];

void push(int x)
{
	while (x <= N * 2 + 2){
		B[x]++;
		x += x & (-x);
	}
}

int pop(int x)
{
	int r = 0;
	while (x){
		r += B[x];
		x -= x & (-x);
	}
	return r;
}

bool chk(int x)
{
	long long need = ((long long)N * (N + 1) / 2 + 1) / 2;
	long long cnt = 0;

	for (int i=0;i<=N*2+2;i++) B[i] = 0;
	int bal = N+1;
	for (int i=1;i<=N;i++){
		push(bal);
		if (A[i] >= x) bal++;
		else bal--;
		cnt += pop(bal);
	}

	return cnt >= need;
}

int main()
{
	scanf ("%d",&N);
	for (int i=1;i<=N;i++) scanf ("%d",&A[i]);

	int l = 0, r = 1000000001;
	while (l + 1 < r){
		int m = (l + r) / 2;
		if (chk(m)) l = m;
		else r = m;
	}

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

	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b && a==c && b==c) || (a!=b && a!=c && b!=c))
        cout <<"No";
    else cout<<"Yes";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
s = input()
check = 'keyence'

if s[0] != 'k' and s[-1] != 'e':
    print('NO')
else:
    if s[:7] == check or s[-7:] == check:
        print('YES')
        exit()
    else:
        for i in range(1, 7):
            if s[:i] + s[-(7 - i):] == check:
                print('YES')
                exit()
                # print(s[:i], s[-(7 - i):])
    print('NO')


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


int main(){
  int na,nb,nm;
  cin >> na >> nb >> nm;
  //cout<<na<<"  "<<nb<<"  "<<nm<<endl;
  vector <int> a(na);
  rep(i,na)cin>>a.at(i);

  vector <int> b(nb);
  rep(i,nb)cin>>b.at(i);

  vector <int> m(nm);


  rep(i,nm){
    int xa,xb,c;
    cin>>xa>>xb>>c;
    xa-=1;
    xb-=1;
    m.at(i) =a.at(xa)+b.at(xb)-c;
  }


  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(m.begin(),m.end());
  int x = a.at(0)+b.at(0);
  int y = m.at(0);
  int ans = min(x,y);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

int main(void){
	int H,W,i,j=0;
	scanf("%d %d",&H,&W);
	char a[H][W];
	int column[H],row[W];
	for(i=0;i<H;i++)scanf("%s",a[i]);
	
	for(i=0;i<H;i++){
		column[i] = 0;
		row[j] = 0;
		for(j=0;j<W;j++){
			if(a[i][j] == '#'){
				column[i] = 1;
				row[j] = 1;
			}
		}
	}
	
	int aaa=0;
	for(i=0;i<H;i++){
		aaa=0;
		for(j=0;j<W;j++){
			if(column[i]==1 && row[j]==1){
				printf("%c",a[i][j]);
				aaa=1;
			}
		}
		if(aaa==1)printf("\n");
	}
	
	
	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        int n,m;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer in=new StringTokenizer(br.readLine());
        n=Integer.parseInt(in.nextToken());
        m=Integer.parseInt(in.nextToken());
        in=null;
        Union_Find tree=new Union_Find(n);
        for(int i=0;i<m;i++){
            in=new StringTokenizer(br.readLine());
            int a=Integer.parseInt(in.nextToken()),b=Integer.parseInt(in.nextToken());
            in=null;
            tree.Union(a,b);
        }
        br=null;
        System.out.println(tree.get_tree(n));
    }
}
class Union_Find{
    private int[] t,s;
    public Union_Find(int max_length){
        t=new int[max_length];
        s=new int[max_length];
        for(int i=0;i<max_length;i++){
            t[i]=i;
            s[i]=1;
        }
    }
    void Union(int x,int y){
        if (same(x, y)) return;
        x--;y--;
        int tx = Find(x), ty = Find(y);
        if (s[tx] < s[ty]) {
            s[ty] += s[tx];
            t[tx] = ty;
        }
        else if (s[tx] > s[ty]) {
            s[tx] += s[ty];
            t[ty] = tx;
        }
        else if (tx > ty) {
            t[tx] = ty;
            s[ty] += s[tx];
        }
        else {
            t[ty] = tx;
            s[tx] += s[ty];
        }
    }
    int Find(int n) {
        if (t[n] == n)
            return n;
        else
            return t[n] = Find(t[n]);
    }
    boolean same(int x, int y) {
        return Find(x-1) == Find(y-1);
    }
    int get_Size(int a) {
        return s[a-1];
    }
    int get_tree(int size){
        HashSet<Integer> st=new HashSet<>();
        for(int i=0;i<size;i++){
            st.add(Find(i));
        }
        return st.size();
    }
}


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

int main(){
  int A,B,C,K;
  cin>>A>>B>>C>>K;

  if(A>=K){
    cout<<K<<endl;
  }
  else if(A+B>=K){
    cout<<A<<endl;
  }
  else if(A+B+C>=K){
    int D=K-(A+B);
    cout<<A-D<<endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int r; cin >> r;
  if(r < 1200) cout << "ABC" << "\n";
  else if(r < 2800) cout << "ARC" << "\n";
  else cout << "AGC" << "\n";
  return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N);
	REP(i, N) scanf("%d", &A[i]);
	REP(i, N) scanf("%d", &B[i]);
	
	map<int, int> mm[2]; // [0]:A, [1]:B
	REP(i, N) {
		++mm[0][A[i]];
		++mm[1][B[i]];
	}
	
	priority_queue<pii> pq; // (cnt, num)
	for (auto p : mm[0]) if (mm[1][p.first] > 0) {
		int c = p.second + mm[1][p.first];
		pq.emplace(c, p.first);
		if (c > N) {
			puts("No");
			return 0;
		}
	}
	
	vector<int> ans[2];
	while (pq.size() > 1) {
		pii p1 = pq.top(); pq.pop();
		pii p2 = pq.top(); pq.pop();
		ans[0].emplace_back(p1.second);
		ans[1].emplace_back(p2.second);
		if (--mm[0][p1.second] > 0) pq.emplace(p1.first - 1, p1.second);
		if (--mm[1][p2.second] > 0) pq.emplace(p2.first - 1, p2.second);
	}
	
	// 残りをリスト
	vector<int> res[2];
	int ng = pq.empty() ? -1 : pq.top().second;
	int c = mm[0][ng];
	REP(i, c) res[0].emplace_back(ng);
	REP(i, 2) for (auto p : mm[i]) if (p.first != ng) REP(j, p.second) res[i].emplace_back(p.first);
	c = mm[1][ng];
	REP(i, c) res[1].emplace_back(ng);
	
	REP(i, 2) ans[i].insert(ans[i].end(), ALL(res[i]));
	
	puts("Yes");
	vector<int> ord(N);
	iota(ALL(ord), 0);
	sort(ALL(ord), [&](int x, int y) { return ans[0][x] < ans[0][y]; });
	REP(i, N) printf("%d%c", ans[1][ord[i]], " \n"[i + 1 == N]);
	return 0;
}


Measured memory_bytes: 29100
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int tmp[100001], tmp2[100001];
void pakuri_sort(int N, int A[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

void pakuripair_sort(int N, int A[], int B[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) {
			tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
			tmp2[kazu[A[i] >> k * b & ((1 << b) - 1)]] = B[i];
		}
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) {
			A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
			B[kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp2[i];
		}
	}
}

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


	int N = getint(), M = getint();

	int A[100000];
	rep(i, N) A[i] = getint();
	pakuri_sort(N, A);

	int B[100000], C[100000];
	rep(i, M) {
		B[i] = getint();
		C[i] = getint();
	}
	pakuripair_sort(M, C, B);

	ll kotae = 0;
	int kazu = 0;
	for (int i = M - 1; i >= 0; i--) {
		int makkusu = min(B[i], N - kazu);
		rep(j, makkusu) kotae += max(A[kazu++], C[i]);
	}

	for (int i = kazu; i < N; i++) kotae += A[i];

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 2176
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	g := [15][15]int{}
	for i := 0; i < 15; i++ {
		for j := 0; j < 15; j++ {
			g[i][j] = -1
		}
	}

	var a int
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		var x, y int
		for j := 0; j < a; j++ {
			fmt.Scan(&x, &y)
			g[i][x-1] = y
		}
	}

	ans := 0
	for i := 0; i < 1<<uint(n); i++ {
		d := make([]int, n)
		for j := 0; j < n; j++ {
			if (i>>uint(j))&1 > 0 {
				d[j] = 1
			}
		}

		ok := true
		for j := 0; j < n; j++ {
			if d[j] != 1 {
				continue
			}
			for k := 0; k < n; k++ {
				if g[j][k] == -1 {
					continue
				}
				if g[j][k] != d[k] {
					ok = false
					break
				}
			}
		}
		if ok {
			c := count1(i)
			if ans < c {
				ans = c
			}
		}
	}
	fmt.Println(ans)
}

func count1(a int) int {
	c := 0
	for i := 0; i < a; i++ {
		if a&(1<<uint(i)) > 0 {
			c++
		}
	}
	return c
}


Measured memory_bytes: 4864
import sys
def Ii():return int(sys.stdin.buffer.readline())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))

k = Ii()
a,b = Mi()

for i in range(a,b+1):
  if i%k == 0:
    print('OK')
    exit(0)
    
print('NG')

Measured memory_bytes: 9136
co = list(map(int,input().split()))
N = co[0]
M = co[1]
h = list(map(int,input().split()))
tenbo = [0 for i in range(N)]
for i in range(M):
    load = list(map(int,input().split()))
    if h[load[0]-1] >= h[load[1]-1]:
        tenbo[load[1]-1] +=1
    if  h[load[0]-1] <= h[load[1]-1]:
        tenbo[load[0]-1] +=1
    #elif  h[load[0]-1] == h[load[1]-1]:
        #tenbo[load[0]-1] +=1
        #tenbo[load[1]-1] +=1
ans =0
for i in range(N):
    if tenbo[i] == 0:
        ans +=1
print(ans)
    
    



Measured memory_bytes: 19936