akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>

using namespace std;

const int INF = (1<<30) - 1;

int gcd(int a, int b){
    return b ? gcd(b, a%b) : a;
}

class BipartiteGraph{
private:
    int lV, rV;
    int V;
    vector<vector<int> > G;
    vector<int> match;
    vector<bool> used;
    
    bool dfs(int v){
        used[v] = true;
        for(int i=0; i<G[v].size(); i++){
            int u = G[v][i], w = match[u];
            if(w < 0 || (!used[w] && dfs(w))){
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }
public:
    BipartiteGraph(int _lV, int _rV): lV(_lV), rV(_rV){
        V = rV + lV;
        G.resize(V);
        match.resize(V);
        used.resize(V);
    }
    
    void add_edge(int l, int r){
        r += lV;
        G[l].push_back(r);
        G[r].push_back(l);
    }
    
    int max_matching(){
        fill(match.begin(), match.end(), -1);
        int res = 0;
        for(int i=0; i<lV; i++){
            if(match[i] < 0){
                fill(used.begin(), used.end(), false);
                res += dfs(i);
            }
        }
        return res;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, M;
    while(cin>>N>>M, N|M){
        vector<int> blues(N);
        vector<int> reds(M);
        for(auto &b: blues)
            cin >> b;
        for(auto &r: reds)
            cin >> r;
        
        auto bipartite_graph = BipartiteGraph(N, M);
        for(int i=0; i<N; i++)
            for(int j=0; j<M; j++)
                if(gcd(blues[i], reds[j]) != 1)
                    bipartite_graph.add_edge(i, j);
        
        cout << bipartite_graph.max_matching() << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2716
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
map<int,int>:: iterator it;
set<int>st;
set<int>::iterator it1;

int main()
{
    int  i,j,n,t,a,c=0;
    string s,s1;
    cin>>s>>s1;
    for(i=0;i<s.size();i++)
    {
        if(s[i]==s1[i])
            continue;
        else
            c++;

    }
    cout<<c<<"\n";

return 0;
}



Measured memory_bytes: 3924
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int h,w,n,sr,sc,a[200005],b[200005],c[200005],i,j,k,x,y;
char s[200005],t[200005];
int main()
{
	scanf("%d%d%d",&h,&w,&n);
	scanf("%d%d",&sr,&sc);
	scanf("%s%s",s+1,t+1);
	for(i=1,j=k=sc;i<=n;++i)
	{
		if(s[i]=='L')
			a[i]=-1;
		else if(s[i]=='R')
			a[i]=1;
		else
			a[i]=0;
		if(t[i]=='L')
			b[i]=-1;
		else if(t[i]=='R')
			b[i]=1;
		else
			b[i]=0;
		if(a[i]==-1)
			--j;
		else if(a[i]==1)
			++k;
		if(j<1||k>w)
		{
			printf("NO");
			return 0;
		}
		if(b[i]==-1)
			--k;
		else if(b[i]==1)
			++j;
		if(k<1)
			++k;
		if(j>w)
			--j;
	}
	for(i=1,j=k=sr;i<=n;++i)
	{
		if(s[i]=='U')
			a[i]=-1;
		else if(s[i]=='D')
			a[i]=1;
		else
			a[i]=0;
		if(t[i]=='U')
			b[i]=-1;
		else if(t[i]=='D')
			b[i]=1;
		else
			b[i]=0;
		if(a[i]==-1)
			--j;
		else if(a[i]==1)
			++k;
		if(j<1||k>h)
		{
			printf("NO");
			return 0;
		}
		if(b[i]==-1)
			--k;
		else if(b[i]==1)
			++j;
		if(k<1)
			++k;
		if(j>h)
			--j;
	}
	printf("YES");
	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define db long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 1000000007
    

  int gcd(int a,int b)
  {
    if(b==0)
    {
      return a;
    }
    return gcd(b,a%b);
  }

  bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
  {

    if(a.s==b.s)
    {
      return a.f<b.f;
    }
    return a.s<b.s;
  }
  int32_t main()
  {         
    
  

      IOS

      
      int a,b,c;
      cin>>a>>b>>c;
      cout<<min((b/a),c);
      return 0;
  }           

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int n, m, a, b;

vector<int> G[200005], ans(200005);
bool vis[200005];

int main() {
  cin >> n >> m;
  rep(i, m) {
    cin >> a >> b, a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  queue<int> q;
  q.push(0);
  vis[0] = true;

  while (q.size()) {
    int num = q.front();
    q.pop();
    for (auto to : G[num])
      if (!vis[to]) {
        ans[to] = num;
        vis[to] = true;
        q.push(to);
      }
  }

  cout << "Yes" << endl;
  for (int i = 1; i < n; ++i) cout << ans[i] + 1 << endl;
  return 0;
}


Measured memory_bytes: 13108
#include<cstdio>
#include<algorithm>
struct node{
	int val,id;
	friend bool operator <(node a,node b){return a.val<b.val;}
}ton1[100050],ton2[100050];
int num[100050];
int main(){
	int n,a;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&num[i]);
		(i&1)?(++ton1[num[i]].val):(++ton2[num[i]].val);
	}
	for(int i=1;i<=100000;i++){
		ton1[i].val=n/2-ton1[i].val;ton1[i].id=i,
		ton2[i].val=n/2-ton2[i].val;ton2[i].id=i;
	}
	std::sort(ton1+1,ton1+100001);
	std::sort(ton2+1,ton2+100001);
	
	printf("%d\n",(ton1[1].id!=ton2[1].id)?(ton1[1].val+ton2[1].val):(std::min(ton1[1].val+ton2[2].val,ton1[2].val+ton2[1].val)));
	return 0;
}

Measured memory_bytes: 2176
#アライさんの必殺技は殺人タックルなのだ！！ パークの危機なのだ！！
H,N = gets.strip.split.map(&:to_i)
num = gets.strip.split.map(&:to_i)
if H <= num.sum then
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  bool A = true;
  string X = S.substr(0,(S.size()-1)/2);
  string Y = S.substr((S.size()+3)/2-1,(S.size()-1)/2);
  
  for(int i=0;i<=(S.size()-1)/2;i++){
    if(S.at(i) != S.at(S.size()-i-1)){
      A = false;
      break;
    }
  }
  
  for(int i=0;i<=(X.size()-1)/2;i++){
    if(X.at(i) != X.at(X.size()-i-1)){
      A = false;
      break;
    }
  }
  
  for(int i=0;i<=(Y.size()-1)/2;i++){
    if(Y.at(i) != Y.at(Y.size()-i-1)){
      A = false;
      break;
    }
  }
  if(A == true){
    cout << "Yes" << endl;
  }
  else{
    cout <<"No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int N;
long long W, weight[110], value[110];
long long dp[110][100100] = {0};

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    for (int i = 0; i < N; i++) {
        for (int sum_w = 0; sum_w <= W; sum_w++) {

            if (sum_w - weight[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    cout << dp[N][W] << endl;
}

Measured memory_bytes: 81596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int a,b; cin >> a >> b;
    if((a*b)%2 == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<vector>
typedef long long ll;
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
char a[1010][1010];
int mn[1010][1010];
int dx[5]={0,0,1,-1};
int dy[5]={1,-1,0,0};
int n,m;
int check(int x,int y,int k){
	if(x<0||y<0||x>=n||y>=m)return 0;
	return a[x][y]=='.'&&mn[x][y]>k;
}
queue<pii>Q,T;
int main(){
	int i,j,x1,y1,x2,y2;
	memset(mn,0x3f,sizeof(mn));
	scanf("%d%d%d%d%d%d",&n,&m,&x1,&y1,&x2,&y2);
	x1--,x2--,y1--,y2--;
	for(i=0;i<n;i++)scanf("%s",a[i]);
	mn[x1][y1]=0;
	T.push(mp(x1,y1));
	while(!T.empty()){
		int x=T.front().fi,y=T.front().se;
		T.pop();
		Q.push(mp(x,y));
		while(!Q.empty()){
			int x=Q.front().fi,y=Q.front().se;
			Q.pop();
			int tx,ty,temp=mn[x][y];
			for(i=0;i<4;i++){
				tx=x+dx[i];
				ty=y+dy[i];
				if(check(tx,ty,temp)){
					mn[tx][ty]=temp;
					Q.push(mp(tx,ty));
					T.push(mp(tx,ty));
				}
			}
		}
		for(i=-2;i<=2;i++){
			for(j=-2;j<=2;j++){
				int tx,ty,temp=mn[x][y];
				tx=x+i;
				ty=y+j;
				if(check(tx,ty,temp+1)){
					mn[tx][ty]=temp+1;
					T.push(mp(tx,ty));
				}
			}
		}
	}
	printf("%d",mn[x2][y2]>1e8?-1:mn[x2][y2]);
	return 0;
}

Measured memory_bytes: 8212
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bitset>
#include <math.h>

typedef long long ll;
typedef unsigned long long ull;

#define vi std::vector<int>
#define vl std::vector<ll>
#define floop(n) for(int i = 0; i < n; ++i)
#define print(x) std::cout << x << std::endl;

const ll INF = 1e18;

int main()
{
    int N, max=-1000, min=1000, res = 1000000, temp;
    std::cin >> N;
    vi A(N);

    floop(N)
    {
        std::cin >> A[i];
        if(max < A[i])
            max = A[i];
        if(min > A[i])
            min = A[i];
    }

    for(int i = min; i <= max; ++i)
    {
        temp = 0;
        for(int j = 0; j < N; ++j)
        {
            temp += ((A[j]-i)*(A[j]-i));
        }
        
        if(res > temp)
            res = temp;
    }

    print(res);
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
	int a, b,d, r;
	double f;

	scanf("%d%d", &a, &b);
	d = a / b;
	r = a % b;
	f = (double)a / b;
	printf("%d %d %lf\n", d, r, f);

	return 0;

}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define DEBUG
#define ll long long
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );
#define lli long long int

using namespace std;

int n, m, x, c, ans1, ans2;
bool used[150];

int main()
{
	cin >> n >> m >> x;
	for ( int i = 1; i <= m; i ++ ) {
		cin >> c;
		if ( c < x ) ans1 ++;
		else ans2 ++;
	}
	cout << min( ans1, ans2 );
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
int k, q, d[5678], d1[5678], dsum[5678], d0sum[5678];
signed main() {
	cin >> k >> q;
	for0(i, k)cin >> d[i];
	for1(valsqotch, q) {
		int n, x, m; cin >> n >> x >> m; x %= m;
		for0(i, k) {
			d1[i] = d[i] % m;
			if (!i) {
				dsum[0] = d1[0];
				d0sum[0] = (d1[0] == 0);
			}
			else {
				dsum[i] = dsum[i - 1] + d1[i];
				d0sum[i] = d0sum[i - 1]; if (d1[i] == 0)d0sum[i]++;
			}
		}
		x += dsum[k - 1] * ((n - 1) / k) + dsum[(n - 1) % k - 1];
		cout << n - 1 - x / m - (d0sum[k - 1] * ((n - 1) / k) + d0sum[(n - 1) % k - 1]) << endl;
	}
}

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

const int M = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> cnt(M);
  for (int x : a) {
    if (cnt[x] != 0) {
      cnt[x] = 2;
      continue;
    }
    for (int i = x; i < M; i += x) cnt[i]++;
  }
  int ans = 0;
  for (int x : a) {
    if (cnt[x] == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8000
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;

int n, k;
vector<vector<int>> g(4000, vector<int>());

int cnt(int cur, int prev)
{
    // cout << cur << ", " << prev << endl;

    int ret = 1;
    for (auto &n: g[cur]) {
        if (n == prev) continue;
        ret += cnt(n, cur);
    }
    return ret;
}

int solve(int cur, int prev, int dep)
{
    // cout << cur << ", " << prev << ", " << dep << endl;

    if (dep <= 0) {
        return cnt(cur, prev);
    }

    int ans = 0;

    for (int i = 0; i < (int)g[cur].size(); i++) {
        if (g[cur][i] == prev) continue;
        ans += solve(g[cur][i], cur, dep - 1);
    }

    return ans;
}

int main()
{
    cin >> n >> k;
    g.resize(n);

    for (int i = 0; i < n-1; i++) {
        int a, b; cin >> a >> b;
        a--, b--;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    int ans = n + 1;

    for (int center = 0; center < n; center++) {
        for (auto lng: g[center]) {
            int tmp = 0;
            for (auto root: g[center]) {
                tmp += solve(root, center, k / 2 + ((k % 2 == 1 && lng == root) ? 1 : 0));
            }
            // cout << center + 1 << " -> " << lng + 1 << ": " << tmp << endl;
            ans = min(ans, tmp);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3776
import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;
import std.numeric;

void main() {
  int n = readln.chomp.to!int;
  long sum = 0;
  for(int i=1; i<=n; i++) {
    if(!(i%3==0 || i%5==0)) sum += i;
  }
  writeln(sum);
}



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

bool isPalindrome(string& s, int l, int r) {
	while (l < r)
		if(s[l++] != s[r--])
			return false;

	return true;
}

int main() {

	string s;
	cin >> s;
	int n = s.length() - 1;

	if (!isPalindrome(s, 0, n)) {
		cout << "No" << endl;
		return 0;
	}

	if (!isPalindrome(s, 0, (n-1)/2) || !isPalindrome(s, (n+3)/2, n)) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
max = 0
maxlabel = 0
for i in range(n):
    if max < l[i]:
        max = l[i]
        maxlabel = i
l.pop(maxlabel)
sum = 0
for j in range(n-1):
    sum += l[j]
if max < sum:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int MAXN =  100005;

int n, k;
vector<int> adj[MAXN];
int p[MAXN];
vector<pair<int, int>> edge;

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

  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
    edge.emplace_back(u, v);
  }

  for (int i = 0; i < n; i++) {
    p[i] = 1e9;
  }

  vector<int> vis(n, 0);
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;

  cin >> k;
  for (int i = 0; i < k; i++) {
    int v;
    cin >> v; v--;
    cin >> p[v];
    pq.emplace(p[v], v);
    vis[v] = 1;
  }

  while (!pq.empty()) {
    int u = pq.top().second;
    pq.pop();

    for (auto &i : adj[u]) if (!vis[i]) {
      vis[i] = 1;
      p[i] = p[u] + 1;
      pq.emplace(p[i], i);
    }
  }

  for (auto &e : edge) {
    if (abs(p[e.first] - p[e.second]) != 1) {
      cout << "No\n";
      return 0;
    }
  }

  cout << "Yes\n";
  for (int i = 0; i < n; i++) {
    cout << p[i] << "\n";
  }

  return 0;
}


Measured memory_bytes: 9200
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int x,y,a[4];
    scanf("%d%d",&x,&y);
    for(int i=1; i<=3; i++)
        a[i]=0;
    a[x]=1,a[y]=1;
    for(int i=1; i<=3; i++)
        if(!a[i])
        {
            printf("%d",i);
            return 0;
        }
}


Measured memory_bytes: 256
//start:9:48
#include <bits/stdc++.h>
using namespace std;
int n,m;
const int N=2005;
const int inf=1e9;
int dp[N][N],dp2[N][N],f[3*N],d[3*N],mx;
void Max(int &x,int &y,int z){x=y=max(x,z);}
void upd(int a,int b,int c){
	for (int i=1;i<=n;i++){
		Max(dp2[i][a],dp2[a][i],max(f[i],dp[i][b]+(b==c)));
	}
	Max(dp2[a][b],dp2[b][a],max(mx,dp[c][c]+1));
}
void come(int a){
	for (int i=1;i<=n;i++){
		Max(dp[a][i],dp[i][a],dp2[i][a]);
		f[i]=max(f[i],max(dp[a][i],dp[i][a]));
		mx=max(mx,f[i]);
	}
}
void work(int a,int b,int c){
//	cout << a << ' ' << b << ' ' << c << endl;
	upd(a,b,c);upd(b,c,a);upd(c,a,b);
//	for (int i=1;i<=n;i++){
//		for (int j=1;j<=n;j++) cout << dp2[i][j] << ' ';cout << endl;
//	}cout << endl;
	come(a);come(b);come(c);
	for (int i=1;i<=n;i++){
		dp2[i][a]=dp2[i][b]=dp2[i][c]=dp2[a][i]=dp2[b][i]=dp2[c][i]=-inf;
	}
}
int main(){
//	freopen("i.in","r",stdin);
	cin >> n;for (int i=1;i<=n*3;i++) cin >> d[i];
	memset(dp,-10,sizeof(dp));memset(dp2,-10,sizeof(dp2));memset(f,-10,sizeof(f));
	dp[d[1]][d[2]]=dp[d[2]][d[1]]=f[d[1]]=f[d[2]]=0;
	for (int i=1;i<n;i++){
		if (d[3*i]==d[3*i+1] && d[3*i+1]==d[3*i+2]) m++;
		else work(d[3*i],d[3*i+1],d[3*i+2]);
//		for (int j=1;j<=n;j++){
//			for (int k=1;k<=n;k++) cout << dp[j][k] << ' ';cout << endl;
//		}cout << endl;
	}
	Max(mx,dp[d[3*n]][d[3*n]],dp[d[3*n]][d[3*n]]+1);
	cout << mx+m << endl;
	return 0;
}

Measured memory_bytes: 35092
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<functional>
#include<cassert>

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

int main(void) {
	unsigned long long int x, y;
	cin >> x >> y;
	int i = 1;
	while (((unsigned long long int)(x<<i)) <= y) {
		i++;
	}
	cout << i << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
int main()
{
    ll h, n;
    cin >> h >> n;
    ll a[n];
    rp(i, 0, n) cin >> a[i];
    ll sum = 0;
    rp(i, 0, n) sum += a[i];
    if (sum >= h)
        cout << "Yes";
    else
        cout << "No";
    cout << endl;
}

Measured memory_bytes: 1024
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (int)1000000007
#define DBLINF (DBL_MAX)/10
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline int gcd(int a, int b) {
	while (b) {
		int c = a;
		a = b; b = c % b;
	}
	return a;
}
inline int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
bool isprime(int n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
int mypow(int a, int b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	int memo = mypow(a, b >> 1);
	return memo * memo;
}
int modpow(int a, int b, int m = mod) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	int memo = modpow(a, b / 2, m);
	return memo * memo % m;
}
int h, w;
char c[310][310];
int dp[310][310];
int memo[310][310];
signed main() {
	cin >> h >> w;
	rep(i, h) {
		rep(j, w)cin >> c[i][j];
	}
	int ans = 0;
	rep(i, w - 1) {
		rep(j, h) {
			rep(k, h) {
				if (c[j][i] == c[k][i + 1])memo[j + 1][k + 1] = memo[j][k] + 1;
				else memo[j + 1][k + 1] = memo[j][k];
			}
		}
		rep(j, h + 1) {
			rep(k, h + 1)dp[j][k] = INF;
		}
		dp[h][h] = 0;
		for (int j = h; j >= 0; j--) {
			for (int k = h; k >= 0; k--) {
				chmin(dp[j - 1][k], dp[j][k] + memo[j][k]);
				chmin(dp[j][k - 1], dp[j][k] + memo[j][k]);
			}
		}
		ans += dp[0][0];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
# -*- coding:utf-8 -*-
A = []
bingo = 0
for i in range(3):
    a = list(map(int, input().split()))
    A.append(a)

n = int(input())

for i in range(n):
    b = int(input())
    for ai in A:
        if b in ai:
            ai[ai.index(b)] = None

for i in range(3):
    if A[i] == [None, None, None]:
        bingo = 1

    if [A[0][i], A[1][i], A[2][i]] == [None, None, None]:
        bingo = 1

if [A[0][0], A[1][1], A[2][2]] == [None, None, None] or [A[0][2], A[1][1], A[2][0]] == [None, None, None]:
    bingo = 1

print("Yes") if bingo == 1 else print("No")


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion

void solve() {
    string s;
    cin >> s;
    int n = (int)s.size();
    int ans = 0;

    int bound = n/2 - (n%2 == 0);
    for (int i=0; i<n; i++) {
        if (i <= bound) {
            if (s.at(i) == 'p') ans--;
        } else {
            if (s.at(i) == 'g') ans++;
        }
    }

    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }

int main() {
  int n,k; cin >>n >>k;
  vector<ll> h(n);
  rep(i,n) cin >>h.at(i);
  sort(all(h));
  ll ans = 0;
  if (n <= k) ans = 0;
  else{
    // 必殺技が使えない相手がいる
    rep(i, n-k) ans += h.at(i);
  }
  cout <<ans <<endl;
}

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

const int INF = 1001001001;
int dist[105][105];
int nextv[105][105];
bool used[105][105];
struct edge{
    int from, to, cost;
};
vector<edge> es;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m;
    cin >> n >> m;
    fill((int*)dist, (int*)(dist + n), INF);
    for(int i = 0; i < n; ++i){
        dist[i][i] = 0;
    }
    fill((int*)nextv, (int*)(nextv + n), -1);
    fill((bool*)used, (bool*)(used + n), true);
    for(int i = 0; i < m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        dist[a][b] = c;
        dist[b][a] = c;
        nextv[a][b] = b;
        nextv[b][a] = a;
        used[a][b] = false;
        used[b][a] = false;
        es.push_back((edge){a, b, c});
    }
    
    for(int k = 0; k < n; ++k){
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                if(dist[i][j] > dist[i][k] + dist[k][j]){
                    dist[i][j] = dist[i][k] + dist[k][j];
                    
                    nextv[i][j] = k;
                }
            }
        }
    }
    
    // for(int s = 0; s < n; ++s){
    //     for(int t = 0; t < n; ++t){
    //         if(s == t)      continue;
            
    //         int now = s;
    //         for(int v = s; v != t; v = nextv[v][t]){
    //             used[now][v] = true;
    //             used[v][now] = true;
    //             now = v;
    //         }
    //         used[now][t] = true;
    //         used[t][now] = true;
    //     }
    // }
    
    int ans = 0;
    for(int i = 0; i < m; ++i){
        edge &e = es[i];
        bool flag = false;
        for(int s = 0; s < n; ++s){
            if(dist[s][e.from] + e.cost == dist[s][e.to]){
                flag = true;
                break;
            }
        }
        if(!flag)   ++ans;
    }
    // for(int i = 0; i < n - 1; ++i){
    //     for(int j = i + 1; j < n; ++j){
    //         if(!used[i][j])     ++ans;
    //     }
    // }
    
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A;
    cin >> A;
    vector<int> N(A);
    for(int i=0; i<A; i++) cin >> N.at(i);
    sort(N.begin(),N.end());
    cout << N.at(A-1)-N.at(0) << endl;
}

Measured memory_bytes: 3608
H, W, N = gets.strip.split(/ /).collect(&:to_i)
y, x = gets.strip.split(/ /).collect(&:to_i)

S = gets.strip.split(//)
T = gets.strip.split(//)

def check(s, t, i, w, c1, c2)
	win_min = 1
	win_max = w
	
	N.times.reverse_each{|j|
		if j < N - 1
			tc = t[j]
			if tc == c1
				win_max += 1
			elsif tc == c2
				win_min -= 1
			end
			if win_max > w
				win_max = w
			end
			if win_min < 1
				win_min = 1
			end
		end
		sc = s[j]
		if sc == c1
			win_min += 1
		elsif sc == c2
			win_max -= 1
		end
		if win_max > w
			win_max = w
		end
		if win_min < 1
			win_min = 1
		end
		if win_max < win_min
			return false
		end
	}
	if win_min <= i && win_max >= i
		return true
	else
		return false
	end
end

if check(S, T, x, W, 'L', 'R') && check(S, T, y, H, 'U', 'D')
	puts "YES"
else
	puts "NO"
end






Measured memory_bytes: 28028
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run() {
		int n = sc.nextInt();
		int out = 0;
		boolean[] base = new boolean [4];
		base[0] = true;
		int count = 0;
		int ining = 0;
		while (true) {
			if( ining == n ) break;
			String str = sc.next();
			if(str.equals("HIT")) {
				if(base[3]) count ++;
				for(int i=3;i>0;i--) base[i] = base[i-1];
			}
			else if( str.equals("HOMERUN") ) {
				for(int i=0;i<4;i++) {
					if (base[i]) count++;
					base[i] = false;
				}
				base[0] = true;
			}
			else {
				out++;
				if( out == 3 ) {
					ining++;
					System.out.println(count);
					count=0;
					out=0;
					
					base = new boolean[4];
					base[0] = true;
				}
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
import java.util.*;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    
    while (true) {
      double n = sc.nextDouble();
      if (n == -1) break;
      
      int left = (int)n;
      String lhs = Integer.toString(left, 2);
      
      if (lhs.length() > 8) {
        System.out.println("NA");
        continue;
      }
      
      double right = n % 1;
      String rhs = "";
      int rem = 4;
     
      while (rem-- > 0 && right != 0) {
         right *= 2;
         rhs += (int)right;
         right %= 1;
      }
      
      if (right != 0) {
        System.out.println("NA");
        continue;
      }
      
      while (lhs.length() != 8) lhs = "0" + lhs;
      while (rhs.length() != 4) rhs += "0";
      
      System.out.println(lhs + "." + rhs);
    }
  }
}

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

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

int main() {
  int N, X;
  cin >> N >> X;
  int x[100010];
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    x[i] = abs(X - x[i]);
  }

  int ans = x[0];
  for (int i = 0; i < N; i++) {
    ans = gcd(ans, x[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i<n;i++)
int main(){
int n;
string a;
cin >> n;
cin >> a;
if(n%2 == 0){
    if(a.substr(0,n/2) ==a.substr(n/2, n)){
        printf("Yes\n");
        return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> n(a);
  rep(i,a) cin >> n[i];
  sort(n.begin(),n.end());
  int ans = 0;
  rep(i,b) {
    ans += n[i];
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3632
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h, w;
        while (true) {
            h = sc.nextInt();
            w = sc.nextInt();
            if (h == 0 && w == 0) {
                break;
            }
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (i % 2 == 0) {
                        if (j % 2 == 0) {
                            System.out.print("#");
                        } else {
                            System.out.print(".");
                        }
                    } else {
                        if (j % 2 == 0) {
                            System.out.print(".");
                        } else {
                            System.out.print("#");
                        }
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
        sc.close();
    }
}


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

int main(){
    string S;
    cin >> S;
    string divide[4] = {"dream", "dreamer", "erase", "eraser"};

    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; i++){
        reverse(divide[i].begin(), divide[i].end());
    }

    /*for (int i = 0; i < 4; i++){
        cout << divide[i] << endl;
    }*/
    //cout << S << endl;
    //cout << S.substr(0, 5) << endl; 
    while(1){
        if (S.substr(0, 5) == divide[0]) S.erase(0, 5);
        else if (S.substr(0, 7) == divide[1]) S.erase(0, 7);
        else if (S.substr(0, 5) == divide[2]) S.erase(0, 5);
        else if (S.substr(0, 6) == divide[3]) S.erase(0, 6);
        else {
            cout << "NO" << endl;
            break;
        }
        if (S == "") {
            cout << "YES" << endl;
            break;
        }
    }
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int answer;
		
		if(A >= 13) {
			
			answer = B;
		}else if(A >= 6) {
			
			answer = B / 2;
			
		}else{
			
			answer = 0;
		}

		System.out.println(answer);
	}

}

Measured memory_bytes: 21844
N, A, B = gets.split.map(&:to_i)

def sum(n, a, b, upper)
    digits = n.to_s.length
    return 0 if b < 0 || n < 0
    if digits == 1
        max = upper + [b, n].min
        min = upper + [a, 0].max
        if max >= min
          return (max + min) * (max - min + 1) / 2
        else
          return 0
        end
    end

    result = 0
    10.times do |top_digit|
        remain = [n - top_digit * 10 ** (digits - 1), 10 ** (digits - 1) - 1].min
        break if remain < 0
        result += sum(remain, a - top_digit, b - top_digit, upper + top_digit * 10 ** (digits - 1))
    end
    return result
end

print sum(N, A, B, 0)

Measured memory_bytes: 1916
import queue

N = int(input())

adj = dict([(i+1, []) for i in range(N)])
dist = [-1 for i in range(N)]
dist[0] = 0
for i in range(N-1):
    u, v, w = map(int, input().split())
    adj[u].append((v, w))
    adj[v].append((u, w))

q = queue.Queue()
q.put((1, 0))
while(not q.empty()):
    v, w = q.get()
    dist[v-1] = w
    for nv, nw in adj[v]:
        if(dist[nv-1]!=-1):
            continue
        q.put((nv, dist[v-1]+nw))

for c in dist:
    print(c%2)

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

int stringCount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}
int main(void){

  string str;
  cin >> str;
  cout << stringCount(str,'1') << endl;
}


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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
template<class T = int> using V = vector<T>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

int prime[1001001];
bool is_prime[1001001];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i < n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < n; i++){
    if (is_prime[i]){
      prime[p++] = i;
      for (int j = 2*i; j < n; j+=i) is_prime[j] = false;
    }
  }
  return p;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
  vector<pair<long long, long long> > res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    long long ex = 0; // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    // その結果を push
    res.push_back({a, ex});
  }

  // 最後に残った数について
  if (N != 1) res.push_back({N, 1});
  return res;
}

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

  int N;
  cin >> N;
  int A[N];
  REP(i,N) cin >> A[i];

  bool is_pairwise = true;
  bool is_setwise = true;
  vector<int> appeared(1001001, 0);
  REP(i,N) {
    const auto &res = prime_factorize(A[i]);
    for (auto p : res) {
      appeared[p.first]++;
      if (appeared[p.first] > 1) {
        is_pairwise = false;
      }
    }
  }

  int max_appeared = 0;
  REP(i,1001001) {
    chmax(max_appeared, appeared[i]);
  }

  if (max_appeared == N) is_setwise = false;

  if (is_pairwise) {
    cout << "pairwise coprime" << endl;
  } else if (is_setwise) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}


Measured memory_bytes: 11044
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <numeric>
#include <string>
#include <cmath>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	vector<int> x(6);
	int ans;

	for (int i = 1; i < 6; i++) {
		cin >> x[i];
		if (x[i] == 0) {
			ans = i;
		}
	}

	cout << ans;

	return 0;
}


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

using namespace std;


int main() {

    int N;
    cin >> N;
    vector<int> A;
    vector<int> B;
    vector<int> C;

    for(int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        A.push_back(a);
    }

    for(int i = 0; i < N; i++)
    {
        int b;
        cin >> b;
        B.push_back(b);
    }

    for(int i = 0; i < N-1; i++) {
        int c;
        cin >> c;
        C.push_back(c);
    }

    int sum = 0;
    for(int i = 0 ; i < N; i++)
    {
        if(i != 0 && A[i]-A[i-1] == 1)
        {
            sum += B[A[i]-1] + C[A[i-1]-1];
        } else
        {
            sum += B[A[i]-1];
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 100010
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
int n,K,ans,v[5],op[maxn],mp[500],f[maxn][5];
char str[maxn];
int check(int x,int y)
{
	return x==(y+1)%3? v[x]:0;
}
int dp(int *str,int l)
{
	for(int i=1;i<=l;i++)
	{
		f[i][0]=max(f[i-1][1],f[i-1][2])+check(0,str[i]);
		f[i][1]=max(f[i-1][0],f[i-1][2])+check(1,str[i]);
		f[i][2]=max(f[i-1][0],f[i-1][1])+check(2,str[i]);
	}
	return max(f[l][0],max(f[l][1],f[l][2]));
}
int main()
{
	read(n,K);
	mp['s']=0;
	mp['r']=1;
	mp['p']=2;
	read(v[1],v[0],v[2]);
	scanf("%s",str+1);
	for(int i=1;i<=K&&i<=n;i++)
	{
		int cnt=0;
		for(int j=i;j<=n;j+=K)
			op[++cnt]=mp[(int)str[j]];
		ans+=dp(op,cnt);
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <map>
using namespace std;

const long MOD = 1'000'000'007;

int main() {
	long n; cin >> n;
	long ans = 0;
	for (long i = 1; i <= n; i++) {
		if (i % 3 && i % 5) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int N, M;
vector<vector<int>> relation;
vector<bool> seen;

int dfs(int x) {
  seen.at(x) = true;
  int count = 0;
  for(int i = 0; i < relation.at(x).size(); i++) {
    if(seen.at(relation.at(x).at(i))) {
      continue;
    }
    count += dfs(relation.at(x).at(i));
  }
  count++;
  return count;
}

int main() {
  cin >> N >> M;
  relation.assign(N, {});
  seen.assign(N, false);
  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    relation.at(a).push_back(b);
    relation.at(b).push_back(a);
  }
  int ans = 0;
  for(int i = 0; i < N; i++) {
    if(seen.at(i)) {
      continue;
    }
    int x = dfs(i);
    if(x > ans) {
      ans = x;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 23456
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b;
	cin >> a >> b;
	cout << (a - 1) * (b - 1) << endl;
	return 0;
}


Measured memory_bytes: 256
_1_1=[]
_1_2=[]
_1_3=[]
_2_1=[]
_2_2=[]
_2_3=[]
_3_1=[]
_3_2=[]
_3_3=[]
_4_1=[]
_4_2=[]
_4_3=[]
for i in range(10):
    _1_1.append(0)
    _1_2.append(0)
    _1_3.append(0)
    _2_1.append(0)
    _2_2.append(0)
    _2_3.append(0)
    _3_1.append(0)
    _3_2.append(0)
    _3_3.append(0)
    _4_1.append(0)
    _4_2.append(0)
    _4_3.append(0)
N=int(input())
s=[input() for i in range(N)]
bfrv=[]
for i in s:
    bfrv.append(i.split())
for i in bfrv:
    if int(i[0])==1 and int(i[1])==1:
        _1_1[int(i[2])-1]+=int(i[3])
    elif int(i[0])==1 and int(i[1])==2:
        _1_2[int(i[2])-1]+=int(i[3])
    elif int(i[0])==1 and int(i[1])==3:
        _1_3[int(i[2])-1]+=int(i[3])
    elif int(i[0])==2 and int(i[1])==1:
        _2_1[int(i[2])-1]+=int(i[3])
    elif int(i[0])==2 and int(i[1])==2:
        _2_2[int(i[2])-1]+=int(i[3])
    elif int(i[0])==2 and int(i[1])==3:
        _2_3[int(i[2])-1]+=int(i[3])
    elif int(i[0])==3 and int(i[1])==1:
        _3_1[int(i[2])-1]+=int(i[3])
    elif int(i[0])==3 and int(i[1])==2:
        _3_2[int(i[2])-1]+=int(i[3])
    elif int(i[0])==3 and int(i[1])==3:
        _3_3[int(i[2])-1]+=int(i[3])
    elif int(i[0])==4 and int(i[1])==1:
        _4_1[int(i[2])-1]+=int(i[3])
    elif int(i[0])==4 and int(i[1])==2:
        _4_2[int(i[2])-1]+=int(i[3])
    elif int(i[0])==4 and int(i[1])==3:
        _4_3[int(i[2])-1]+=int(i[3])
print("",*_1_1)
print("",*_1_2)
print("",*_1_3)
print("#"*20)
print("",*_2_1)
print("",*_2_2)
print("",*_2_3)
print("#"*20)
print("",*_3_1)
print("",*_3_2)
print("",*_3_3)
print("#"*20)
print("",*_4_1)
print("",*_4_2)
print("",*_4_3)


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

using namespace std;
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  ll W, H; cin >> W >> H;
  vector<ll> p(W), q(H);
  rep(i, W) scanf("%lld", &p[i]);
  rep(i, H) scanf("%lld", &q[i]);

  vector<pair<ll, int>> vs;
  rep(i, W) vs.emplace_back(p[i], 0);
  rep(i, H) vs.emplace_back(q[i], 1);

  sort(all(vs));

  int wcnt = 0, hcnt = 0;

  ll sum = 0;

  rep(i, W + H) {
    if(vs[i].second)
      sum += vs[i].first * (W + 1 - wcnt), hcnt ++;
    else
      sum += vs[i].first * (H + 1 - hcnt), wcnt ++;
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 6000
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

char albt[26] = {'a','b','c','d','e','f','g','h','i','j','k','l',
                 'm','n','o','p','q','r','s','t','u','v','w','x',
                 'y','z'};

//vector<ll> g[202020];
//fill(score, score+202020, 0);
//vector<ll> v;

ll par[202020];
ll rnk[202020];

void init(ll n){
  for (int i=0;i<n;i++){
    par[i] = i;
    rnk[i] = 0;
  }
}

ll find(ll x){
  if(par[x] == x) return x;
  else{
    par[x] = find(par[x]);
    return par[x];
  }
}
  
void unite(ll x, ll y){
  x = find(x);
  y = find(y);
  if (x == y) return;
  
  if (rnk[x] < rnk[y]){
    par[x] = y;
  }
  else{
    par[y] = x;
    if(rnk[x] == rnk[y]) rnk[x]++;
  }
}
 
bool same(ll x, ll y){
  return find(x) == find(y);
}

int main(){
  ll n, m;
  cin >> n >> m;
  init(n);
  ll x, y, z;
  for (int i=0;i<m;i++){
    cin >> x >> y >> z;
    unite(x, y);
  }
  ll ans = 0;
  for (int i=0;i<n;i++){
    if (par[i] == i) ans += 1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1792
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    global L
    N,m = i_map()
    l = [[0]*N for i in range(N)]

    for i in range(m):
        a,b = i_map()
        a -= 1
        b -= 1
        l[a][b] = 1
        l[b][a] = 1

    L = 0
    v = [0] * N
    v[0] = 1

    def dfs(n):
        global L
        if 0 not in v:
            L += 1
            return

        for i in range(N):
            if l[n][i] == 1 and v[i] == 0:
                v[i] = 1
                dfs(i)
                v[i] = 0

    dfs(0)
    print(L)



if __name__=="__main__":
    main()


Measured memory_bytes: 74688
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision


using namespace std;
bool routecheck(vector<int>& perm, vector<vector<int>>& G,int n){
    for (int i = 0; i < n-1; i++)
        {   
            int& j = perm[i];
            if(find(G[j].begin(),G[j].end(),perm[i+1]) == G[j].end()) return false;
        }
    return true;
}

int main() {
    int n,m; cin >> n >> m;
    vector<vector<int>> G(n);
    for (int i = 0; i < m; i++)
    {
        int b,a; cin >> b >> a;
        b--; a--;
        G[b].push_back(a);
        G[a].push_back(b); 
    }
    vector<int> perm(n);
    for (int i = 0; i < n; i++)
    {
        perm[i] = i;
    }
    int count=0;
    do
    {   
        if(routecheck(perm,G,n)) count++;
    } while (next_permutation(perm.begin()+1,perm.end()));
    
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3168
# D - Partition
import bisect
N, M = map(int, input().split())

def make_divisors(n):
    divisors = []
    for i in range(1, int(pow(n,0.5)+1)):
        if n%i==0:
            divisors.append(i)
            if i!=n//i: 
                divisors.append(n//i)
    divisors.sort()
    return divisors

d = make_divisors(M)
print(M//d[bisect.bisect_left(d, N)])


Measured memory_bytes: 3064