akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#include <numeric>
#define lint unsigned long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++)
#define DUMP(ar) for(auto itd=begin(ar); itd != end(ar); itd++) cout << "["s << itd - begin(ar) << "]:"s << *itd << endl
#define DUMPL(ar) for(auto itd=begin(ar); itd != end(ar); itd++) { cout << *itd; if(end(ar)-itd > 1) cout << ' '; } cout << endl
#define COUT(x) cout << (x) << endl
#define VCIN(ar) for(auto &vcin: (ar)) cin >> vcin
#define ALL(ar) ar.begin(), ar.end()
#define LOOPD(i) cout << "ループ["s << i << "]回目---------------"s << endl
using namespace std;
// lint:64ビット 10^19

vector<int> mm(100001, -1);

struct edge{
    int x;
    int y;
};

int rec(vector<vector<int>> &back, int node){
    if(back[node].size() == 0) return 0;
    if(mm[node] != -1) return mm[node];

    int num = 0;
    for(int i=0; i<(int)back[node].size(); i++){
        int tmp = rec(back, back[node][i]) + 1;
        if(tmp > num) num = tmp;
    }
    mm[node] = num;
    
    return num;
}

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

    int n, m;
    cin >> n >> m;
    vector<edge> edges(m);
    for(auto &i : edges){
        cin >> i.x >> i.y;
    }

    vector<vector<int>> back(n, vector<int>(0));
    for(int i=0; i<m; i++){
        back[edges[i].y-1].push_back(edges[i].x-1);
    }

    int ans = 0;
    for(int i=0; i<n; i++){
        if(mm[i] != -1){
            ans = max(ans, mm[i]);
        }else{
            ans = max(ans, rec(back, i));
        }
    }

    COUT(ans);

    return 0;
}

Measured memory_bytes: 11392
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		int l = S.length();
		long ans = 0;
		long cnt = 0;
		for(int i = 0; i < l; i++) {
			char c1 = S.charAt(i);
			if(c1 == 'B') {
				cnt++;
			}else {
				ans += cnt;
			}
		}
		System.out.println(ans);
	}
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<std::vector<char> > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int h, w;
    
    cin >> h >> w;

    v2_char s(h+1, v_char(w+1));
    
    irep2(i, 1, h) {
        irep2(j, 1, w) {
            cin >> s[i][j];
        }
    }

    irep2(i, 1, 2*h) {
        irep2(j, 1, w) {
            cout << s[(i+1)/2][j];
        } cout << endl;
    }
    
    return 0;
}
/** atcoder **/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s;
    cin >> s;
    bool flg=false;
    for(int i=0;i<s.size()-1;i++){
        for(int j=i+1;j<s.size();j++){
            if(s.at(i)=='C'&&s.at(j)=='F') flg=true;
        }
    }
    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define INF 10000009
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int grid1(string s[],vector<vector<int>> &dp,int h,int w)
{
	if(h<0 || w<0)
	{
		return 0;
	}
	if(dp[h][w]!=-1)
	{
		return dp[h][w];
	}
	if(s[h][w]=='#')
	{
		return dp[h][w]=0;
	}
	return dp[h][w]=(grid1(s,dp,h-1,w)+grid1(s,dp,h,w-1))%1000000007;
}

int main()
{
	fastio
	int h,w,i,j;
	cin>>h>>w;
	char x;
	string s[h];
	for(i=0;i<h;i++)
	{
		s[i]="";
		for(j=0;j<w;j++)
		{
			cin>>x;
			s[i]+=x;
		}
	}
	vector<vector<int>> dp(h,vector<int>(w,-1));
	dp[0][0]=1;
	cout<<grid1(s,dp,h-1,w-1);
	/*for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			cout<<dp[i][j]<<" ";
		}
		cout<<"\n";
	}*/
}

Measured memory_bytes: 9212
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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; }


