akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)






#define MAX_V 100
struct edge { int to, cap, cost,rev; };

int V; // ????????°
vector<edge> G[MAX_V];
vector<int> h(MAX_V);	//??????????????£???
vector<int> dist(MAX_V);// ???????????¢
int prevv[MAX_V], preve[MAX_V];// ??´??????????????¨???

// from??????to??????????????????cap????????????cost????????????????????????????????????
void add_edge(int from, int to, int cap, int cost) {
	G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
	G[to].push_back((edge){from, 0, -cost, (int)G[from].size() - 1});
}


//?????????????????????????????????????????´????????????
int shortest_path(int s,vector<int> &d){
	int v = d.size();
	rep(i,d.size())d[i]=INF;
	d[s]=0;
	rep(loop,v){
		bool update = false;
		rep(i,MAX_V){
			for(auto e:G[i]){
				if(d[i]!=INF && d[e.to] > d[i]+e.cost){
					d[e.to] = d[i]+e.cost;
					update = true;
				}
			}
		}
		if(!update)break;
		if(loop==v-1)return true;	//negative_cycle
	}
	return false;
}


// s??????t????????????f???????°??????¨???????±???????
// ??????????????´??????-1?????????
int min_cost_flow(int s, int t, int f) {
	int res = 0;
	rep(i,h.size())h[i]=0;
	shortest_path(s, dist);
	
	while (f > 0) {
		// ?????????????????????????????¨??????h?????´??°??????
		priority_queue<pii, vector<pii>, greater<pii> > que;
		rep(i,dist.size())dist[i]=INF;
		dist[s] = 0;
		que.push(pii(0, s));
		while (!que.empty()) {
			pii p = que.top(); que.pop();
			int v = p.second;
			if (dist[v] < p.first) continue;
			for (int i = 0; i < G[v].size(); i++) {
				edge &e = G[v][i];
				if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
					dist[e.to] = dist[v] + e.cost + h[v] - h[e.to]; prevv[e.to] = v;
					preve[e.to] = i;
					que.push(pii(dist[e.to], e.to));
				}
			}
		}
		if (dist[t] == INF) return -1;	//????????\???????????????
		
		for (int v = 0; v < V; v++) h[v] += dist[v];
		
		// s-t????????????????????£??????????????????
		int d = f;
		for (int v = t; v != s; v = prevv[v]) {
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * h[t];
		for (int v = t; v != s; v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]]; e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

int main(){
	int e,f;
	cin>>V>>e>>f;
	rep(i,e){
		int u,v,c,d;
		cin>>u>>v>>c>>d;
		add_edge(u, v, c, d);
	}
	cout<<min_cost_flow(0, V-1, f)<<endl;
}

Measured memory_bytes: 3188
#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],tt;

void dfs_visit(int i)
{
  int j;
  color[i]=GRAY;
  d[i]=++tt;
  for(j=0;j<n;j++)
  {
    if(M[i][j]==0)continue;
    if(color[j]==WHITE)
    {
      dfs_visit(j);
    }
  }
  color[i]=BLACK;
  f[i]=++tt;
}

void dfs()
{
  int i;
  for(i=0;i<n;i++)
  {
    color[i]=WHITE;
  }
  tt=0;
  for(i=0;i<n;i++)
  {
    if(color[i]==WHITE)dfs_visit(i);
  }
  for(i=0;i<n;i++)
  {
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}

int main()
{
  int i,j,id,n2,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",&id,&n2);
    {
      id=id-1;
      for(j=0;j<n2;j++)
      {
        scanf("%d",&v);
        v=v-1;
        M[id][v]=1;
      }
    }
  }
  dfs();
  return 0;
}



Measured memory_bytes: 2084
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int n;
    cin>>n;
    int x=0;
    for(int i=1;i<=n;i++)
    {
        int lft=i-1;
        int rgt=(n-i);
        int way=lft*rgt;
        x+=way;
        x+=rgt;
        x+=(lft);
        x+=1;
    }
    int y=0;
    f(i,1,n-1)
    {
        int u,v;
        cin>>u>>v;
        if(u>v)swap(u,v);
        int lft=u;
        int rgt=n-v+1;
        int way=lft*rgt;
        y+=way;
    }
    //cout<<x<<" "<<y<<endl;
    cout<<x-y<<endl;
    return 0;

}





































Measured memory_bytes: 3544
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(a) begin(a),end(a)
#define INF 999999999
#define debug(x) cerr << #x << ":" << x << '\n'
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef unsigned long long ull;
typedef unsigned long ul;
typedef unsigned int  ui;

int main() {
	int n;
	cin >> n;
	switch(n) {
		case 111:
			cout << 999 << "\n";
			break;
		case 119:
			cout << 991 << "\n";
			break;
		case 191:
			cout << 919 << "\n";
			break;
		case 199:
			cout << 911 << "\n";
			break;
		case 911:
			cout << 199 << "\n";
			break;
		case 919:
			cout << 191 << "\n";
			break;
		case 999:
			cout << 111 << "\n";
			break;
		case 991:
			cout << 119 << "\n";
			break;
	}
}

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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

