akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct edge{
  int to,cost,rcost;
  edge(){}
  edge(int to,int cost,int rcost):to(to),cost(cost),rcost(rcost){}
};
signed main(){
  int n,t;
  cin>>n>>t;
  string a,b;
  cin>>a>>b;
  int c[n];
  vector<string> vs[n];
  vector<int> vi[n];
  for(int i=0;i<n;i++){
    cin>>c[i];
    vs[i].resize(c[i]);
    vi[i].resize(c[i]-1);
    for(int j=0;j<c[i];j++) cin>>vs[i][j];
    for(int j=0;j<c[i]-1;j++) cin>>vi[i][j];
  }
  int cnt=0;
  map<string,int> m;
  m[a]=cnt++;
  m[b]=cnt++;
  for(int i=0;i<n;i++)
    for(int j=0;j<c[i];j++)
      if(!m.count(vs[i][j]))
	m[vs[i][j]]=cnt++;
  int sum=0;
  for(int i=0;i<n;i++) sum+=c[i];
  vector<vector<edge> > G(cnt+sum);
  int tmp=cnt;
  for(int i=0;i<n;i++){
    for(int j=0;j<c[i];j++){
      G[m[vs[i][j]]].push_back(edge(tmp,t,0));
      G[tmp].push_back(edge(m[vs[i][j]],0,t));
      if(j<c[i]-1){
	G[tmp].push_back(edge(tmp+1,vi[i][j],vi[i][j]));
	G[tmp+1].push_back(edge(tmp,vi[i][j],vi[i][j]));
      }
      tmp++;
    }
  }
  assert(tmp==cnt+sum);
  int inf=1LL<<55LL;
  vector<int> dist(tmp,inf);
  typedef pair<int,int> P;
  priority_queue<P,vector<P>,greater<P> > q;
  dist[m[a]]=0;
  q.push(P(0,m[a]));
  while(!q.empty()){
    P p=q.top();q.pop();
    int d=p.first,v=p.second;
    if(dist[v]<d) continue;
    for(edge e:G[v]){
      if(dist[e.to]>dist[v]+e.cost){
	dist[e.to]=dist[v]+e.cost;
	q.push(P(dist[e.to],e.to));
      }
    }
  }
  if(dist[m[b]]==inf){
    cout<<-1<<endl;
    return 0;
  }
  vector<int> dist2(tmp,inf);
  dist2[m[b]]=0;
  q.push(P(0,m[b]));
  while(!q.empty()){
    P p=q.top();q.pop();
    int d=p.first,v=p.second;
    //cout<<d<<" "<<v<<endl;
    if(dist2[v]<d) continue;
    for(edge e:G[v]){
      //cout<<e.to<<" "<<e.rcost<<":"<<dist[e.to]<<" "<<dist[v]<<endl;
      if(dist[e.to]+e.rcost!=dist[v]) continue;
      //cout<<e.to<<":"<<dist2[e.to]<<" "<<dist2[v]+(0<=e.to&&e.to<cnt)<<endl;
      if(dist2[e.to]>dist2[v]+(0<=e.to&&e.to<cnt)){
	dist2[e.to]=dist2[v]+(0<=e.to&&e.to<cnt);
	q.push(P(dist2[e.to],e.to));
      }
    }
  }
  cout<<dist[m[b]]-t<<" "<<dist2[m[a]]-1<<endl;
  return 0;
}

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

int main() {
  string O,E;
  cin >> O >> E;
 
  vector<char> o(O.size());
  for (int i = 0; i < O.size(); i++) {
    o.at(i) = O.at(i);
  }
  vector<char> e(E.size());
  for (int i = 0; i < E.size(); i++) {
    e.at(i) = E.at(i);
  }
  
  for (int i = 0; i < E.size(); i++) {
    cout << o.at(i) << e.at(i);
  }
  
  if (O.size() > E.size()){
    cout << o.at(O.size()-1) << endl;
  }
  else {
    cout << endl;
  }
}
  
  

Measured memory_bytes: 256
/* it was worth becoming a chemist */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "cardgame"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 1e6 + 5;

int n;
ll a[MAXN];

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

	cin >> n;
	n *= 3;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort (a + 1, a + 1 + n);
	ll sum = 0;
	int l = 1, r = n;
	for (int i = 1; i <= n / 3; i++) {
		sum += a[r - 1];
		r -= 2;
		l++;
	}
	cout << sum;
	return 0;
}


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