int main() {
    int k; cin >> k;
    int res;
    if(k%2==0) res = (k/2) * (k/2);
    else res = (k/2)*(k/2+1);
    cout << res << ln;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <fstream>
#include<string>
#include<sstream>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
#include <math.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long long int MOD = 1000000007;
const int INF = 1000000007;
const double EPS = 1e-10;
const double PI = 3.14159265359;
const int N = 100005;
//cout << fixed << std::setprecision(9)
//--------------------------

string str;
int d;
ll dp[10005][105][2];

int main() {
	cin >> str;
	cin >> d;
	dp[0][0][0] = 1;

	for (int i = 0; i<str.size(); i++) {
		int pos = str[i] - '0';
		for (int j = 0; j<d; j++) {
			for (int a = 0; a <= pos; a++) {
				if (a == pos) dp[i + 1][(j + a) % d][0] += dp[i][j][0];
				else dp[i + 1][(j + a) % d][1] += dp[i][j][0];
			}
			for (int a = 0; a <= 9; a++) {
				dp[i + 1][(j + a) % d][1] += dp[i][j][1];
			}
		}
		for (int j = 0; j < d; j++)
			for (int k = 0; k < 2; k++)
				dp[i + 1][j][k] %= MOD;
	}
	ll ans = -1LL + dp[str.size()][0][0] + dp[str.size()][0][1];
	cout << (ans%MOD + MOD) % MOD << endl;
}



Measured memory_bytes: 16640
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    string s; cin >> s;
    int table[s.size()]; rep(i, s.size()) table[i] = 0;
    rrep(i, 1, s.size()) if (s[i - 1] == 'A' && s[i] == 'C') table[i] = 1;
    rrep(i, 1, s.size()) table[i] += table[i - 1];
    rep(i, q) {
        int l, r; cin >> l >> r; l--; r--;
        cout << table[r] - table[l] << endl; //lがCで加算されても引かなあかん
    }
    
}


Measured memory_bytes: 1488
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k;
ll a,b;
multiset<pair<ll,ll> > num;
multiset<pair<ll,ll> > ::iterator iter;
int main(){
	
    cin>>n>>k;
    for(int i=1;i<=n;i++)  
    {
	    cin>>a>>b;
	   num.insert(make_pair(a,b));
	}
  ll sum=0;
  for(iter=num.begin();iter!=num.end();iter++)
      {
      	 sum+=iter->second;
      	 if(sum>=k)
      	   return 0*printf("%d\n",iter->first);
      }
  
	return 0;
}

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

int n,a[300010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	int ans=0ll;
	for(int i=1;i<=60;i++){
		int cnt=0;
		for(int j=1;j<=n;j++) if(a[j]&(1ll<<(i-1))) cnt++;
		ans=ans+(((1ll<<(i-1))%MOD)*((cnt*(n-cnt))%MOD))%MOD;
		if(ans>=MOD) ans-=MOD;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2560
from itertools import permutations

n, c = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(c)]
cmat = [list(map(int, input().split())) for _ in range(n)]

dcnt = [[0] * c for _ in range(3)]
for i in range(n):
    for j in range(n):
        mod = (i + j) % 3
        dcnt[mod][cmat[i][j] - 1] += 1

ans = 10 ** 9
for color in permutations(range(c), 3):
    tmp = 0
    for tgt, cnt in zip(color, dcnt):
        tmp += sum(d[i][tgt] * cnt[i] for i in range(c))
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 76620
#include <stdio.h>

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

    unsigned long p = 1;
    for (int i = 1; i <= n; i++) {
        p = (p * i) % (1000000000 + 7);
    }

    printf("%lu\n", p);

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		int point1 = 0;
		int point2 = 0;

		for(int i = 0;i < count;i++) {
			String card1 = sc.next();
			String card2 = sc.next();
			if(card1.compareTo(card2) > 0){
				point1 += 3;
			} else if (card1.compareTo(card2) < 0) {
				point2 += 3;

			} else {
				point1 += 1;
				point2 += 1;
			}

		}
		System.out.println(point1 + " " + point2);



	}
}

Measured memory_bytes: 29220
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],time=0;

void visit(int u)//頂点への訪問
{
  int v;
  color[u] = GRAY;
  d[u] = ++time;
  for(v=0;v<n;v++)//Sが空でない時
  {
    if(M[u][v] == 0)continue;
    if(color[v] == WHITE)visit(v);
  }
  color[u] = BLACK;
  f[u]= ++time;
}

void dfs()//深さ優先検索
{
  int u;
  for(u=0; u<n ;u++)color[u] = WHITE;
  time = 0;
  for(u=0; u<n ;u++) if( color[u] == WHITE ) visit(u);
  for(u=0; u<n ;u++) printf("%d %d %d\n",u+1,d[u],f[u]);
}