void megaRandom() {
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  srand(FOR);
}

int n, k;
vector<int> g[N];
int leave, mx, cnt;

void dfs(int x, int pr = 0, int dist = 0) {
	if(dist <= (k >> 1)) {
		leave ++;
		for(auto to : g[x]) {
			if(to == pr) continue;
			dfs(to, x, dist + 1);		
		}
	}
}

void jfs(int x, int pr = 0, int dist = 1) {
	if(dist == (k >> 1) + 1) cnt ++;
	if(dist <= (k >> 1)) {
		for(auto to : g[x]) {
			if(to == pr)
				continue;
			jfs(to, x, dist + 1);
		}
	}
}

int main() {
	megaRandom();
	cin >> n >> k;
	for(int i = 1, a, b; i < n; i ++) {
		cin >> a >> b;		
		g[a].pb(b), g[b].pb(a);
	}
	int res= 0;
	for(int i = 1; i <= n; i ++) {
		leave = 0, mx = 0, cnt = 0;
		dfs(i);
		if(k & 1) { 
			for(auto to : g[i]) { 
				cnt = 0;
				jfs(to, i);
				mx = max(mx, cnt);
			}
		}
		leave += mx;
		res = max(res, leave);
	}
	cout << n - res;
	return 0;  
}


Measured memory_bytes: 23808
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr int INF = 1e9;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

//#####################
//Dijkstra
//#####################
struct edge
{
    int to, cost;
};

int n, m;
vector<edge> g[212345];
int dis[212345];

void dijkstra(int s)
{
    priority_queue<P, vector<P>, greater<P>> que;
    fill(dis, dis + n + 1, INF);
    dis[s] = 0;
    que.push(P(0, s));

    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        int n_ = p.second;
        if (dis[n_] < p.first)
            continue;
        for (int i = 0; i < g[n_].size(); i++)
        {
            edge e = g[n_][i];
            if (dis[e.to] > dis[n_] + e.cost)
            {
                dis[e.to] = dis[n_] + e.cost;
                que.push(P(dis[e.to], e.to));
            }
        }
    }
}

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

    cin >> n >> m;

    REP(i, m)
    {
        int a, b;
        cin >> a >> b;

        g[a].push_back({b, 1});
        g[b].push_back({a, 1});
    }

    dijkstra(1);

    if (dis[n] == 2)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 15336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    string s;
    cin >> s;

    int a[2019] = {};
    ll ans = 0;
    ll duh = 1;

    reverse(s.begin(), s.end());
    int cur = 0;
    a[0]++;
    for (char c : s) {
        cur += (c - 48) * duh;
        cur %= 2019;

        duh *= 10;
        duh %= 2019;

        ans += a[cur];
        a[cur]++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3748
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> h(n);
    for(int i = 0; i < n; i++){
        std::cin >> h[i];
    }

    int maxStep = 0;
    int step = 0;
    for(int i = 1; i < n; i++){
        if(h[i - 1] >= h[i]){
            step++;
            maxStep = std::max(maxStep, step);
        }else{
            step = 0;
        }
    }

    std::cout << maxStep << std::endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
  int n;
  string tri;
  
  cin >> n;
  
  while (n){
    switch (n%3){
    case 0:
      n/=3; tri.push_back('0');
      break;
    case 1:
      n=(n-1)/3; tri.push_back('+');
      break;
    case 2:
      n=(n+1)/3; tri.push_back('-');
      break;
    }
  }
  reverse(tri.begin(), tri.end());
  cout << tri << endl;
  return 0;
}
  


Measured memory_bytes: 3240
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int h,w,k;
    cin >> h >> w >> k;

    char c[h][w],temp[h][w];
    REP(i,h)REP(j,w)cin >> c[i][j];
    ll answer = 0;
    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bith = 0; bith < (1<<h); ++bith) {
        for(int bitw = 0;bitw < (1<<w); ++bitw){
            int count = 0;
            vector<int> S;
            REP(i,h)REP(j,w)temp[i][j] = c[i][j];
            for (int i = 0; i < h; ++i) {
                for(int j = 0;j < w;++j){
                    if ((bith & (1<<i)) or (bitw & (1<<j))) { // 列挙に i が含まれるか
                        temp[i][j] = 'x';
                    }
                }
            }

            REP(i,h)REP(j,w){
                if(temp[i][j] == '#')count++;
            }
            if(count == k)answer++;
        }
    }

    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 3620