int main() {
  string S;
  cin >> S;
  deque<char> s;
  for (char c : S) s.push_back(c);

  int Q;
  cin >> Q;
  bool reversed = false;
  for (int i = 0; i < (int)(Q); ++i) {
    int T;
    cin >> T;
    if (T == 1) {
      reversed = !reversed;
    } else {
      int F;
      char C;
      cin >> F >> C;
      if ((F == 1) ^ reversed) {
        s.push_front(C);
      } else {
        s.push_back(C);
      }
    }
  }

  if (reversed) reverse((s).begin(), (s).end());
  for (char c : s) cout << c;
  cout << endl;

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M), B(M);
  REP(i, 0, M) cin >> A[i] >> B[i];

  map<pll, ll> p;
  REP(i, 0, M) p[pll(A[i], B[i])]++;

  vector<ll> x(N, M);
  for (auto q : p) {
    ll a = q.first.first, b = q.first.second, cnt = q.second;
    x[0] += a * cnt;
    for (ll j = b - a; j - 1 < N; j += b) {
      x[j - 1] -= b * cnt;
    }
  }

  REP(i, 0, N - 1) x[i + 1] += x[i];
  REP(i, 0, N) cout << x[i] << endl;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.size();
	ll sum = 0;
	rep(i, n) {
		if (s[i] != t[i]) sum++;
	}
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 3844
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi t(n+1,0),v(n+1,0);
    rep(i,n) cin >> t[i+1];
    rep(i,n) cin >> v[i+1];
    t.pb(0);
    v.pb(0);
    int sum = 0;
    vi l(n+2),r(n+2);
    rep(i,n+2) {
        l[i] = sum;
        sum += t[i] * 2;
        r[i] = sum;
    }
    vd mx(sum+1,inf);
    rep(i,sum+1) {
        rep(j,n+2) {
            double now;
            if(i < l[j]) {
                now = v[j]+0.5*(l[j]-i);
            } else if(i > r[j]) {
                now = v[j]+0.5*(i-r[j]);
            } else {
                now = v[j];
            }
            chmin(mx[i],now);
        }
    }
    double ans = 0;
    rep(i,sum) ans += (mx[i]+mx[i+1])*0.25;
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef pair<char, int> P;

int main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    vector<P> T;
    int cnt = 1;
    char prev = S[0];
    if(N == 1) T.push_back(P(prev, cnt));
    for(int i=1; i<N; ++i) {
        if(prev != S[i]) {
            T.push_back(P(prev, cnt));
            prev = S[i];
            cnt = 1;
        } else {
            ++cnt;
        }
        if(i == N - 1) T.push_back(P(prev, cnt));
    }

    int res = 0;
    cnt = 0;
    int l = 0, r = 0;
    while(r < T.size()) {
        if(K == 0 && T[r].first == '0') { 
            cnt -= T[l].second;
            ++l;
            if(T[l].first == '0') {
                cnt -= T[l].second;
                ++l;
            }
            ++K;
        }
        cnt += T[r].second;
        if(T[r].first == '0') --K;
        ++r;
        res = max(res, cnt);
    }

    cout << res << endl;
}