int main()
{
  int i,j,k,u,v;
  scanf("%d",&n);
  for(i=0; i<n; i++)
  {
    for(j=0; j<n; j++)M[i][j] = 0;
  }

  for(i=0; i<n; i++)
  {
    scanf("%d %d",&u,&k);
    u--;
    for(j=0; j<k; j++)
    {
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }
  dfs();

  return 0;
}



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

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

    bool judge=true;

    if(s.size()!=a+b+1){
        judge=false;
    }else if(s.at(a)!='-'){
        judge=false;
    }

    for(int i=0; i<a+b+1; i++){
        if(i==a){
            if(s.at(i)!='-'){
                judge=false;
            }
        }else{
            if(s.at(i)=='-'){
                judge=false;
            }
        }
    }
    
    cout<<(judge==true ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
double n,i,t,c=-1,a,b,sum,x,y;
int main()
{
    cin>>n;
    if(int(n)%1000!=0)
    {
        c=ceil(n/1000);
        t=c*1000;
    }
    else
        t=n;
    cout<<t-n;


}


Measured memory_bytes: 3904
#include<iostream>
#include<vector>
#include<set>
using namespace std;
#define ll long long

int main(){
  ll N;
  cin >> N;
  
  ll S[N][N];
  vector<ll> E[N];
  for(ll i=0; i<N; ++i){
    string s;
    cin >> s;    
    for(ll j=0; j<N; ++j) {
      S[i][j] = s[j]=='1' ? 1 : 0;
      if(S[i][j]==1) { E[i].emplace_back(j); }
    }
  }

  // for(ll i=0; i<N; ++i){
  //   for(ll j=0; j<N; ++j) cout << S[i][j] << " ";
  //   cout << endl;
  // }
  // for(ll i=0; i<N; ++i){
  //   for(auto itr = E[i].begin(); itr!=E[i].end(); ++itr) cout << (*itr) << " ";
  //   cout << endl;
  // }

  ll max_size = -1;
  ll dist[N];
  for(ll start=0; start<N; ++start){
    for(int i=0; i<N; ++i) dist[i]=-1;
    dist[start]=0;
    set<ll> queue = {start};
    ll d=1;
    ll conflict=0;
    
    while(queue.size()>0 && conflict==0){
      set<ll> queue_new;
      for(auto itr_par=queue.begin(); itr_par!=queue.end(); ++itr_par){
        vector<ll>& edge = E[*itr_par];
        for(auto itr_chi = edge.begin(); itr_chi!=edge.end(); ++itr_chi){
          
          if(dist[*itr_chi]==dist[*itr_par]){ conflict=1; break; }
          if(dist[*itr_chi]==-1){
            dist[*itr_chi]=d;
            queue_new.emplace(*itr_chi);
          }
        }
        if(conflict==1) break;
      }
      queue = queue_new;
      ++d;
    }

    if(conflict==0) max_size = max(d, max_size);
    
  }

  cout << (max_size==-1? -1:  max_size-1) << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }
  vector<ll> m(n, -1);
  m[0] = 0;
  ll from = 0;
  ll to = -1;

  rep(i, k) {
    to = a[from];
    //cout << m[to] << endl;
    if (m[to] != -1) {
      ll cnt = k - m[from] - 1;
      cnt %= (m[from] - m[to] + 1);
      rep(j, n) {
        if (m[j] == m[to]+cnt) {
          to = j;
          break;
        }
      }
      break;
    }
    m[to] = m[from] + 1;
    //cout << from << " " << to << endl;
    from = to;
  }

  cout << to+1 << endl;;

  return 0;
}


Measured memory_bytes: 6372
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

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

    constexpr int cost[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    int dp[10100];
    int N, M;

    cin >> N >> M;

    vector<int> a(M);
    for (int i = 0; i < M; ++i) cin >> a[i];

    memset(dp, ~INF, sizeof(dp));
    dp[0] = 0;
    for (int i = 0; i <= N; ++i) {
        for (int n : a) chmax(dp[i + cost[n]], dp[i] + 1);
    }

    sort(ALL(a), greater<>());
    int rem = N;
    string ans;
    for (int i = 0; i < dp[N]; ++i) {
        for (int n : a) {
            if (rem - cost[n] < 0) continue;
            if (dp[rem] == dp[rem - cost[n]] + 1) {
                ans.push_back(n + '0');
                rem -= cost[n];
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;

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

  int n;
  cin >> n;
  cout << UPDight(n,2) << '\n';
    return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")

#include <bits/stdc++.h>
using namespace std;

template<class INT>
std::vector<INT> factorize(INT n){
    std::vector<INT> res;
    for (INT i = 1; i * i <= n; i++){
        if (n % i == 0){
            res.push_back(i);
            if (i * i != n)
                res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> A(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    auto F = factorize(accumulate(A.begin(), A.end(), 0));
    sort(F.begin(), F.end(), greater<int>());

    for (const auto &f: F){
        auto res = [&](const auto &f){
        vector<int> B(n);
        int border = 0;
        for (int i = 0; i < n; i++){
            B[i] = A[i] % f;
            border += min(B[i], f - B[i]);
            if (border > k + k)
                return false;
        }
        const auto S = accumulate(B.begin(), B.end(), 0);
        const auto i = S / f;
        nth_element(B.begin(), B.begin() + (n - i), B.end());
        if (max(accumulate(B.begin(), B.begin() + (n - i), 0), S - accumulate(B.begin() + (n - i), B.end(), 0)) <= k){
            return true;
        }}(f);

        if (res){
            printf("%d\n", f);
            return 0;
        }
    }

    puts("0");
}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = [int(i) for i in input().split()]
As = []
for i in range(N):
	As.append([int(j) for j in input().split()])
cnt = 0
for item in As:
	res = 0
	for idx, elem in enumerate(item):
		res += elem * B[idx]
	res += C
	if res > 0:
		cnt += 1
print(cnt)


Measured memory_bytes: 3060
class Dice
	def initialize(array)
		@data = array
	end
	
	def move(dir)
		case dir.downcase
		when "e"
			tmp=@data[0]
			@data[0]=@data[3]
			@data[3]=@data[5]
			@data[5]=@data[2]
			@data[2]=tmp
		when "n"
			tmp=@data[0]
			@data[0]=@data[1]
			@data[1]=@data[5]
			@data[5]=@data[4]
			@data[4]=tmp
		when "s"
			tmp=@data[0]
			@data[0]=@data[4]
			@data[4]=@data[5]
			@data[5]=@data[1]
			@data[1]=tmp
		when "w"
			tmp=@data[0]
			@data[0]=@data[2]
			@data[2]=@data[5]
			@data[5]=@data[3]
			@data[3]=tmp
		end
	end
	
	def rotate
		tmp=@data[1]
		@data[1]=@data[2]
		@data[2]=@data[4]
		@data[4]=@data[3]
		@data[3]=tmp
	end
	
	def top
		return @data[0]
	end
	
	def front
		return @data[1]
	end
	
	def left
		return @data[3]
	end
	
	def right
		return @data[2]
	end
	
	def back
		return @data[4]
	end
	
	def bottom
		return @data[5]
	end
end

array = gets.chomp.split(" ").map(&:to_i)
dice = Dice.new(array)
q = gets.chomp.to_i

q.times{
    data = gets.chomp.split(" ").map(&:to_i)
	if dice.top == data[0]
	elsif dice.front == data[0]
		dice.move("N")
	elsif dice.left == data[0]
		dice.move("E")
	elsif dice.right == data[0]
		dice.move("W")
	elsif dice.back == data[0]
		dice.move("S")
	elsif dice.bottom == data[0]
		dice.move("N")
		dice.move("N")
	end
	
	while dice.front != data[1]
		dice.rotate
	end
	
	puts dice.right
}

Measured memory_bytes: 8756
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

struct UnionFind {
  vector<int> par, rank, sz;
  UnionFind(int n) {
    par.assign(n, 0);
    rank.assign(n, 0);
    sz.assign(n, 1);
    for (int i = 0; i < n; i++) { par[i] = i; }
  }
  int find(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
      sz[y] += sz[x];
    } else {
      par[y] = x;
      sz[x] += sz[y];
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
};

void solve() {
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) { chmax(ans, uf.sz[uf.find(i)]); }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 5532
#include <stdio.h>
int main(void){
	int a[10],b[10],c,d,i,j,k,n,m;
	for(i=1;i<=6;i++)
		scanf("%d",&a[i]);
	scanf("%d",&d);
	for(i=0;i<d;i++){
		scanf("%d %d",&n,&m);
		for(k=1;k<=6;k++)
			b[k] = a[k];
		for(j=0;j<4;j++){	/*tate idou*/
			if(b[1]==n)
				break;
			c = b[1];
			b[1] = b[2];
			b[2] = b[6];
			b[6] = b[5];
			b[5] = c;
		}
		while(1){		/*tate(1ga yokoniarutoki) idou*/
			if(b[1]==n)
				break;
			c = b[1];
			b[1] = b[3];
			b[3] = b[6];
			b[6] = b[4];
			b[4] = c;
		}
		while(1){		/*yoko idou*/
			if(b[2]==m)
				break;
			c = b[2];
			b[2] = b[3];
			b[3] = b[5];
			b[5] = b[4];
			b[4] = c;
		}
		printf("%d\n",b[3]);
	}
	return 0;
}			
	

Measured memory_bytes: 596
#include <cassert>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <cstdalign>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <exception>
#include <initializer_list>
#include <limits>
#include <new>
#include <stdexcept>
#include <string>
#include <system_error>
#include <typeinfo>

#if __has_include(<string_view>)
#include <string_view>
#endif

#include <algorithm>
#include <array>
#include <cfenv>
#include <cmath>
#include <deque>
#include <forward_list>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#if __has_include(<filesystem>)
#include <filesystem>
#endif

#include <cinttypes>
#include <cstdio>

#include <atomic>
#include <condition_variable>
#include <future>
#include <mutex>
#include <regex>
#include <shared_mutex>
#include <thread>

using namespace std;
using namespace std::literals;
int main()
{
    int n;
    cin >> n;
    string S;
    cin >> S;

    auto half = S.substr(0, n / 2);
    if (half + half == S)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip()

def main():
  n,m,k = map(int, input().split())
  a = list(map(int, input().split()))
  b = list(map(int, input().split()))
  sa = np.cumsum([0]+a)
  sb = np.cumsum([0]+b)
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  print(rx)

if __name__ == '__main__':
    main()

Measured memory_bytes: 58028
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
map<P,int> ans;

int main(){
    int n;
    cin>>n;
    vector<vector<int> > G(n);
    vector<int> a(n-1),b(n-1);
    for(int i=0;i<n-1;i++){
        cin>>a[i]>>b[i];
        a[i]--; b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    queue<P> q;
    vector<bool> used(n,false);

    q.push(P(0,0));
    int color=0;

    while(!q.empty()){
        int u=q.front().first; 
        int kinsi=q.front().second;  
        q.pop();
        used[u]=true;
        color=max(color,(int)G[u].size());

        int c=1;
        for(int v:G[u]){
            if(!used[v]){
                if(kinsi==c) c++;
                ans[P(u,v)]=c;
                q.push(P(v,c));
                c++;
            }
        }
    }

    cout<<color<<endl;

    for(int i=0;i<n-1;i++){
        cout<<ans[P(a[i],b[i])]<<endl;
    }

}

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

int main(){
  int shft;
  cin>>shft;
  string x;
  cin>>x;
  vector <char> v(x.length());
  copy(x.begin(), x.end(), v.begin());
  for(int i = 0; i < x.length(); i++){
    char c = v[i];
    int a = (int)c;
    int b = (((a - 65) + shft) % 26) + 65;
    cout<<(char)b;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdlib>
using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;

bool ok(ll a, ll b, ll c) {
    ll sa = llabs(a - b);
    ll wa = a + b;
    return (sa < c) && (c < wa);
}

int main() {
    int n;
    cin >> n;
    ll l[n];
    for(int i = 0; i < n; i++) cin >> l[i];
    sort(l, l + n);


    ll ans = 0;
    for(int i = 0; i < n - 2; i++) {
        for(int j = i + 1; j < n - 1; j++) {
            for(int k = j + 1; k < n; k++) {
                if(ok(l[i], l[j], l[k])) ans++;
                else break;
            }
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
int64_t INF = 1000000007;
// int64_t INF = 9223372036854775807;
// int64_t INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll x;
    cin >> x;
    ll step = 0;
    ll res = 0;
    ll time = 0;
    for(ll i=1; i<INF; i++){
        step += i;
        time++;
        if(step>=x){
            res = time;
            break;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-x))
#define f(i,x,y) for(int i=(x);i<=(y);i++)
#define r(i,x,y) for(int i=(x);i>=(y);i--)
#define ll long long
using namespace std;//head

int n;
int main(){
	cin>>n;
	if(n%2==0)cout<<n/2;
	else cout<<n/2+1;
	return 0;
}

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

typedef long long ll;

using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
//  --------------------------------------

	int N; cin >> N;
	int A[110], B[110];
	for (int i = 0; i < N-1; i++)
	{
		cin >> B[i];
	}
	
	int ans = B[0];

	for (int i = 1; i < N-1; i++)
	{
		if (B[i] > B[i-1])
		{
			ans += B[i-1];
		}
		else
		{
			ans += B[i];
		}
		
	}
	ans += B[N-2];

	cout << ans << "\n";
	

}

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

long long mod=1000000007LL;

template<typename T>
constexpr T modpow(T a,T n){//(a^n)%MOD
    T ret=1;
    while(n>0){
        if((n&1)!=0){//n%2==1
            ret=ret*a%mod;
        }
        a=a*a%mod;
        n=n/2;
    }
    return ret;
}


std::vector<long long> fac;
std::vector<long long> ifac;


void combinit(int maxn){
    fac.resize(maxn);
    ifac.resize(maxn);
    fac[0] = 1;
    ifac[0] = 1;
    for(long long i = 0; i<maxn; i++){
        fac[i+1] = fac[i]*(i+1) % mod;
        ifac[i+1] = ifac[i]*modpow(i+1, mod-2) % mod;
    }
}


template <typename T>
T modcomb(T a, T b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    long long tmp = 1;
    for (long long i = 0; i < b; ++i) {
        tmp*=a-i;
        tmp%=mod;
    }


    return tmp * ifac[b] % mod;
}

using namespace std;
using ll=long long;

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    combinit(200000);
    ll ans=modpow(2LL,n);
    --ans;
    if(ans<0)ans+=mod;
    ans-=modcomb(n,a);
    if(ans<0)ans+=mod;
    ans-=modcomb(n,b);
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N+1);
  vector<int> b(N+1, 0);
  vector<int> res;
  for (int i = 1; i < N+1; i++) cin >> a[i];
  for (int i = N; i > 0; i--) {
    int tmp = 0;
    for (int j = i; j <= N; j+=i) {
      tmp += b[j];
    }
    if (tmp % 2 != a[i]) {
      b[i]++;
      res.push_back(i);
    }
  }
  reverse(res.begin(), res.end());
  cout << res.size() << endl;
  for (auto x: res) cout << x << " ";
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin>>N;
    int A[N];
    map<int,int> m;
    rep(i,N){
        cin>>A[i];
        m[A[i]]++;
    }
    int co=0;
    for(auto p:m){
        co++;
    }
    int ans=0;
    if(co%2==0){
        ans=co-1;
    }else ans=co;
    cout << ans << endl;




}


Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N,K; cin >> N >> K;
    vector<int> p(N);
    for(int i=0;i<N;i++){
        cin >> p[i];
    }
    sort(p.begin(),p.end());
    int out=0;
    for(int i=0;i<K;i++){
        out += p[i];
    }
    cout << out << endl;
    
    return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
unsigned a,n,c;
inline bool isp(unsigned a){
    if(a==2)return true;
    for(int i=2;i*i<=a;++i)if(a%i==0)return false;
    return true;
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d",&a);
        if(isp(a))++c;
    }
    printf("%d\n",c);
    return 0;
}


Measured memory_bytes: 2628
N, M = list(map(int, input().split()))

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

L = [0] * (N + 2)

for l, r in LR:
  L[l] += 1
  L[r + 1] -= 1

Ans = 0
for i in range(1, N + 1):
  L[i] += L[i - 1]
  if L[i] >= M:
    Ans += 1

print(Ans)

Measured memory_bytes: 31300
n, t = gets.chomp.split.map(&:to_i)
tmin = 1000
cmin = 1000

n.times do |i|
  a, b = gets.chomp.split.map(&:to_i)
  if a <= cmin && b <= t
    cmin = a
    tmin = b
  end
end
puts tmin <= t ? cmin : 'TLE'


Measured memory_bytes: 1788
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int main()
{
  int a,b;
  cin >> a >> b;
  if(a+b == 15)
    cout << "+" << endl;
  else if(a*b == 15)
    cout << "*" << endl;
  else
    cout << "x" << endl;
  return 0;
}


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

int a[3007] = {};
LLI dp[3007][3007] = {};

int main() {
	
	int i,j;
	int N;
	
	cin >> N;
	for( i=1; i<=N; i++)
		cin >> a[i];
	
	
	int flag = N&1;
	if( flag) {
		for( i=1; i<=N; i++)
			dp[i][i] = a[i];
	}
	else {
		for( i=1; i<=N; i++)
			dp[i][i] = -a[i];
	}
	flag = !flag;
	for( i=2; i<=N; i++, flag = !flag) {
		for( j=1; j+i-1<=N; j++) {
			if( flag)
				dp[j][j+i-1] = max( dp[j+1][j+i-1] + a[j], dp[j][j+i-2] + a[j+i-1]);
			else
				dp[j][j+i-1] = min( dp[j+1][j+i-1] - a[j], dp[j][j+i-2] - a[j+i-1]);
		}
	}
	
	printf("%lld\n", dp[1][N]);
	
	return 0;
}

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

long long int prime(long long int x) {
	long long int sq = sqrt(x) ;
	bool ok = true ;
	for(int i = 2 ; i < sq ; i ++){
		if(x%i == 0 ){
			ok = false ;
			break ;
		}
	}
	if(ok) return x ;
	else return prime(x+1) ;
}

int main(){
	long long int x ;
	cin >> x;
	
	cout << prime(x) << endl ;
	
	return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
vector <vector <ll> >dp;
vector <ll> input,sum;

ll func(ll start,ll end)
{
    if(start == end)
        return 0;
    if(dp[start][end] != -1)
        return dp[start][end];
    ll result = LLONG_MAX;
    for(ll k = start;k<end;k++)
    {
        result = min(result,func(start,k)+sum[end]-sum[start-1]+func(k+1,end));
    }
    return dp[start][end] = result;
}
int main()
{
    ll n;cin>>n;
    input.clear();
    sum.clear();
    input.resize(n+1),sum.resize(n+1,0);
    dp.clear();
    dp.resize(n+1,vector <ll> (n+1,-1));
    for(ll i=1;i<=n;i++)
    {
        cin>>input[i];
        sum[i] = sum[i-1]+input[i];
    }
    cout<<func(1,n);
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Mar 28 21:00:08 JST 2020
 **/

signed main() {
    Int X, Y, A, B, C;
    std::cin >> X >> Y >> A >> B >> C;
    std::vector<Int> p(A), q(B), r(C);
    REP(i, A) std::cin >> p[i];
    REP(i, B) std::cin >> q[i];
    REP(i, C) std::cin >> r[i];
    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    REP(i, X) r.push_back(p[i]);
    REP(i, Y) r.push_back(q[i]);
    sort(r.rbegin(), r.rend());
    std::cout << std::accumulate(r.begin(), r.begin() + X + Y, 0LL) << std::endl;
}


Measured memory_bytes: 6384
from collections import deque

S = list(input())
d = deque(S)
# print (d)

import sys
input = sys.stdin.readline

Q = int(input())
flag = True #向きの保持　Trueで順
for _ in range(Q):
    tmp = tuple(input())
    if len(tmp) == 2:
        flag = not flag
    else:
        if flag:
            if tmp[2] == '1':
                d.appendleft(tmp[4])
            else:
                d.append(tmp[4])
        else:
            if tmp[2] == '2':
                d.appendleft(tmp[4])
            else:
                d.append(tmp[4])

if flag:
    print (*d, sep = '')
else:
    d.reverse()
    print (*d, sep = '')

Measured memory_bytes: 13040
import sys
input = sys.stdin.readline
ri = lambda: int(input())
#rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

#nCr % MOD
def cmb(n, r, MOD=0):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
 
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
 
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
 
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
            if MOD != 0:
                result %= MOD
 
    return result

N,K=rl()
R = N-K

ans = 0
for i in range(1,K+1):
    if R+1 >= i:
        print(cmb(R+1,i,MOD)*cmb(K-1,i-1,MOD)%MOD)
    else:
        print(0)

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

struct Ac
{
    int x,y;
} ac[111];

struct Bc
{
    int x,y;
} bc[111];

int vis[222][222];
int flag[222];
int pri[222];
int n;

bool _find(int i)
{
    int j;
    for(j=1; j<=n; j++)
    {
        if(vis[ac[i].x][bc[j].x]&&!flag[j])
        {
            flag[j]=1;
            if(pri[j]==-1||_find(pri[j]))
            {
                pri[j]=i;
                return true;
            }
        }
    }
    return false;
}

int main()
{
    scanf("%d",&n);
    memset(vis,0,sizeof(vis));
    memset(pri,-1,sizeof(pri));
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&ac[i].x,&ac[i].y);
    }
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&bc[i].x,&bc[i].y);
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(ac[i].x<bc[j].x&&ac[i].y<bc[j].y)
            {
                vis[ac[i].x][bc[j].x]=1;
            }
        }
    }
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        memset(flag,0,sizeof(flag));
        if(_find(i))
            ans+=1;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int cnt[100001];

int main()
{
	int n;
	cin >> n;
	for(int i =0;i<n;i++)
	{
		int x;
		cin >> x;
		cnt[x]++;
	}
	bool j = false;
	for(int i =0;i<100001;i++)
	{
		while(cnt[i])
		{
			if(j)cout<<' ';
			cout<<i;
			cnt[i]--;
			j =1;
		}
	}
	cout<<endl;
	return 0;
}


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

int h,w;
char a[1003][1003];
long long int dp[1003][1003];

long long int grid(int m,int n){

	if(m==h && n==w){
		return 1;
	}
	if(a[m][n] == '#' || m>h || n>w){
		return 0;
	}
	if(dp[m][n]!=-1){
		return dp[m][n];
	}
	else{
		return dp[m][n] = (grid(m,n+1)+grid(m+1,n))%1000000007;
	}
}

int main(){

	cin>>h>>w;
	for(int i=0;i<1003;i++)
		for(int j=0;j<1003;j++)
			dp[i][j]=-1;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			cin>>a[i][j];

	cout<<grid(1,1)%1000000007<<endl;
	return 0;
}

Measured memory_bytes: 9216
// 模範解答

#include <iostream>
#include <vector>
using namespace std;

const int MAX = 1000100;
const int INF = 1<<29;

int main() {
    vector<int> dp(MAX, INF), odddp(MAX, INF);
    dp[0] = odddp[0] = 0;
    for (int i = 1;; ++i) {
        int num = i * (i+1) * (i+2) / 6;
        if (num >= MAX) break;
        for (int j = num; j < MAX; ++j) {
            dp[j] = min(dp[j], dp[j-num]+1);
            if (num & 1) odddp[j] = min(odddp[j], odddp[j-num]+1);
        }
    }
    int n;
    while (cin >> n) {
        if (n == 0) break;
        cout << dp[n] << " " << odddp[n] << endl;
    }
}


Measured memory_bytes: 10508
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i= x;i<n;i++)

int main()
{
    ll n;
    cin>>n;
    unordered_set<string> ans;
    loop(i,0,n){
        string s;
        cin>>s;
        ans.insert(s);
    }
    cout<<ans.size()<<endl;
}

Measured memory_bytes: 17788
#include <iostream>
#include <queue>
#define pll pair<ll,ll>
#define NMAX 1000006
#define eps 1e-12

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

char a[1005][1005];
ll val[1005][1005];
queue<pll> q;
ll n,m;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
bool inside(int x,int y)
{
    if(x<1 || y<1 || x>n || y>m) return 0;
    return 1;
}
int main()
{
    ll i,j,ans=0;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            cin>>a[i][j];
            if(a[i][j]=='#')
            {
                q.push({i,j});
                val[i][j]=0;
            }
        }
    }
    ans=0;
    while(!q.empty())
    {
        i=q.front().first;
        j=q.front().second;
        ans=max(ans,val[i][j]);
        q.pop();
        for(int d=0;d<4;d++)
        {
            int x=i+dx[d];
            int y=j+dy[d];
            if(inside(x,y) && a[x][y]!='#' && val[x][y]==0)
            {
                val[x][y]=val[i][j]+1;
                q.push({x,y});
            }
        }
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 24832
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef ONPC
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main()
{
#ifdef ONPC
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector <int> a(n);
  for (int &x : a) cin >> x;
  vector <int> dp(n);
  auto f = [&] (int i, int x)
  {
    if (i < 0) return 0;
    if (a[i] == x)
    {
      return dp[i];
    }
    else
    {
      return 0;
    }
  };
  map <int, int> ans;
  int mod = 1e9 + 7;
  for (int i = 0; i < n; i++)
  {
    if (i == 0)
    {
      dp[i] = 1;
      ans[a[i]] = 1;
    }
    else
    {
      ans[a[i]] += (dp[i - 1] - f(i - 1, a[i]) + mod) % mod;
      ans[a[i]] %= mod;
      dp[i] = ans[a[i]];
    }
  }
  cout << dp[n - 1] << '\n';
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ul>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size())cout << v[i]<<" "
const double h = 1e-6;
const int MAX_  = 200005;
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
ll sqr(ll x)
{
    return x*x;
}
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;  cin>>n>>k;
    string str;  cin>>str;
    str[k-1] += 32;
    cout << str;

       
    return 0;
}
    


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

int main(){
    string s;
    cin>>s;

    bool north=false;
    bool south=false;
    bool east=false;
    bool west=false;

    bool judge=true;

    for(int i=0; i<s.size(); i++){
        if(s[i]=='N'){
            north=true;
        }
        if(s[i]=='S'){
            south=true;
        }
        if(s[i]=='E'){
            east=true;
        }
        if(s[i]=='W'){
            west=true;
        }
    }

    if((north&&south==false)||(north==false&&south)){
        judge=false;
    }else if((east&&west==false)||(east==false&&west)){
        judge=false;
    }

    cout<<(judge ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int main(){
  int K,N,L[50];
  scanf("%d %d",&N,&K);
  for(int i=0;i<N;i++) scanf("%d",&L[i]);
  sort(L,L+N);
  int ans=0;
  for(int i=N-1;i>N-1-K;i--) ans+=L[i];
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128