mv=(((1,0,0)  ,(-1,0,0))  ,#move x direction
    ((0,1,0)  ,(0,-1,0))  ,#move y direction
    ((0,0,1)  ,(0,0,-1))  ,#move z direction
    ((1,1,0)  ,(-1,-1,0)) ,#move xy direction y=-x+a
    ((1,-1,0) ,(-1,1,0))  ,#move xy direction y=x+b
    ((1,0,1)  ,(-1,0,-1)) ,#move xz direction x z same increase
    ((1,0,-1) ,(-1,0,1))  ,#move xz direction x increase z decrease
    ((0,1,1)  ,(0,-1,-1)) ,#move yz direction y z same increase
    ((0,1,-1) ,(0,-1,1))  ,#move yz direction y increase z decrease
    ((1,1,1)  ,(-1,-1,-1)),
    ((1,1,-1) ,(-1,-1,1)) ,
    ((1,-1,1) ,(-1,1,-1)) ,
    ((1,-1,-1),(-1,1,1)))

def check(L,y,x,z,color):
    for line in mv:
        cnt=1
        tx,ty,tz=x,y,z
        for dx,dy,dz in line:
            while (0<=x+dx<n) and (0<=y+dy<n) and (0<=z+dz<len(L[y+dy][x+dx])) and L[y+dy][x+dx][z+dz]==color:
                cnt+=1
                x+=dx
                y+=dy
                z+=dz
            x,y,z=tx,ty,tz
        if cnt>=m:
            return True
    return False

while True:
    n,m,p=map(int,raw_input().split())
    if n==m==p==0:break
    L=[[[] for i in range(n)] for i in range(n)]
    data=[map(int,raw_input().split()) for i in range(p)]
    for i in range(len(data)):
        x,y=data[i][0],data[i][1]
        L[y-1][x-1].append(i%2)
        z=len(L[y-1][x-1])
        if check(L,y-1,x-1,z-1,i%2):
            if i%2:
                print "White",i+1
            else:
                print "Black",i+1
            break
    else:
        print "Draw"