Measured memory_bytes: 1528
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<deque>
using namespace std;
int n,m,i,j,x,ans;
map<int,int> s;
vector<int> v;
int main()
{
	cin>>n>>m;
	while (n--)
	{
		cin>>x;
		s[x]++;
	}
	if (s.size()<=m)
	{
		cout<<0;
		return 0;
	}
	for (map<int,int>::iterator it=s.begin();it!=s.end();it++)
	{
		v.push_back(it->second);
	}
	sort(v.begin(),v.end());
	for (i=0;i+m<s.size();i++) ans+=v[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 10748
from operator import itemgetter

n=int(input())
red=[]
blue=[]
for i in range(n):
    a,b=map(int,input().split())
    red.append([a,b])

for i in range(n):
    c,d=map(int,input().split())
    blue.append([c,d])

blue=sorted(blue)  #青をxの小さい順にソート

red=sorted(red,key=itemgetter(1),reverse=True)

ans = 0

for i in blue:
    for j in red:
        if i[0]>j[0] and i[1]>j[1]:
            ans += 1
            red.remove(j)
            break

print(ans)

Measured memory_bytes: 3064
math_line = list(map(int,input().split()))
input_line = list(map(int,input().split()))

area = math_line[0]*math_line[1]
black_cell = math_line[0]*input_line[1] + math_line[1]*input_line[0]
duplicate =  black_cell - input_line[0]*input_line[1]
white_cell = area - duplicate

print(white_cell)

Measured memory_bytes: 3064
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_083_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(11).
    01 A      PIC 9(2).
    01 B      PIC 9(2).
    01 C      PIC 9(2).
    01 D      PIC 9(2).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO A B C D.

    IF A + B < C + D THEN
        DISPLAY "Right"
    ELSE
        IF A + B = C + D THEN
            DISPLAY "Balanced"
        ELSE
            DISPLAY "Left"
        END-IF
    END-IF.

    STOP RUN.


Measured memory_bytes: 384
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> f(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());
    ll l = -1, r = 1e12;
    while (l+1 < r) {
        ll c = (l+r)/2;
        ll s = 0;
        rep(i,n) {
            s += max(ll(0), a[i]-c/f[i]);
        }
        if (s <= k) r = c;
        else l = c;
    }
    cout << r << endl;
    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(A+B > C+D) {
    cout << "Left" << endl;
  } else if (A+B == C+D) {
    cout << "Balanced" << endl;
  } else if (A+B < C+D) {
    cout << "Right" << endl;
  }
}

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

int n,k,m,a,b,c,d;
string s;

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int main() {

	set<int> A;
	int x,y;
	vector<int> B;

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

		for (int i = 0; i < 30; i++) {
			int n;
			n = A.count(i+1);
			if (n == 0) {
				B.push_back(i+1);
			}
		}

		x = B[0];
		y = B[1];

		cout << min(x, y) << endl << max(x, y) << endl;
}


Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;

struct Node{
	int key;
	Node *parent;
	Node *left;
	Node *right; 
};
Node *root, *NIL;
void insert(int k){
	Node *x = root,*y = NIL,*z;
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	while(x!=NIL){
		y = x;
		if(z->key<x->key)
			x = x->left;
		else
			x = x->right;
	}
	z->parent = y;
	if(y==NIL)
		root = z;
	else{
		if(z->key<y->key)
			y->left = z;
		else
			y->right = z;
	}
}
void pre(Node *n){
	if(n==NIL) return;
	printf(" %d",n->key);
	pre(n->left);
	pre(n->right);
}
void in(Node *n){
	if(n==NIL) return;
	in(n->left);
	printf(" %d",n->key);
	in(n->right);
}
int main() {
	int n,x;
	char s[10];
	scanf("%d",&n);
	while(n--){
        scanf("%s",s);
		if(s[0]=='i'){
			scanf("%d",&x);
			insert(x);
		}else{
			in(root);
			printf("\n");
			pre(root);
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 26560
import java.util.*;

public class Main{

public static void main(String[] args) {
Scanner scn=new Scanner (System.in);
int x=scn.nextInt();
int n=scn.nextInt();
int []arr=new int[n];
boolean team=false;
for(int i=0;i<n;i++){
    arr[i]=scn.nextInt();
    if(arr[i]==x){
        team=true;
    }
}
Arrays.sort(arr);
if(arr.length==0){
    System.out.println(x);
    return;
}
if( team==false){
    System.out.println(x);
    return;
}
int idx=0;
for(int i=0;i<arr.length;i++){
    if(arr[i]==x){
        idx=i;
    }
    
}

int p1=idx+1;
int p2=idx-1;
int val=1;
while(p1!=arr.length && p2!=-1){
    if(arr[p2]!=x-val){
      
        System.out.println(x-val);
        return;
    }
    if(arr[p1]!=x+val){
         
        System.out.println(x+val);
        return;
    }
    val++;
    p2--;
    p1++;
}
if(p1!=arr.length){

   System.out.println(x-val);
   return;
}
if(p2!=-1){
    
    if(arr[p2]==x-val){
         
        System.out.println(x+val);
        return;
    }
      
     System.out.println(x-val);
     return;
}
System.out.println(arr[0]-1);



 }
}

Measured memory_bytes: 35792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<functional>

#define vec2c vector<vector<char>>
#define vec2i vector<vector<int>>
#define vecc vector<char>
#define vecs vector<string>
#define veci vector<int>
#define rep(i, n) for(int i=0; i < (int)(n); i++)
#define rrep(i, n) for(int i=(int)(n); i>=0;i--)

using namespace std;

int sumDig(int num) {
	int dig, sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}
float calc(float y2, float y1, float x2, float x1, float x) {
	float tmp = (y2 - y1) / (x2 - x1);
	float tmp2 = (x - x1);
	return (tmp * tmp2) + y1;
}
veci inVeci(int n) {
	int in;
	veci vec;
	rep(i, n) {
		cin >> in;
		vec.push_back(in);
	}
	return vec;
}
vecc inVecc( int n) {
	char in;
	vecc vec;
	rep(i, n) {
		cin >> in;
		vec.push_back(in);
	}
	return vec;
}
vecs inVecs(int n) {
	string in;
	vecs vec;
	rep(i, n) {
		cin >> in;
		vec.push_back(in);
	}
	return vec;
}


int main()
{
	int n;
	int count =0;

	cin >> n;

	if ( 2 % n == 0) cout << '2' << endl;
	else if (n % 2 == 0) cout << n << endl;
	else{
		cout << 2 * n << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

using R = double;
constexpr R pi = acos((R)-1), eps = 1e-10, inf = 1e10;

int sgn(R a) { return (a > eps) - (a < -eps); }
int sgn(R a, R b) { return sgn(a - b); }
using P = complex<R>;
istream& operator>>(istream& i, P& p) { R x, y; i >> x >> y; p = P(x, y); return i; }
ostream& operator<<(ostream& o, P p) { return o << fixed << setprecision(15) << real(p) << ' ' << imag(p); }
bool cmp(P p, P q) { return 2 * sgn(real(p), real(q)) + sgn(imag(p), imag(q)) < 0; }
bool eql(P p, P q) { return !cmp(p, q) and !cmp(q, p); }
R dot(P p, P q) { return real(conj(p) * q); }
R crs(P p, P q) { return imag(conj(p) * q); }
// -2: back, -1: cw, 0: on, 1: ccw, 2: front
int ccw(P p, P q) {
  int s = sgn(crs(p, q));
  if (s) return s;
  if (dot(p, q) < 0) return -2;
  if (dot(p, q - p) > 0) return 2;
  return 0;
}
int ccw(P o, P p, P q) { return ccw(p - o, q - o); }
struct L {
  P s, t;
  P vec() const { return t - s; }
  R abs() const { return std::abs(vec()); }
  R arg() const { return std::arg(vec()); }
};
int ccw(L s, P p) { return ccw(s.s, s.t, p); }

P proj(P p, L l) {
  P e = l.vec() / l.abs();
  return l.s + dot(p - l.s, e) * e;
}
P refl(P p, L l) { return (R)2 * proj(p, l) - p; }
R distPP(P p, P q) { return abs(q - p); }
R distPL(P p, L l) { return distPP(p, proj(p, l)); }
R distPS(P p, L s) {
  P q = proj(p, s);
  if (!ccw(s, q)) return distPP(p, q);
  return min(distPP(p, s.s), distPP(p, s.t));
}
R distLL(L l, L m) {
  if (sgn(crs(l.vec(), m.vec()))) return 0;
  return distPL(l.s, m);
}
R distLS(L l, L s) {
  if (ccw(l, s.s) * ccw(l, s.t) != 1) return 0;
  return min(distPL(s.s, l), distPL(s.t, l));
}
R distSS(L s, L t) {
  if (ccw(s, t.s) * ccw(s, t.t) <= 0 and ccw(t, s.s) * ccw(t, s.t) <= 0) return 0;
  return min({distPS(s.s, t), distPS(s.t, t), distPS(t.s, s), distPS(t.t, s)});
}
P intxn(L l, L m) {
  assert(sgn(crs(l.vec(), m.vec())));
  return l.s + crs(m.s - l.s, m.vec()) / crs(l.vec(), m.vec()) * l.vec();
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<P> p(n); for (auto&& e : p) cin >> e;
  V<P> q(m); for (auto&& e : q) cin >> e;
  R res = inf;
  auto fn = [&]() -> void {
    L s{q[0], q[1]};
    VV<R> g(n, V<R>(n, inf));
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (sgn(distSS({p[i], p[j]}, s))) {
      g[i][j] = distPP(p[i], p[j]);
    }
    bitset<1000> bs;
    V<R> d(n, inf);
    d[0] = 0;
    for (int _ = 0; _ < n; ++_) {
      int v = -1;
      for (int w = 0; w < n; ++w) if (!bs[w]) {
        if (v == -1 or d[w] < d[v]) v = w;
      }
      bs[v] = true;
      for (int w = 0; w < n; ++w) {
        d[w] = min(d[w], d[v] + g[v][w]);
      }
    }
    res = min(res, d[1] + s.abs());
  };
  fn();
  swap(n, m), swap(p, q);
  fn();
  if (res == inf) cout << -1 << '\n';
  else cout << fixed << setprecision(15) << res << '\n';
}


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

typedef long long ll;

const int N = 1e5 + 5;

vector<vector <int> > g(N);
vector <bool> vis(N);
vector <int> dp(N);
stack <int> topo;

void dfs(int u) {
    vis[u] = 1;
    for (auto v : g[u])
	if (!vis[v])
	    dfs(v);
    topo.push(u);
}

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

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
	int u, v; cin >> u >> v;
	g[u].push_back(v);
    }

    for (int i = 1; i <= n; i++)
	if (!vis[i])
	    dfs(i);
    
    for (; !topo.empty(); topo.pop()) {
	int u = topo.top();
	for (auto v : g[u])
	    dp[v] = max(dp[v], dp[u] + 1);
    }

    cout << *max_element(dp.begin() + 1, dp.begin() + n + 1) << '\n';
    return 0;
}


Measured memory_bytes: 8576
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)

main() {
    int n = 0;
    char c;
    while(1) {
        c = getwchar_unlocked();
        if(c!='\n')
            n = n * 10 + c - '0';
        else
            break;
    }
    int sqrtN = sqrt(n);
    ll ans = 0;
    ll d = (ll)(sqrtN) * (sqrtN + 1) * (2 * sqrtN + 1) / 6;
    rep2(i, 1, sqrtN) { ans += (i * (i + (n / i)) * ((n / i) + 1 - i)); }
    ans -= d;
    char wr[15];
    char *w = wr;
    while(ans) {
        *w = ans % 10 + '0';
        ans /= 10;
        w++;
    }
    while(1) {
        w--;
        putwchar_unlocked(*w);
        if(w == wr) break;
    }
}


Measured memory_bytes: 3712
N = gets.chomp.to_s
n = N.length
answer = 0
if n.even?
    (1..(n/2)).each do |e|
        answer += 9 * 10 ** (2 * e - 2)
    end
else
    (1..(n-1)/2).each do |e|
        answer += 9 * 10 ** (2 * e - 2)
    end
    answer += N.to_i + 1 - 10 ** (n - 1)
end
print answer

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    if(i < 10) ans++;
    else if(i >= 100 && i <= 999) ans++;
    else if(i >= 10000 && i <= 99999) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void Swap(int *x, int *y)
{
    int tmp;
    tmp = *x;
    *x = *y;
    *y = tmp;
}

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

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

    if (a > b){
        Swap(&a, &b);
    }
    if (b > c){
        Swap(&b, &c);
    }
    if (a > b){
        Swap(&a, &b);
    }

    printf("%d %d %d\n", a, b, c);

    return 0;
}

Measured memory_bytes: 596
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:usize,
        k:usize,
        xn:[i64;n],
    }
    let mut ans = std::i64::MAX;
    for j in 0..(n-k+1){
        let left = xn[j].abs()+(xn[j+k-1]-xn[j]).abs();
        let right = xn[j+k-1].abs() + (xn[j+k-1]-xn[j]).abs();
        ans = min(min(left,right),ans);
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
import sys
input = sys.stdin.readline
s = list(input().rstrip())
t = list(input().rstrip())
s = sorted(s)
t = sorted(t, reverse=True)
alpha2num = lambda c: ord(c) - ord("a")
if s == t:
    print("No")
    sys.exit()
for i in range(min(len(s), len(t))):
    x, y = s[i], t[i]
    if alpha2num(x) < alpha2num(y):
        print("Yes")
        sys.exit()
    elif alpha2num(x) > alpha2num(y):
        print("No")
        sys.exit()
if len(t) > len(s):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<random>
using namespace std;

int main(){

  vector<int> a(4);
  vector<int> b(4);
  while(cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]){

    vector<int> n(10, 0);
    int hit = 0;
    int blow = 0;
    for(int i=0; i<4; i++){
      if( a[i] == b[i] ){
        hit++;
        n[ a[i] ]--;
      }
    }

    for(int i=0; i<4; i++){
      n[ a[i] ]++;
      n[ b[i] ]++;
    }
    for(int i=0; i<10; i++){
      if( n[i] == 2 ) blow++;
    }

    cout << hit << " " << blow << endl;
  }

  return 0;
}




// EOF

Measured memory_bytes: 3044
#include <iostream>
using namespace std;
 
int main(){
     
    int data[20][20] = {0}, number, n;
    char mark;
     
    cin >> n;
     
    for(int i = 0; i < n; i++){
         
        cin >> mark >> number;
         
        if(mark == 'S'){    data[0][number - 1] = 1;}
        if(mark == 'H'){    data[1][number - 1] = 1;}
        if(mark == 'C'){    data[2][number - 1] = 1;}
        if(mark == 'D'){    data[3][number - 1] = 1;}
    }
     
    for(int i = 0; i < 4; i++){
        for(int j = 0; j < 13; j++){
             
            if(data[i][j] == 0){
                 
                if(i == 0){ cout << "S " << j+1 << endl;}
                if(i == 1){ cout << "H " << j+1 << endl;}
                if(i == 2){ cout << "C " << j+1 << endl;}
                if(i == 3){ cout << "D " << j+1 << endl;}
            }
        }
    }
     
    return 0;
}

Measured memory_bytes: 1160
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input!{
        source = src,
        n: isize,
    }

    let a = n % 1000;
    let b = if a == 0 {
        0 
    } else { 
        1000 - a 
    };
    return b.to_string();
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int e=0;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    for(int i=0;i<n;i++){
        if(a[i]%2!=0&&(i+1)%2!=0)e++;
    }
    printf("%d",e);
    return 0;
}