Measured memory_bytes: 4384
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&s){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#else
template<class...T>void dprint(T&&...t){_print(cerr,t...);}
#endif
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<<(ostream&o,const multiset<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    vi x;
    REP(i,n){
        if(a[i]==b[i]){
            x<<1;
        }else{
            x<<2;
            i++;
        }
    }
    ll ans=(x[0]==1?3:6);
    REP(i,1,x.size()){
        if(x[i]==2){
            if(x[i-1]==2){ // ==
                ans*=3;
            }else{ // |=
                ans*=2;
            }
        }else{
            if(x[i-1]==2){ // =|

            }else{ // ||
                ans*=2;
            }
        }
        ans%=MOD;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;

int h,w;
char c[110][110];
int main(){
  cin>>h>>w;
  FOR(i,1,h+1){
    FOR(j,1,w+1){
      cin>>c[j][i];
    }
  }

  FOR(i,1,h*2+1){
    FOR(j,1,w+1){
      cout<<c[j][(i+1)/2];
    }
    cout<<endl;
  }


}


Measured memory_bytes: 256
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];
int dp[N];
int solve() 
{
	//happy coding

	string s;
	cin>>s;
	int n = s.size();
	for(int i=0;i<n;i++){
		if(s[i]=='R'&&s[i+1]=='L'){
			int st = i;
			int en = i+1;
			int cnt = 0;
			while(st>=0){
				if(s[st]=='R'){
					cnt++;
				}else break;
				st--;
			}
			dp[i] = cnt;
			cnt = 0;
			while(en<n){
				if(s[en]=='L'){
					cnt++;
				}else break;
				en++;
			}
			dp[i+1]=  cnt;
		}
	}

	for(int i=0;i<n;){
		if(dp[i]!=0&&dp[i+1]!=0){
			int x = dp[i];
			int y = dp[i+1];
			dp[i+1] = (x-((x-1)/2))+(y-1)/2;
			dp[i] = (y-((y-1)/2))+(x-1)/2;
			i+=2;
		}else i++;
	}

	for(int i=0;i<n;i++){
		cout<<dp[i]<<" ";
	}cout<<endl;


	
	return 0;
}
int main(){
	int test = 1;
  	//scanf("%d", &test);
  	while (test--)solve();return 0;
}

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

int main() {
	
	int N, K;
	cin >>N >>K;
	
	string S;
	cin >>S;
	
	if(S.at(K-1)=='A'){
		
		S.at(K-1)='a';
		
	}
	if(S.at(K-1)=='B'){
		
		S.at(K-1)='b';
		
	}
	if(S.at(K-1)=='C'){
		
		S.at(K-1)='c';
		
	}
	
	cout <<S <<endl;
	
}

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

#define INF 1e9
using namespace std;

int main() {

    string S; cin >> S;

    int count = 0;
    int ans = 0;

    for (auto s:S) {
        if (s == 'A' || s == 'T' || s == 'G' || s == 'C') {
            ++count;
        } else {
            count = 0;
        }

        ans = max(ans, count);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <cstdint>

struct UnionFind {
	std::vector<int> par;
	std::vector<int> size;

	UnionFind(int n) : par(n), size(n, 1) {
		for (int i = 0; i < n; ++i)
			par[i] = i;
	}

	int root(int x) {
		return (par[x] == x ? x : par[x] = root(par[x]));
	}

	void unite(int x, int y) {
		x = root(x), y = root(y);
		if (x == y)
			return;

		size[x] += size[y];
		par[y] = x;
	}

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

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

int main() {
	int n, m, k;
	std::cin >> n >> m >> k;

	std::vector<std::pair<int, int>> ff(m);
	UnionFind uf(n);

	for (auto&& p : ff) {
		std::cin >> p.first >> p.second;
		--p.first, --p.second;

		uf.unite(p.first, p.second);
	}

	std::vector<int> cands(n);
	for (int i = 0; i < n; ++i)
		cands[i] = uf.getSize(i) - 1;

	for (auto&& p : ff)
		if (uf.isSame(p.first, p.second))
			--cands[p.first], --cands[p.second];

	for (int i = 0; i < k; ++i) {
		int c, d;
		std::cin >> c >> d;
		--c, --d;

		if (uf.isSame(c, d))
			--cands[c], --cands[d];
	}

	std::cout << cands[0];
	for (int i = 1; i < n; ++i)
		std::cout << ' ' << cands[i];

	std::cout << std::endl;
}

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, VL, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll L;
struct edge {
    ll to, cost;
};
vector<vector<edge>> es;

signed main() {
    cin >> L;
    ll N = 32 - __builtin_clz(L);
    es.resize(N);
    REP(i, N - 1) {
        es[i].push_back({i + 1, 1 << i});
        es[i].push_back({i + 1, 0});
    }
    ll mb = 1 << (N - 1);
    REPR(i, N - 2) {
        if(L & 1LL << i) {
            es[i].push_back({N - 1, mb});
            mb += 1LL << i;
        }
    }
    ll M = 0;
    FOREACH(e, es) M += e.size();
    cout << N << " " << M << "\n";
    REP(i, es.size()) {
        FOREACH(e, es[i]) {
            cout << i + 1 << " " << e.to + 1 << " " << e.cost << "\n";
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int a,b;
    cin>>a>>b;
    if(a<b){
        rep(i,b) cout<<a;
    }
    else rep(i,a) cout<<b;
}

Measured memory_bytes: 3568
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=5005,mod=1000000007;
int n,u,v,cnt,ans,head[N],to[N*2],nxt[N*2],f[N][N],g[N],t[N],siz[N];
void adde(int u,int v){
	to[++cnt]=v;
	nxt[cnt]=head[u];
	head[u]=cnt;
}
void dfs(int pre,int u){
	siz[u]=1;
	f[u][1]=1;
	int v;
	for(int i=head[u];i;i=nxt[i]){
		v=to[i];
		if(v!=pre){
			dfs(u,v);
			for(int j=1;j<=siz[u];j++){
				for(int k=1;k<=siz[v];k++){
					t[j]=(t[j]-1LL*f[u][j]*f[v][k]%mod*g[k]%mod+mod)%mod;
					t[j+k]=(t[j+k]+1LL*f[u][j]*f[v][k])%mod;
				}
			}
			siz[u]+=siz[v];
			for(int j=1;j<=siz[u];j++){
				f[u][j]=t[j];
				t[j]=0;
			}
		}
	}
}
int main(){
	scanf("%d",&n);
	g[0]=1;
	for(int i=2;i<=n;i++){
		if((i&1)^1){
			g[i]=1LL*g[i-2]*(i-1)%mod;
		}
		scanf("%d%d",&u,&v);
		adde(u,v);
		adde(v,u);
	}
	dfs(0,1);
	for(int i=1;i<=n;i++){
		ans=(ans+1LL*f[1][i]*g[i])%mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 56404
//be name khoda
//Pedram Sadeghian
// :)
#include <bits/stdc++.h>
using namespace std;

const int maxN = 1e5;
int n, m, a, b, c, TM = 1, ans;
pair <int, int> P;
set < pair <int, pair <int, int> > > S;
vector < pair <int, int> > G[maxN];
bool Mark[maxN];

int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		cin >> a >> b >> c;
		G[a].push_back(make_pair(b, c));
		G[b].push_back(make_pair(a, c));
		if (a == 0 || b == 0)
			S.insert(make_pair(c, make_pair(a, b)));
	}
	Mark[0] = 1;
	/*
	for (set <pair <int, int> > ::iterator it = S.begin(); it != S.end(); it++){
		cout << (*it).first << " ";
	}
	cout << endl;*/
	while (TM != n){
		P = (*S.begin()).second;
		while (Mark[P.first] && Mark[P.second]){
			S.erase(make_pair((*S.begin()).first, make_pair(P.first, P.second)));
			P = (*S.begin()).second;
		}
		ans += (*S.begin()).first;
		TM++;
		a = P.first;
		if (Mark[P.first]) a = P.second;
		for (int i = 0; i < G[a].size(); i++){
			if (not Mark[G[a][i].first]){
				S.insert(make_pair(G[a][i].second, make_pair(a, G[a][i].first)));
			}
		}
		Mark[a] = 1;
	}
	cout << ans << endl;
}

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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int A, B, C;
	
	cin >> A >> B >> C;
	
	if(A == B){
		cout << C;
	}else if(B == C){
		cout << A;
	}else
		cout << B;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

ll dpl[200010];
ll dpr[200010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;
    ll num = 0;
    ll i = 0;
    while (i < N) {
        // cout << i << endl;
        if (S[i] == 'o') {
            // cout << "aaa" << endl;
            dpl[num] = i;
            num++;
            i += C + 1;
        } else {
            i++;
        }
    }
    if (num > K) {
        return 0;
    }
    num = 0;
    i = N - 1;
    while (i >= 0) {
        if (S[i] == 'o') {
            dpr[K - 1 - num] = i;
            num++;
            i -= C + 1;
        } else {
            i--;
        }
    }
    // REP(i, 0, K) {
    //     cout << dpl[i] << " " << dpr[i] << endl;
    // }
    REP(i, 0, K) {
        if (dpl[i] == dpr[i]) {
            cout << dpl[i] + 1 << endl;
        }
    }
}


Measured memory_bytes: 5012
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
using namespace std;
const int MAXN = 110;
int n;
ll a[MAXN];
void work() {
  scanf("%d", &n);
  for(reg int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  int ans = 0;
  for(reg int i = 1; i <= n; ++i) {
    for(reg int j = i + 1; j <= n; ++j) {
      for(reg int k = j + 1; k <= n; ++k) {
        if(a[i] != a[j] && a[j] != a[k] && a[i] != a[k]) {
          if(a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i]) ++ans;
        }
      }
    }
  }
  printf("%d\n", ans);
}
signed main() {
  int _ = 1;
  // scanf("%d", &_);
  while(_--) {
    work();
  }
  return 0;
}


Measured memory_bytes: 3800
#include <stdio.h>
#define MAX 101
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, adj[MAX][MAX], c[MAX], d[MAX], f[MAX], t=0;

void visit(int);

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

  for ( i=1; i<=n; i++ ) if ( c[i] == WHITE ) visit(i);

  for ( i=1; i<=n; i++ ) printf( "%d %d %d\n" , i , d[i] , f[i] );

  return 0;
}

void visit(int u) {
  int i;
  
  c[u] = GRAY;
  d[u] = ++t;
  for ( i=1; i<=n; i++ ) if ( (adj[u][i] == 1) && (c[i] == WHITE) ) visit(i);
  c[u] = BLACK;
  f[u] = ++t;
}



Measured memory_bytes: 2108
#include<iostream>
#include<cstdio>
using namespace std;
int n;long long l,a[101000];
int main()
{
	scanf("%d%lld",&n,&l);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	int i;for(i=1;i<n;i++)if(a[i]+a[i+1]>=l)break;
	if(i==n)return 0*puts("Impossible");
	puts("Possible");
	for(int j=1;j<i;j++)printf("%d\n",j);
	for(int j=n-1;j>=i;j--)printf("%d\n",j);
	return 0;
}

Measured memory_bytes: 1536
from collections import defaultdict


def main():
    height, width, target_count = [int(x) for x in input().split()]
    count_by_height = defaultdict(int)
    count_by_width = defaultdict(int)
    bomb_is = set()
    for _ in range(target_count):
        bom_h, bom_w = [int(x) - 1 for x in input().split()]
        count_by_height[bom_h] += 1
        count_by_width[bom_w] += 1
        bomb_is.add((bom_h, bom_w))
    max_h = max(v for v in count_by_height.values())
    max_w = max(v for v in count_by_width.values())
    max_h_index = [i for i, x in count_by_height.items() if x == max_h]
    max_w_index = [i for i, x in count_by_width.items() if x == max_w]
    no_cross = any(
        (hh, ww) not in bomb_is for hh in max_h_index for ww in max_w_index)
    return max_h + max_w - (not no_cross)


if __name__ == '__main__':
    ans = main()
    print(ans)


Measured memory_bytes: 185640
#include <iostream>
using namespace std;
int main()
{
    int n;//n=100a+10b+c d=10b+c
    cin>>n;
    int c=n%10;int d=n%100;
    int a=(n-d)/100;
    
    if(a==c)
        cout<<"Yes";
    else
        cout<<"No";
        
    
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<math.h>
#include<string>
#include<cstdlib>
#include<sstream>

typedef long long ll;

using namespace std;

int main()
{
	string input, j;
	ll x = 0, total = 0;

	cin >> input;

	for(int i = 0; i < input.length(); i++)
	{
		j = input[i];
		stringstream in(j);
		in >> x;
		total = total + x;
	}
	
	if(total % 9 == 0)
		cout << "Yes";
	else
		cout << "No";

}



Measured memory_bytes: 3780
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


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

const int mod = 1000000007;
int f[100][10];
int p[100][11];
int joshino[10];
int main(){
  int n;
  cin >> n;

  

  rep(i, n){
    rep(j, 10){
      cin >> f[i][j];
    }
  }


  rep(i, n){
    rep(j, 11)  cin >> p[i][j];
  }

  ll ans = LONG_MIN;


  for(int bit = 1; bit < (1 << 10); ++bit){
    ll profit = 0;

    for(int i = 0; i < n; ++i){
      int c = 0;
      for(int j = 0; j < 10; ++j){
        c += f[i][j] && ((bit >> j) & 1);
        
      }
      profit += p[i][c];
    }

    ans = max(profit, ans);
  }

  cout << ans << endl;


}


Measured memory_bytes: 256
def solve():
    N = int(input())
    from collections import defaultdict
    X, Y = defaultdict(list), defaultdict(list)
    dx, dy = defaultdict(list), defaultdict(list)
    for i in range(N):
        x, y, U = list(input().split())
        x, y = int(x), int(y)
        X[x].append((y, U))
        Y[y].append((x, U))
        dy[x+y].append((x-y, U))
        dx[x-y].append((x+y, U))
    ans = float("inf")
    for key in X.keys():
        X[key].sort()
        for i in range(1, len(X[key])):
            y1, dir1 = X[key][i-1]
            y2, dir2 = X[key][i]
            if dir1 == "U" and dir2 == "D":
                ans = min(ans, 5*y2-5*y1)
    for key in Y.keys():
        Y[key].sort()
        for i in range(1, len(Y[key])):
            y1, dir1 = Y[key][i-1]
            y2, dir2 = Y[key][i]
            if dir1 == "R" and dir2 == "L":
                ans = min(ans, 5*y2-5*y1)
    for key in dx.keys():
        dx[key].sort()
        for i in range(1, len(dx[key])):
            y1, dir1 = dx[key][i-1]
            y2, dir2 = dx[key][i]
            if (dir1 == "U" and dir2 == "L") or (dir1 == "R" and dir2 == "D"):
                ans = min(ans, 5*y2-5*y1)
    for key in dy.keys():
        dy[key].sort()
        for i in range(1, len(dy[key])):
            y1, dir1 = dy[key][i-1]
            y2, dir2 = dy[key][i]
            if (dir1 == "R" and dir2 == "U") or(dir1 == "D" and dir2 == "L"):
                ans = min(ans, 5*y2-5*y1)
    if ans == float("inf"):
        print("SAFE")
    else:
        print(ans)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 215360
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0].to!int;
    auto M = s[1];
    auto edges = new int[][](N);
    foreach (_; 0..M) {
        s = readln.split.map!(to!int);
        edges[s[0]-1] ~= s[1]-1;
        edges[s[1]-1] ~= s[0]-1;
    }


    int[][] groups;
    bool[] used = new bool[](N);
    int[] color = new int[](N);
    color.fill(-1);

    void dfs1(int n, int g) {
        if (used[n]) return;
        used[n] = true;
        groups[g] ~= n;
        foreach (m; edges[n]) if (used[n]) dfs1(m, g);
    }

    bool dfs2(int n, int c) {
        if (color[n] != -1) return color[n] == c;
        color[n] = c;
        foreach (m; edges[n]) {
            if (!dfs2(m, c^1)) return false;
        }
        return true;
    }


    int gn = 0;
    bool[] is_bi;
    foreach (i; 0..N) if (!used[i]) {groups ~= (new int[](0)); dfs1(i, gn++);}
    foreach (g; 0..gn) is_bi ~= dfs2(groups[g][0], g);

    long ans = 0;

    long G = groups.length;
    long one = groups.map!(g => g.length == 1).sum;
    long bi = is_bi.sum - one;
    long other = G - one - bi;

    ans += one * 2 * N - one * one;
    ans += bi * 2 + other;
    ans += bi * (bi - 1) * 2;
    ans += other * (other - 1);
    ans += other * bi * 2;

    ans.writeln;
}


Measured memory_bytes: 25596
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define N 300010
#define M 500010

typedef long long ll;
const int INF = 1 << 30;
const int Mod = 1000000007;

int main()
{
	//freopen("in.in", "r", stdin);
	//freopen("out.out", "w", stdout);
	
	ll n, a, b;
	cin >> n >> a >> b;
	if (a > b)
	{
		cout << 0 << endl;
		return 0;
	}
	if (n == 1)
	{
		if (a == b) cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	cout << b * (n - 2) - a * (n - 2) + 1 << endl;
	
	return 0; 
}

Measured memory_bytes: 256
import Data.Array
import Data.List

main = do
  getLine -- n
  co <- getContents
  let ss = lines co
  let ans = compute ss
  putStrLn ans

-- 要は、全ての文字について、その個数の最小値だけ繰り返したものを作ればいいのかな。

compute :: [String] -> String
compute ss = buildString $ map minimum $ transpose $ map (elems.buildArray) ss

buildArray :: String -> Array Char Int
buildArray s = accumArray (+) 0 ('a','z') [ (c,1) | c <- s ]

buildString :: [Int] -> String
buildString ns = [ c | (c,i) <- zip ['a'..'z'] ns, _ <- [1..i] ]


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

int main() {
  int a[3], m = 0;
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a+3);
  while(1) {
    if(a[0] == a[1] && a[1] == a[2]) {
      cout << m;
      return 0;
    } else {
      if(a[0] == a[1] && a[2]-a[1] == 1) {
        cout << m+1;
        return 0;
      } else {
        a[0] += 2;
        m++;
        sort(a, a+3);
      }
    }
  }
}

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

int n, a, b, c;
vector<int> x;

int func(vector<int> v){
	int res = 1e9;
	if(v.size() > 3){
		for(size_t i=0; i<v.size(); ++i)
			for(size_t j=i+1; j<v.size(); ++j){
				vector<int> w;
				for(size_t k=0; k<v.size(); ++k){
					if(k == i || k == j) continue;
					w.push_back(v[k]);
				}
				w.push_back(v[i]+v[j]);
				sort(w.begin(), w.end());
				res = min(res, func(w)+10);
			}
	}
	for(size_t i=0; i<v.size(); ++i)
		for(size_t j=i+1; j<v.size(); ++j)
			for(size_t k=j+1; k<v.size(); ++k)
				res = min(res, abs(c-v[i])+abs(b-v[j])+abs(a-v[k]));
//	cout << v.size() << " " << res << "\n";
//	for(size_t i=0; i<v.size(); ++i)
//		cout << v[i] << " \n"[i+1==v.size()];
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> a >> b >> c;
	x.resize(n);
	for(int i=0; i<n; ++i) cin >> x[i];
	sort(x.begin(), x.end());
	cout << func(x) << "\n";
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


class UnionFind:
    def __init__(self, size):
        self.parent = list(range(size))
        self.rank = [0] * size

    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

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


N, M = map(int, input().split())
uf = UnionFind(N+1)
for _ in range(M):
    X, Y, Z = map(int, input().split())
    uf.unite(X, Y)
root = set()
for i in range(1, N+1):
    root.add(uf.find(i))
print(len(root))


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

#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'

int main()
{
 fastIO();
 long long s , w , ans ;
 
 cin>>s>>w;
 
 if(w>=s)
 {
 	cout<<"unsafe"<<endl;
 	
 }
 else if(s>w)
 {
 	cout<<"safe" <<endl;
 }

return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
 
int combi(int n, int s, int min)
{
    int i, ans;
 
    if (min == 10 || min > s) return 0;
    if (n == 1) return s < 10;
 
    ans = 0;
    for (i = min; i < 10; i++) ans += combi(n - 1, s - i, i+1);
    return ans;
}
 
int main()
{
    int n, s;
 
    while (1) {
        scanf("%d%d", &n, &s);
        if (n < 1) break;
        printf("%d\n", combi(n, s, 0));
    }
    return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K, X;
  cin >> K >> X;
  int l=max(-1000000,X-(K-1));
  int r=min(1000000,X+(K-1));
  for(int i=l;i<=r;i++){
    cout << i << endl;
  }
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.Char

stdev n s = sqrt . (/n) . sum . map ((**2) . subtract (sum s / n)) $ s

main = do
    n <- readLn
    when (n/=0) $ stdev n <$> (map read . words <$> getLine) >>= print >> main

Measured memory_bytes: 4984
gets
a=10.times.map{gets.split.map &:to_i}
10.times{|k|10.times{|i|10.times{|j|
	a[i][j]=[a[i][j],a[i][k]+a[k][j]].min
}}}
r=0
$<.each{|e|
	e.split.map(&:to_i).each{|i|r+=a[i][1] if i!=-1}
}
p r

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  vector<int> s(n);
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
    sum += s[i];
  }
  if ((sum % 10) != 0) {
    cout << sum << "\n";
    return 0;
  }
  sort(s.begin(), s.end());

  for (size_t i = 0; i < s.size(); ++i) {
    if ((s[i] % 10) != 0) {
      cout << sum - s[i] << "\n";
      return 0;
    }
  }
  cout << 0 << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define eb emplace_back
#define MOD 1000000007
#define int long long
using namespace std;
#define s second
#define f first

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n];
    bool vis[n] = {0};
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        a[i]--;
    }
    int ans=1, i=0;
    bool flag=false;
    while( !vis[i] )
    {
        if( a[i] == 1 )
        {
            flag = true;
            break;
        }
        vis[i] = true;
        i = a[i];
        ans++;
    }
    if( flag )
        cout << ans;
    else
        cout << "-1";
}

Measured memory_bytes: 4508
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
ll gcd(ll a,ll b){
	if(b==0)
	return a;
	return gcd(b,a%b);
}
string toBin(ll a) {
	string res = "";
	while (a) {
		res += char((a & 1) + '0');
		a >>= 1;
	}
	reverse(res.begin(), res.end());
	return res;
}
const int mod = 1e9+7;
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow!=0){
        if(pow&1==1){
            ans = ans*base;
            ans = ans%mod;
        }
        base *= base;
        base%=mod;
        pow/=2;
    }
    return ans;
}
ll inv(ll x){
    return expo(x,mod-2);
}
bool isPal(string ss){
    int len = ss.length();
    for(int i = 0 ; i<len/2 ; i++){
	int comp = len-i-1;
	if(ss[i]!=ss[comp])
		return false;
	}
    return true;
}
double pi = 3.141592653589793238462643;
double error = 0.0000001;
/* -------Template ends here-------- */

const int M = 100001;

ll arr[M];
int main(){
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
   // pre();
    int n;
    si(n);
    ll ans = 0;
    ll tem = 0;
    for(int i = 0 ; i<n ; i++){
        ll el;
        sll(el);
        if(el == 0){
            ans += (tem/2);
            tem = 0;
        }
        else{
            tem+=el;
        }
    }
    ans += (tem/2);


    cout<<ans;







}














Measured memory_bytes: 256
a=[]
for _ in range(int(input())):
    ar=list(map(int,input().split()))
    if len(ar)==1: x,=ar
    else: x,y=ar
    if x==0:
        a.append(y)
    if x==1:
        print(a[y])
    if x==2:
        a.pop()



Measured memory_bytes: 13368
N, M = gets.chomp.split.map(&:to_i)
ans = 0
(1..M).each do |m|
  break if m*m > M and m > N
  if M % m == 0
    ans = [ans, M / m].max if m >= N
    ans = [ans, m].max if M / m >= N
  end
end
puts ans

Measured memory_bytes: 1788
package main

import "fmt"

func main() {
	var n int
	var s, t string
	fmt.Scan(&n, &s, &t)

	for i := 0; i < n; i++ {
		ok := true
		for j := 0; j < n-i; j++ {
			if i+j < n && s[j+i] != t[j] {
				ok = false
				break
			}
		}
		if ok {
			fmt.Println(i + n)
			return
		}
	}
	fmt.Println(n + n)
}


Measured memory_bytes: 512
# A - Colorful Transceivers
# https://atcoder.jp/contests/abc097/tasks/abc097_a

a, b, c, d = map(int, input().split())

result = 'No'

if abs(a - c) <= d:
    result = 'Yes'
elif abs(a - b) <= d and abs(b - c) <= d:
    result = 'Yes'

print(result)


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

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif

    int a, b;

    cin >> a >> b;

    int socks = 1;
    int cnt = 0;
    while (socks < b) {
        socks += a - 1;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
from functools import lru_cache
N, A, B, C, *L = map(int, open(0).read().split())


@lru_cache(None)
def popcnt(n):
    return bin(n).count('1')


@lru_cache(None)
def synth(bit):
    length = 0
    for i in range(N):
        if bit >> i & 1:
            length += L[i]
    return length


ans = 1 << 60
for bit1 in range(1, 1 << N):
    if popcnt(bit1) >= N-1:
        continue
    length1 = synth(bit1)

    for bit2 in range(1, 1 << N):
        if bit1 & bit2:
            continue
        if popcnt(bit1 | bit2) == N:
            continue
        length2 = synth(bit2)

        for bit3 in range(1, 1 << N):
            if bit1 & bit3 or bit2 & bit3:
                continue

            length3 = synth(bit3)
            c, b, a = sorted([length1, length2, length3])

            cost = 10*(popcnt(bit1 | bit2 | bit3)-3) + abs(C-c) + abs(B-b) + abs(A-a)
            if cost < ans:
                ans = cost

print(ans)


Measured memory_bytes: 9528
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<vin> vvin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
const int MOD=1e9+7;
int main(){
  ll a,b;cin>>a>>b;
  cout<<a*b<<endl;
  
}


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

int v[60];
int c[60];

vector<int> xy;

int main()
{
    int a;
    cin >> a;
    int i;
    int sum = 0;
    for(i=0;i<a;i++)
    {
        cin >> v[i];
    }
    for(i=0;i<a;i++)
    {
        cin >> c[i];
    }
    for(i=0;i<a;i++)
    {
        if(v[i] > c[i])
        sum += v[i] - c[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int c = b - a;
    cout << (c + 1) * c / 2 - b << endl;
    return 0;
}


Measured memory_bytes: 256