Measured memory_bytes: 3824
n = gets.to_i
n.times do |i|
	data = gets.chomp.split.map(&:to_f)
	if data[2]==data[0] or data[6]==data[4]
		if data[2]==data[0] and data[6]==data[4]
			puts "YES"
		else
			puts "NO"
		end
	else
		puts ((data[3]-data[1])/(data[2]-data[0]) == (data[7]-data[5])/(data[6]-data[4])) ? "YES" : "NO"
	end
end

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

int main() {
    long long A, B, K; cin >> A >> B >> K;
    if (A >= K) {
        cout << A - K << ' ' << B << endl;
    } else if (A + B >= K){
        cout << "0 " << A + B - K << endl;
    } else {
        cout << "0 0" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX 8000

signed main(){
    string s;
    cin >> s;
    int x,y;
    cin >> x >> y;
    vector<int> X, Y;
    int start_x;
    int cnt_F = 0, cnt_T = 0;
    REP(i,s.size()){
        if(s[i] == 'T'){
            if(cnt_T == 0) start_x = cnt_F;
            else if(cnt_T % 2 == 0) X.emplace_back(cnt_F);
            else Y.emplace_back(cnt_F);
            cnt_F = 0;
            cnt_T++;
        }else{
            cnt_F++;
        }
    }
    if(cnt_T == 0) start_x = cnt_F;
    else if(cnt_T % 2 == 0) X.emplace_back(cnt_F);
    else Y.emplace_back(cnt_F);
    vector<vector<bool>> dp_x(X.size() + 1, vector<bool>(MAX * 2 + 1, false)), dp_y(Y.size() + 1, vector<bool>(MAX * 2 + 1, false));
    dp_x[0][MAX + start_x] = true;
    for(int i = 0; i < X.size(); i++){
        for(int j = 0; j <= MAX * 2; j++){
            if(j - X[i] >= 0) dp_x[i + 1][j] = dp_x[i + 1][j] || dp_x[i][j - X[i]];
            if(j + X[i] <= MAX * 2) dp_x[i + 1][j] = dp_x[i + 1][j] || dp_x[i][j + X[i]];
        }
    }
    dp_y[0][MAX] = true;
    for(int i = 0; i < Y.size(); i++){
        for(int j = 0; j <= MAX * 2; j++){
            if(j - Y[i] >= 0) dp_y[i + 1][j] = dp_y[i + 1][j] || dp_y[i][j - Y[i]];
            if(j + Y[i] <= MAX * 2) dp_y[i + 1][j] = dp_y[i + 1][j] || dp_y[i][j + Y[i]];
        }
    }
    if(dp_x[X.size()][MAX + x] && dp_y[Y.size()][MAX + y]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

void Main()
{
    long a, b, c;
    cin >> a >> b >> c;
    if(c-a-b <= 0)
        cout << "No" << endl;
    else if(4*a*b < (c-a-b)*(c-a-b))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    // a^0.5 + b^0.5 < c^0.5
    // a + 2*(a*b)^0.5 + b < c
    // 2*(a*b)^0.5 < c-a-b
    // 4*a*b < (c-a-b)^2
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
int main(){
int n;
cin>>n;
vector<int>in(n);
rep(i,n)cin>>in[i];
rep(i,n-1)cout<<in[n-i-1]<<" ";
cout<<in[0]<<endl;
}

Measured memory_bytes: 1196
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <climits>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;

#define a n[0]
#define b n[1]
#define c n[2]
#define d n[3]

int calc(int x, int y, int op)
{
	switch (op)
	{
	case '+':return x + y;
	case '-':return x - y;
	case '*':return x * y;
	}
}

int main()
{
	vector<int> n(4);
	string op = "+++---***";
	while (cin >> a >> b >> c >> d && a || b || c || d)
	{
		bool flag = true;
		sort(all(n));
		do
		{
			sort(all(op));
			do
			{
				if (calc(calc(calc(a, b, op[0]), c, op[1]), d, op[2]) == 10)
				{
					printf("(((%d%c%d)%c%d)%c%d)\n", a, op[0], b, op[1], c, op[2], d);
					flag = false;
					break;
				}

				if (calc(calc(a, b, op[0]), calc(c, d, op[2]), op[1]) == 10)
				{
					printf("((%d%c%d)%c(%d%c%d))\n", a, op[0], b, op[1], c, op[2], d);
					flag = false;
					break;
				}

				if (calc(calc(a, calc(b, c, op[1]), op[0]), d, op[2]) == 10)
				{
					printf("((%d%c(%d%c%d))%c%d)\n", a, op[0], b, op[1], c, op[2], d);
					flag = false;
					break;
				}

				if (calc(a, calc(calc(b, c, op[1]), d, op[2]), op[0]) == 10)
				{
					printf("(%d%c((%d%c%d)%c%d))\n", a, op[0], b, op[1], c, op[2], d);
					flag = false;
					break;
				}

				if (calc(a, calc(b, calc(c, d, op[2]), op[1]), op[0]) == 10)
				{
					printf("(%d%c(%d%c(%d%c%d)))\n", a, op[0], b, op[1], c, op[2], d);
					flag = false;
					break;
				}

			} while (next_permutation(all(op)));

		} while (next_permutation(all(n)) && flag);
		if (flag)
		{
			cout << 0 << endl;
		}
	}
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;

int main() {
	cout << fixed << setprecision(0);
	int N, M;
	cin >> N >> M;
	double passable = pow(0.5, M);
	//1回で通る確率:
	double pass = 0;
	for (size_t i = 1; i<1000; i++)
	{
		pass += (double)((N-M)*100+M * 1900)*i * pow((1.0 - passable), i - 1) * passable;
		//100 5cout << pass << endl;
	}
	
	cout << pass;
}

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

int main()
{
  int a = 0, b = 0;
  string s;

  cin >> s;
  for (int i = 0; i < 3; i++)
  {
    if (s[i] == 'A')
      a++;
    else
      b++;
  }
  if (a > 0 && b > 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
  int n;
  
  cin >> n;
  vector<ll> a(n+1);
  a.at(0)=0;
  ll sum=0;
  ll c;
  for(int i=1;i<n+1;i++){
    cin >> a.at(i);
    if(a.at(i-1)>a.at(i)){
      
      c = a.at(i-1)-a.at(i);
      sum += c;
      a.at(i) = a.at(i-1);
    }
  }
  
  cout << sum;
  
  return 0;
}


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

int main(){
	
	
	int arr[20];
	
	for(int i =1;i<=5;i++){
		
		cin>> arr[i];
	}
	for(int i=1;i<=5;i++){
		
		if(arr[i]==0){
			cout<< i;
		}
	}
	
	return 0;
}

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

using namespace std;

int n,i,j,a[100005];

bool check(int s){
	vector <int> t;
	
	for(i = 0; i < n; i++){
		if(i == s) continue;
		t.push_back(a[i]);
	}
	
	long long siz = a[s];
	
	int cnt = 0;
	
	for(i = 0; i < t.size(); i++){
		if(t[i] <= 2LL * siz){
			siz += t[i];
			cnt++;
		}
	}
	
	return cnt == n - 1;
}

int main(){
	scanf("%d", &n);
	
	for(i = 0; i < n; i++)
	scanf("%d", &a[i]);
	
	sort(a, a + n);
	
	int lb = -1;
	int ub = n;
	
	while(ub - lb > 1){
		int mid = (lb + ub) / 2;
		
		if(check(mid))
		ub = mid;
		else
		lb = mid;
	}
	
	printf("%d\n", n - ub);
}


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

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ll x;
  cin >> x;
  ll fh = x / 500;
  ll f = (x - fh * 500) / 5;
  ll ans = 1000 * fh + 5 * f;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
 
using namespace std;

int main (){
    int N,ans=0,A=0,B=0;

	cin >> N;

    string s[N];
    int c[3];

    rep(i,0,N){
        cin >> s[i];
    }

    rep(i,0,3){
        c[i] = 0;
    }

    rep(i,0,N){
        rep(j,0,s[i].size()-1){
            if(s[i][j]=='A' && s[i][j+1]=='B'){
                ans++;
            }
        }
        A=0;
        B=0;
        if(s[i][0]=='B'){
            B++;
        }
        if(s[i][s[i].size()-1]=='A'){
            A++;
        }
        if(A==1 && B==1){
           c[0]++; 
        }
        else if(A==1){
            c[1]++;
        }
        else if(B==1){
            c[2]++;
        }
       
    }

    if(c[0]==0){
        ans += min(c[1],c[2]);
    }
    else if(c[1]+c[2] > 0){
        ans += c[0] + min(c[1],c[2]);
    }
    else if(c[1]+c[2] == 0){
        ans += c[0] - 1;
    }

    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

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

const int MOD = 998244353;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    string s;
    cin >> s;
    int k;
    cin >> k;
    
    vector<int> otr(1, 0);
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '0') {
            otr.push_back(0);
        } else {
            ++otr.back();
        }
    }
    int n = otr.size();
    int m = s.size() - n + 1;
    k = min(k, m);
    
    vector<vector<vector<int>>> v(n + 1, vector<vector<int>>(k + 1, vector<int>(k + 1, 0)));
    v[n][0][0] = 1;
    for (int u = n - 1; u >= 0; --u) {
        for (int i = 0; i <= k; ++i) {
            for (int j = 0; j <= i; ++j) {
                for (int q = 0; q < otr[u]; ++q) {
                    if (i + otr[u] - q > k) {
                        continue;
                    }
                    v[u][i + otr[u] - q][j + otr[u] - q] += v[u + 1][i][j];
                    while (v[u][i + otr[u] - q][j + otr[u] - q] > MOD) {
                        v[u][i + otr[u] - q][j + otr[u] - q] -= MOD;
                    }
                }
                v[u][i][j] += v[u + 1][i][j];
                while (v[u][i][j] > MOD) {
                    v[u][i][j] -= MOD;
                }
                for (int q = 1; q <= j; ++q) {
                    v[u][i][j - q] += v[u + 1][i][j];
                    while (v[u][i][j - q] > MOD) {
                        v[u][i][j - q] -= MOD;
                    }
                }
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i <= k; ++i) {
        ans += v[0][i][0];
        if (ans > MOD) {
            ans -= MOD;
        }
    }
    cout << ans << "\n";
    
    
    return 0;
}


Measured memory_bytes: 17596
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


i64 n, m, d[101010];

//union-find
vector<int> par, depth;
void init(int n){
	par.resize(n+1), depth.resize(n+1);
	for(int i = 1; i <= n; i++){
		par[i] = i;
		depth[i] = 0;
	}
}
int find(int x){
	if(par[x] == x) return x;
	else return par[x] = find(par[x]);
}
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(depth[x] < depth[y]) par[x] = y;
	else{
		par[y] = x;
		if(depth[x] == depth[y]) depth[x]++;
	}
}
bool same(int x, int y){
	return find(x) == find(y);
}
////

int main(){
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		int a;
		cin >> a;
		d[a] = i;
	}
	init(n);
	for(int i = 0; i < m; i++){
		int a,b;
		cin >> a >> b;
		unite(a,b);
	}
	
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		if(same(i, d[i])) cnt++;
	}
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 1792
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e8;
const int MAX_V = 201;
int a[4];
int c[10];
bool use[10];
int t[200010];
bool cmp(const pii &left, const pii &right) {
	return left.second < right.second;
}
void IslandsWar() {
	int n,m;
	cin >> n >> m;
	pii ab[100010];
	for (size_t i = 0; i < m; i++)
	{
		cin >> ab[i].first >> ab[i].second;
	}
	sort(ab, ab + m, cmp);
	int to = 0;
	int res = 0;
	for (size_t i = 0; i < m; i++)
	{
		if (to <= ab[i].first) {
			res++;
			to = ab[i].second;
		}
	}
	cout << res << endl;
}

int main() {
	IslandsWar();
	return 0;
}



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

using namespace std;
int a,b;
int main(){
    cin>>a>>b;
 if(a>8||b>8){
     cout<<":("<<endl;
 }
 else if(abs(a-b)<=2){
    cout<<"Yay!"<<endl;
 }
 else{
     cout<<":("<<endl;
 }
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!
N,P=map(int,input().split())
l=[0]*int(-(-P**0.5//1)+1)

if N==1:
    print(P)
    exit()

for i in range(2,int(-(-P**0.5//1)+1))[::-1]:
    p=P
    count=0
    while p%i==0:
        p/=i
        count+=1
        if count==N:
            print(i)
            exit()
print(1)

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

const int N = 100005;

// Male: 0
// Female: 1
int n;
int save[N];

int get(int pos) {
	if (save[pos] != -1) return save[pos];

	cout << pos << endl;
	string reply; 
	cin >> reply;
	if (reply == "Vacant") exit(0);
	return save[pos] = (reply == "Female");
}

int main() {
	memset(save, -1, sizeof save);

	cin >> n;
	int l = 0, r = n - 1;
	while(true) {
		int L = get(l), R = get(r);
		int mid = ((l + r) >> 1);
		int M = get(mid);

		if ((L == M) != (l % 2 == mid % 2)) {
			r = mid;
		} else {
			l = mid;
		}
	}
}

Measured memory_bytes: 1236
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        System.out.println(solve(A, B, C) ? "YES" : "NO");

        sc.close();
    }

    static boolean solve(int A, int B, int C) {
        return Arrays.equals(IntStream.of(A, B, C).sorted().toArray(), new int[] { 5, 5, 7 });
    }
}

Measured memory_bytes: 26836
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>

using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;

#define rep(i,x) for(Int i = 0; i < (Int)(x); i++)
#define rrep(i,x) for(Int i = ((Int)(x) - 1); i >= 0; i--)
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
#define MX 100010


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

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

Int dx[4] = {1,0,-1,0};
Int dy[4] = {0,1,0,-1};
const Int INF = 1001002003004005006ll;
const Int mod = 1e9 + 7;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//







int func(int a, int b, int c){
        if(a%2 == 1 || b%2 == 1 || c%2 == 1) return 0;

        if(a==b && b==c) return -1;

        return func((b+c)/2, (c+a)/2, (a+b)/2) + 1;
}






int main(void){
        int a,b,c;
        cin >> a >> b >> c;
        int ans = func(a,b,c);
        cout << ans << endl;
        return 0;
}






























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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll X;
    cin >> X;
    ll L = 360  / gcd(X, 360);
    cout << L << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int n,m,x,y;
vector<int>v[21],o;
bool used[21];
void dfs(int x){
  used[x]=1;
  r(i,v[x].size())
    if(!used[v[x][i]])
      dfs(v[x][i]);
  o.push_back(x);
}
main(){
  cin>>n>>m;
  while(m--){
    cin>>x>>y;
    x--;y--;
    v[x].push_back(y);
  }
  r(i,n)if(!used[i])dfs(i);
  r(i,n)cout<<o[n-i-1]+1<<endl;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    string s;
    cin>>s;
    int len=s.length();
    vector<int> v(len+1);
    int flag=0,cntR=0,cntL=0,pos=0;
    for(int i=0;i<len;i++){
        if(flag==0 && s[i]=='R'){
            cntR++;
        }else if(flag==0 && s[i]=='L'){
            pos=i;
            v[i-1]+=(cntR/2);
            v[i]+=(cntR/2);
            if(cntR%2==1) v[i-1]++;
            cntR=0;
            cntL++;
            flag=1;
            if(i+1==len){
                v[i]++;
            }
        }else if(flag==1 && s[i]=='L'){
            cntL++;
            if(i+1==len){
                v[pos]+=(cntL/2);
                v[pos-1]+=(cntL/2);
                if(cntL%2==1) v[pos]++;
            }
        }else if(flag==1 && s[i]=='R'){
            v[pos]+=(cntL/2);
            v[pos-1]+=(cntL/2);
            if(cntL%2==1) v[pos]++;
            cntL=0;
            cntR++;
            flag=0;
        }
    }
    for(int i=0;i<len;i++){
        cout<<v[i]<<' ';
        if(i+1==len) cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
// https://atcoder.jp/contests/abc171/tasks/abc171_a

use proconio::input;

fn main() {
    let lowers = b'a'..=b'z';
    input! {
      a: String
    }
    for c in a.as_str().chars() {
        println!(
            "{}",
            if lowers.contains(&(c as u8)) {
                "a"
            } else {
                "A"
            }
        );
    }
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}

int main() {
  ll x; cin >> x;
  ll ans = x / 11 * 2;
  if(x % 11 < 7 && x % 11 > 0) {
    ans += 1;
  } else if(x % 11 < 11 && x % 11 != 0) {
    ans += 2;
  }
  cout << ans << endl;
}

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

int main()
{
  string S;
  cin >> S;
  
  int ans = 700;
  for (int i = 0; i < S.size(); i++)
  {
    if (S.at(i) == 'o') ans += 100;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256