akhauriyash/Code-Regression huggingface dataset:
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            string s;
            cin>>s;
            int flag=1;
            if(s.length()!=6)
            {
                flag=0;
            }
            else
            {
                if(s[3]!=s[2] || s[5]!=s[4])
                    flag=0;
            }
            if(flag)
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
        }
        return 0;
    }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define F first
#define S second
#define mod 998244353
using namespace std;

int main(){
    int n;cin >>n;
    int arr[n+1];
    ll vis[n+1]={0};
    for(int i=0;i<n;i++){
        cin >> arr[i];
        vis[arr[i]]+=1;
    }
    ll sum=0;
    for(int i=1;i<=n;i++){
        if(vis[i]>1){
        sum+=(vis[i]*(vis[i]-1))/2;
        }
    }
    for(int i=0;i<n;i++){
        ll ans=sum;
        if(vis[arr[i]]==2){
            ans-=1;
        }else if(vis[arr[i]]>2){
            int curr=vis[arr[i]];
            ans-=((curr)*(curr-1))/2;
            ans+=((curr-1)*(curr-2))/2;
        }
        cout <<ans<<endl;
    }

}


Measured memory_bytes: 4864
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

#include <functional>

template< typename T, typename X,typename Fmv, typename Fop, typename Fmf >
struct LazySegmentTree{
    int n;
    vector<T> data;
    vector<X> lazy;
    Fmv merge_values;
    Fop operate;
    Fmf merge_functions;
    T te;
    X xe;

    LazySegmentTree(){}
    LazySegmentTree(int sz,Fmv merge_values,Fop operate,Fmf merge_functions,T te,X xe):
                    merge_values(merge_values),operate(operate),
                    merge_functions(merge_functions),te(te),xe(xe){
        n=1;
        while(n<sz) n*=2;
        data.resize(2*n-1,te);
        lazy.resize(2*n-1,xe);
    }

    void build(vector<T> &A){
        for(int k=0;k<int(A.size());k++) data[k+n-1]=A[k];
        for(int k=n-2;k>=0;k--) data[k]=merge_values(data[2*k+1],data[2*k+2]);
    }

    void eval(int k,int l,int r){
        if(lazy[k]==xe) return;
        operate(data[k],lazy[k],r-l);
        if(r-l>1){
            merge_functions(lazy[2*k+1],lazy[k]);
            merge_functions(lazy[2*k+2],lazy[k]);
        }
        lazy[k]=xe;
    }

    void update(int a,int b,X val,int k=0,int l=0,int r=-1){
        if(r<0) r=n;
        eval(k,l,r);
        if(b<=l||r<=a) return;
        if(a<=l&&r<=b){
            merge_functions(lazy[k],val);
            eval(k,l,r);
        }else{
            update(a,b,val,2*k+1,l,(l+r)/2);
            update(a,b,val,2*k+2,(l+r)/2,r);
            data[k]=merge_values(data[2*k+1],data[2*k+2]);
        }
    }

    T query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0) r=n;
        eval(k,l,r);
        if(b<=l||r<=a) return te;
        if(a<=l&&r<=b) return data[k];

        T vl=query(a,b,2*k+1,l,(l+r)/2);
        T vr=query(a,b,2*k+2,(l+r)/2,r);
        return merge_values(vl,vr);
    }
};


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

  int N,Q;
  cin>>N>>Q;

  auto merge_values = [](ll a,ll b){
      return min(a,b);
  };
  auto operate = [](ll& a,ll x,int w){
      a=x;
  };
  auto merge_functions = [](ll& a,ll b){
      a=b;
  };
  ll te = (1ll<<31)-1;
  ll xe = -1;

  LazySegmentTree<ll,ll,decltype(merge_values),decltype(operate),decltype(merge_functions)> 
    seg(N,merge_values,operate,merge_functions,te,xe);

  vector<ll> init(N,te);
  seg.build(init);

  for(int q=0;q<Q;q++){
      int t;cin>>t;
      if(t==0){
          int a,b;
          ll x;
          cin>>a>>b>>x;
          seg.update(a,b+1,x);
      }else{
          int a,b;
          cin>>a>>b;
          cout<<seg.query(a,b+1)<<"\n";
      }
  }

  return 0;
}



Measured memory_bytes: 7840
a, b, c, x = [input() for _ in xrange(4)]
cnt = 0
for d in xrange(a + 1):
    for e in xrange(b + 1):
        for f in xrange(c + 1):
            if 500 * d + 100 * e + 50 * f == x:
                cnt += 1
print cnt


Measured memory_bytes: 2572
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch ColoringEdgesOnTree | diff ColoringEdgesOnTree.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address ColoringEdgesOnTree.cpp && ./a.out

/*
 
 11/24/2019
 
 4:11-
 
 */

const int MAX_N=1e6+1;
int N;

int K;
VI res;
vector<II> G[MAX_N];
void dfs(int u, int pre, int c) {
//  dump(u,pre,c);
  int k=1;
  FORR(p,G[u]) {
    int v=p.first,i=p.second;
    if(v==pre) continue;
    if(k==c) ++k;
    res[i]=k++;
    dfs(v,u,res[i]);
  }
}
void solve() {
  II maxd={SZ(G[0]),0};
  REP(i,N) SMAX(maxd,{SZ(G[i]),i});
  K=maxd.first;
//  dump(maxd.first,maxd.second);
  res=VI(N-1,-1);
  dfs(maxd.second,-1,0);
  cout<<K<<endl;
  REP(i,N-1) cout<<res[i]<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N-1) {
    int u,v; cin>>u>>v;
    --u,--v;
    G[u].emplace_back(v,i),G[v].emplace_back(u,i);
  }
  solve();
  
  return 0;
}


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

int n,a[100010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for(int i=1;i<=n;++i)
	{
		if(i+1>a[i+1])
		{
			int ji=i+1,pd=0;
			while(a[ji]==i)
			{
				pd^=1;
				++ji; 
			} 
			if(pd||(a[i]-i)%2==1)
			printf("First\n");
			else
			printf("Second\n");
			break;
		}
	}
	return 0;
}

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

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

  vector<int> E(300010,0), W(300010,0);

  for(int i=1; i<=N; i++){
    if(S[i-1] == 'E'){
      E[i] = E[i-1]+1; W[i] = W[i-1];
    } else {
      E[i] = E[i-1]; W[i] = W[i-1]+1;
    }
  }

  int ans = 400000;
  for(int i=1; i<=N; i++){
    ans = min(ans, W[i-1]+(E[N]-E[i]));
  }
  cout << ans << endl;

}

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

int main(void){
  int n;
  char s[10];
  int i;
  int a=0, b=0, c=0, d=0;
  scanf("%d",&n);
  for(i=1; i<n+1; i++){
    scanf("%s",s);
    if(strcmp(s, "AC")==0){
      a++;
    }else if(strcmp(s,"WA")==0){
      b++;
    }else if(strcmp(s,"TLE")==0){
      c++;
    }else if(strcmp(s,"RE")==0){
      d++;
    }
  }
  printf("AC x %d\n", a);
  printf("WA x %d\n", b);
  printf("TLE x %d\n", c);
  printf("RE x %d\n", d);
  
  return 0;
}


Measured memory_bytes: 1704
n, m = map(int, input().split())
ac = 0
wa = 0
 
memo = [0] * n
for i in range(m):
    p, s = input().split()
    p = int(p)
    p -= 1
    if memo[p] == -1:
        continue
    if s == "AC":
        ac += 1
        wa += memo[p]
        memo[p] = -1
    else:
        memo[p] += 1
 
print(ac, wa)

Measured memory_bytes: 3828
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC163_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var ret = new int[n];
            foreach (var i in a)
            {
                ret[i - 1]++;
            }

            foreach (var item in ret)
            {
                Console.WriteLine(item);
            }
        }
    }
}


Measured memory_bytes: 43844
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <queue>
#include <deque>
#include <math.h>
#include <cmath>
#include <stack>
#include <algorithm>
#include <list>
#include <array>
#include <valarray>
#include <unordered_map>
#include <cassert>
#include <random>
#include <cstring>
#include <sstream>

using namespace std;

typedef long long li;
typedef pair<int, int> pii;

#define X first
#define Y second
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

double eps = 1e-5;
const int INF = 2e9 + 7;
const li LINF = 9e18 + 7;

const int MAX = 1e9;
const int N = 1e5 + 7;

vector<pair<int, int>> g[N], t[N];
vector<pair<pii, int>> e;
int ans[N], col[N];
bool st[N];

void dfs(int u, int w) {
	col[u] = 1;
	ans[u] = w;

	for (auto it : g[u]) {
		int v, i;
		tie(v, i) = it;

		if (!col[v]) {
			dfs(v, ans[u] + e[i].Y);
			continue;
		}
	}

	col[u] = 2;

	for (auto it : t[u]) {
		int v, i;
		tie(v, i) = it;

		if (!col[v]) {
			dfs(v, ans[u] - e[i].Y);
		}
	}
}


int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	int n, m;
	scanf("%d %d", &n, &m);

	forn(i, m) {
		int x, y, w;
		scanf("%d %d %d", &x, &y, &w);
		x--, y--;

		g[x].emplace_back(y, i);
		t[y].emplace_back(x, i);

		e.push_back({ { x, y }, w });

		st[y] = true;
	}



	forn(i, n) {
		if (!col[i] && !st[i])
			dfs(i, 0);
	}

	int mx = -INF, mn = INF;
	forn(i, n) {
		mx = max(mx, ans[i]);
		mn = min(mn, ans[i]);
	}

	if (mx + (mn < 0 ? abs(mn) : 0) > MAX) {
		cout << "No" << endl;
		return 0;
	}

	forn(i, m) {
		int u, v;
		tie(u, v) = e[i].X;

		if (ans[v] - ans[u] != e[i].Y) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 17328
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
Inf = 1000
Dist, Fin = [[Inf for i in range(W)] for j in range(H)], [[False for i in range(W)] for j in range(H)]
Dist[0][0], Fin[0][0] = 0, True
Q, Search = [(0, 0)], [(-1, 0), (0, -1), (1, 0), (0, 1)]

while Q:
    next = Q.pop(0)
    for s in Search:
        if 0 <= next[0] + s[0] <= H-1 and 0 <= next[1] + s[1] <= W-1:
            if Fin[next[0] + s[0]][next[1]+s[1]] == False:
                Fin[next[0]+s[0]][next[1]+s[1]] = True
                if S[next[0]+s[0]][next[1]+s[1]] == ".":
                    Dist[next[0]+s[0]][next[1]+s[1]] = Dist[next[0]][next[1]] + 1
                    Q.append((next[0]+s[0], next[1]+s[1]))

if Dist[H-1][W-1] == Inf:
    print(-1)
else:
    now, dist = (H-1, W-1), Dist[H-1][W-1]
    S[H-1][W-1] = "#"
    while dist > 0:
        for s in Search:
            if 0 <= now[0] + s[0] <= H-1 and 0 <= now[1] + s[1] <= W-1:
                if Dist[now[0]+s[0]][now[1]+s[1]] == dist-1:
                    now, dist = (now[0]+s[0], now[1]+s[1]), dist-1
                    S[now[0]][now[1]] = "#"
                    break

    Score = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == ".":
                Score += 1
    print(Score)

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

int main(){
  int rgb[3];
  cin >> rgb[0] >> rgb[1] >> rgb[2];
  int ans=100*rgb[0]+10*rgb[1]+rgb[2];
  if(ans%4==0) cout <<"YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

long long cnt_divisible(long long A, long long d) {
	return A / d;
}

int main() {
	long long a, b, x;
	cin >> a >> b >> x;
	if (a != 0)
		cout << cnt_divisible(b, x) - cnt_divisible(a - 1, x) << endl;
	else
		cout << cnt_divisible(b, x) + 1;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define FORN(i, x, y) for (int i = x; i <= y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define scan1(X) scanf("%d", &X)
#define scan2(X, Y) scanf("%d%d", &X, &Y)
#define scan3(X, Y, Z) scanf("%d%d%d", &X, &Y, &Z)
#define scan4(X, Y, Z, W) scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define scanl1(X) scanf("%lld", &X);
#define scanl2(X, Y) scanf("%lld%lld", &X, &Y)
#define scanl3(X, Y, Z) scanf("%lld%lld%lld", &X, &Y, &Z)
#define scanl4(X, Y, Z, W) scanf("%lld%lld%lld%lld", &X, &Y, &Z, &W)
#define print1(X) printf("%d\n", X);
#define print2(X, Y) printf("%d %d\n", X, Y);
#define print3(X, Y, Z) printf("%d %d %d\n", X, Y, Z);
#define print4(X, Y, Z, W) printf("%d %d %d %d\n", X, Y, Z, W);
#define printl1(X) printf("%lld\n", X);
#define printl2(X, Y) printf("%lld %lld\n", X, Y);
#define printl3(X, Y, Z) printf("%lld %lld %lld\n", X, Y, Z);
#define printl4(X, Y, Z, W) printf("%lld %lld %lld %lld\n", X, Y, Z, W);
#define max3(X, Y, Z) max(X, max(Y, Z))
#define max4(X, Y, Z, W) max(max(X, Y), max(Z, W))
#define min3(X, Y, Z) min(X, min(Y, Z))
#define min4(X, Y, Z, W) min(min(X, Y), min(Z, W))
#define popcount(X) __builtin_popcount(X)
#define all(x) x.begin(), x.end()
#define size(X) (int)X.size()
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define lc(x) 2 * x
#define rc(x) 2 * x + 1
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pldld;
const long long l_inf = numeric_limits<long long>::max();
const long long l_ninf = numeric_limits<long long>::min();
const int inf = numeric_limits<int>::max();
const int ninf = numeric_limits<int>::min();
const double pi = 1.00 * acos(-1.00);
const double eps = 1e-8;
void cio(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll gcd(ll a, ll b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
int sq( int x ) {return x * x;}
////////////////////////////////////////////////////////////////////Header
int main () {
    cio();
    int x;
    cin>>x;
    cout<<(x^1)<<endl;
}

Measured memory_bytes: 3632
/********************************************************
  **░██████╗██╗░░░░░░█████╗░██╗░░░██╗██╗░█████╗░░██████╗░**
  **██╔════╝██║░░░░░██╔══██╗██║░░░██║██║██╔══██╗██╔════╝░**
  **╚█████╗░██║░░░░░███████║╚██╗░██╔╝██║██║░░╚═╝██║░░██╗░**
  **░╚═══██╗██║░░░░░██╔══██║░╚████╔╝░██║██║░░██╗██║░░╚██╗**
  **██████╔╝███████╗██║░░██║░░╚██╔╝░░██║╚█████╔╝╚██████╔╝**
  **╚═════╝░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░╚════╝░░╚═════╝░**
  *********************************************************/

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


#define ll                          long long
#define ld                          long double

#define forn(i,n)                   for(int i=0;i<n;++i)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend();
#define isSubstring(s1,s2)          s1.find(s2) != std::string::npos
	
#define pb                          push_back
#define pf                          push_front
#define mp                          make_pair
#define fr                          first
#define sc                          second

#define vpi                         vector<pair<int,int>>
#define vi                          vector<int>
#define sz(a)                       (int)a.size()

#define   endl                       "\n"
#define     nl                       cout<<"\n";
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define MN                           INT_MIN
#define MX                           INT_MAX

bool isPrime(ll n){if(n<2)return false;for(ll x = 2;x*x <=n;x++){if(n%x == 0)return false;}return true;}
bool isPerfectSquare(long double x){long double sr=sqrt(x);return((sr-floor(sr))==0);}
int gcd(int a, int b){if(a==0)return b;if(b==0) return a;if(a==b)return a;if(a>b)return gcd(a-b,b);return gcd(a,b-a);}

int32_t main()
{
	int r;
	cin >> r;
	cout << r * r << endl;
}
	

Measured memory_bytes: 3684
/*OJ:
  ProblemID:
  Date:
*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define mp make_pair
#define pb push_back
#define all(n) (n).begin,(n).end
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef vector<int> vi;
const int INF=1e9+7;
/*_____main part_____*/
int used[100005];
vi v[100005];
int n,m;
int a[100005];
int cnt;
int ans;
void dfs(int x)
{
	used[x]=cnt;
	for(int i=0;i<v[x].size() ;i++)
	{
		if(used[v[x][i]]==0)
		dfs(v[x][i]);
	} 
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		a[x]=i;
	}
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	for(int i=1;i<=n;i++)
	{
		if(used[i]==0)
		{
			cnt++;
			used[i]=cnt;
			dfs(i);
		}
	}
	//for(int i=1;i<=n;i++)cout<<used[i]<<' ';
	for(int i=1;i<=n;i++)
	{
		//cout<<used[i]<<' '<<used[a[i]]<<endl;
		if(used[i]==used[a[i]])
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 8576
N, K = map(int, input().split())
R = N - K

if R == 0: #赤いボールが無い時
    print (1)
    for _ in range(1, K):
        print (0)
    exit()

if K == 1: #青いボールが1つのとき
    print (R+1)
    exit()

for i in range(1, K+1): #K回答えを出力
    if i > R+1:
        print (0)
        continue
    if i == 1:
        position = R + 1
        boal = 1
    if i >= 2:
        position = ((position * (R + 1 - (i-1))) // i) #%(7 + 10 ** 9)
        boal = ((boal * (K - (i-1)))// (i-1)) #%(7 + 10 ** 9) 
    print ((position * boal)%(7 + 10 ** 9))

Measured memory_bytes: 3316
use proconio::{input, fastout, marker::Usize1};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: usize, k: usize,
        arr: [Usize1; n],
    }

    let mut map: HashMap<usize, usize> = HashMap::new();
    let mut i: usize   = 0;
    let mut cnt: usize = 0;
    for _ in 0..n {
        i = arr[i];
        cnt += 1;
        if map.contains_key(&i) { break; }
        else { map.insert(i, cnt); }
    }
    let first_i = *map.get(&i).unwrap();
    let circuit = cnt - first_i;
    let k_idx = {
        if k < first_i { k }
        else { (k-first_i) % circuit + first_i }
    };

    i = 0;
    for _ in 0..k_idx {
        i = arr[i];
    }
    println!("{}", i+1);
}


Measured memory_bytes: 11484
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	string s, ss = "";
	cin >> s;
	for (int i = 0; i < s.length(); i += 2) ss = ss + s[i];
	cout << ss << "\n";

	return 0;
}


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int main ()
{
    int a,b,c,d;    cin >> a >> b;
    c=min(a,b);
    d=max(a,b);
    
    for(int i=0;i<d;i++) cout << c;

    cout << endl;
}

     



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 110;
int n, m, match[N], vis[N];
pii mat[N][N], res[N][N], res2[N][N];
vector<int> vec[N][N];
bool dfs(int pos) {
  rep (i, 1, n) if (vec[pos][i].size() > 0) {
    if (vis[i] == 1) continue;
    vis[i] = 1;
    if (!match[i] || dfs(match[i])) {
      match[i] = pos;
      return true;
    }
  }
  return false;
}
void doit() {
  rep (i, 1, n) match[i] = 0;
  rep (i, 1, n) {
    memset(vis, 0, sizeof vis);
    dfs(i);
  }
}
int main() {
  read(n), read(m);
  rep (i, 1, n) {
    int x;
    rep (j, 1, m) {
      read(x);
      mat[i][j] = pii((x - 1) / m + 1, (x - 1) % m + 1);
      vec[i][mat[i][j].fir].push_back(mat[i][j].sec);
    }
  }
  rep (j, 1, m) {
    doit();
    rep (i, 1, n) {
      int p = match[i];
      res[p][j] = pii(i, vec[p][i].back());
      vec[p][i].pop_back();
      res2[i][j] = res[p][j];
    }
  }
  rep (i, 1, n) {
    rep (j, 1, m) {
      printf("%d ", (res[i][j].fir-1) * m + res[i][j].sec);
    }
    puts("");
  }
  rep (i, 1, n) {
    rep (j, 1, m) {
      printf("%d ", (res2[i][j].fir-1) * m + res2[i][j].sec);
    }
    puts("");
  }
  return 0;
}


Measured memory_bytes: 1152
#![allow(non_snake_case, dead_code)]
use std::collections::VecDeque;
use std::io::BufRead;

struct MyReader<R: BufRead> {
    __reader: R,
    queue: VecDeque<String>,
}
impl<R: BufRead> MyReader<R> {
    fn new(reader: R) -> MyReader<R> {
        MyReader {
            __reader: reader,
            queue: VecDeque::new(),
        }
    }
    fn read(&mut self) -> String {
        if self.queue.len() == 0 {
            self.__readFromStdin()
        };
        self.queue.pop_front().unwrap()
    }
    fn readN(&mut self) -> i32 {
        self.read().parse().ok().expect("failed paring")
    }
    fn readUN(&mut self) -> usize {
        self.read().parse().ok().expect("failed paring")
    }
    fn readT<T: std::str::FromStr>(&mut self) -> T {
        self.read().parse().ok().expect("failed parsing")
    }

    fn __readFromStdin(&mut self) {
        let mut s = String::new();
        self.__reader.read_line(&mut s).unwrap();
        for it in s.trim().split_whitespace() {
            self.queue.push_back(it.to_string());
        }
    }
}
//*****************************************
fn main() {
    let stdin = std::io::stdin();
    let input = stdin.lock();
    run(input);
    //println!("{}", run(input))
}

const DIV: usize = 1000_000_007;

fn run<R: BufRead>(reader: R) {
    let mut myReader = MyReader::new(reader);
    let N = myReader.readUN();

    let v10 = powerMod(10, N);
    let v9 = powerMod(9, N);
    let v8 = powerMod(8, N);

    let res = (v10 + v8 + (DIV - v9) * 2) % DIV;
    println!("{}", res);
}

fn powerMod(base: usize, n: usize) -> usize {
    let mut bflg = std::usize::MAX ^ (std::usize::MAX >> 1);
    let mut res = 1;
    while bflg > 0 {
        res = (res * res) % DIV;
        if (n & bflg) > 0 {
            res = (res * base) % DIV;
        }
        bflg >>= 1;
    }
    res
}


Measured memory_bytes: 2128
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int main(){
  typedef pair<int ,int> temp;
  temp sport[1000001];
  int n;
  while( true ){
    int second ,minute;
    cin >> n;
    if( n == 0 ){
      break;
    }

    for( int i=0 ; i<n ; i++ ){ // nチーム分入力
      cin >> sport[i].second; // チーム番号
      sport[i].first = 0;
      for( int j=0 ; j<4 ; j++ ){ // 4競技分の記録
	cin >> minute >> second; 
	if( minute > 0 ){ // 秒で統一
	  second += minute * 60;
	}
	sport[i].first += second;
      }
    }

    sort( sport ,sport+n );

    cout << sport[0].second << endl << sport[1].second << endl;
    cout << sport[n-2].second << endl;
  }
}

Measured memory_bytes: 8972
#include<bits/stdc++.h>
#define mod   1000000007
using namespace std;
const int N = 1e4 + 5;
const int M = 105;
vector<long long>num;
int dp[N][M][2];
int n, m;
string s;
int d;
long long help(long long idx, long long sum, long long tight)
{
    if (idx == num.size())
        return (sum%d==0);
    if (dp[idx][sum][tight] != -1)
        return dp[idx][sum][tight];
    long long res = 0;
    int biggest;
    if (tight)
     biggest= (num[idx]) ;
     else
        biggest=9;
    for (int i = 0; i <= biggest; i++)
    {
        int newtight = ((num[idx])== i) ? tight : 0;
        res =(res+help(idx + 1, (sum + i) % d, newtight))%mod;
    }
    return dp[idx][sum][tight] = res;
}
long long solve(string s)
{
    memset(dp, -1, sizeof dp);
    num.clear();
    for(int i=0;i<=s.size()-1;i++)
        num.push_back(s[i]-'0');
    return (help(0, 0, 1) -1 + mod) % mod;
}
int main()
{
    cin>>s;
    cin>>d;
    cout<<solve(s);
    return 0;
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

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()
{
  int N, Wt;
  int v[110], w[110];
  cin >> N >> Wt;

  rep(i, N)
  {
    cin >> v[i] >> w[i];
  }

  // dp[i][w]: i番目までの品物の中で大きさがwを超えないように選んだ時の価値の最大値
  int dp[110][10001] = {};

  rep(i, N)
  {
    rep(j, Wt + 1)
    {
      if (j >= w[i])
      {
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
      }
      else
      {
        dp[i + 1][j] = dp[i][j];
      }
    }
  }

  cout << dp[N][Wt] << endl;

  return 0;
}


Measured memory_bytes: 7416
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
//const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int N;
    cin>>N;
    N%=10;
    if(N==3){
        cout<<"bon"<<endl;
    }else if(N==0||N==1||N==6||N==8){
        cout<<"pon"<<endl;
    }else{
        cout<<"hon"<<endl;
    }
}


Measured memory_bytes: 3676
X, Y, R, G, N = map(int, input().split())
r = [int(x) for x in input().split()]
g = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
r = sorted(r)[R-X:]
g = sorted(g)[G-Y:]
n = sorted(n, reverse=True)

nr = 0; ng = 0; nn = 0
for i in range(N):
    if n[nn] <= min(r[nr], g[ng]):
        break
    if r[nr] < g[ng]:
        r[nr] = n[nn]
        nr += 1
        if nr == X:
            nr = X-1
    else:
        g[ng] = n[nn]
        ng += 1
        if ng == Y:
            ng = Y-1
    nn += 1

print(sum(r) + sum(g))

Measured memory_bytes: 23644
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <numeric>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define Icin(s) ll (s);cin>>(s);
#define Scin(s) ll (s);cin>>(s);
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; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    if(abs(n-m)>1){
        cout<<0<<endl;
        return 0;
    }
    ll res=1;
    rep3(i,1,n+1){
        res*=i;
        res%=MOD;
    }
    rep3(i,1,m+1){
        res*=i;
        res%=MOD;
    }
    if(n==m)res*=2;
    res%=MOD;
    cout<<res<<endl;
}

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

int pcnt(int x){
  return __builtin_popcount(x);
}

int f(int x){
  if(x==0) return 0;
  return f(x%pcnt(x))+1;
}

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> x(n);
  for(int i=0;i<n;++i) x[i]=s[i]-'0';
  int pc=0;
  for(int i=0;i<n;++i) pc+=x[i];
  vector<int> ans(n);
  for(int b=0;b<2;++b){
    int npc=pc;
    if(b==0) npc++;
    else npc--;

    if(npc<=0) continue;
    int r0=0;
    for(int i=0;i<n;++i){
      r0=(r0*2)%npc;
      r0+=x[i];
    }
    int k=1;
    for(int i=n-1;i>=0;--i){
      if(x[i]==b){
        int r=r0;
        if(b==0) r=(r+k)%npc;
        else r=(r-k+npc)%npc;
        ans[i]=f(r)+1;
      }
      k=(k*2)%npc;
    }
  }
  for(int i=0;i<n;++i){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 5244
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n = int(input())
  A = readInts()
  LIST = set()
  d = 0
  
  for i in A:
    c = i // 400
    if c < 8:
      LIST.add(c)
    else:
      d+=1
  print(max(len(LIST),1),len(LIST)+d)
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
h,w,k = map(int,input().split())
S = [input() for _ in range(h)]
ans = float('inf')
for bit in range(1<<(h-1)):
    segment = [0]*h
    seg = 0
    for i in range(h-1):
        if bit & (1<<i):
            seg += 1
        segment[i+1] = seg
    n = max(segment) + 1

    count = n-1
    k_cnt = [0]*n
    for j in range(w):
        tmp = [0]*n
        for i in range(h):
            k_cnt[segment[i]] += int(S[i][j])
            tmp[segment[i]] += int(S[i][j])
            if k_cnt[segment[i]] > k:
                count += 1
                for i in range(n):
                    k_cnt[i] = tmp[i]
    ans = min(ans,count)
print(ans)

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

#define ll long long
#define ld long double
#define ar array
#define pb push_back
#define FOR(i, a, b) for (int i=(a); i<(b); i++)

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

// void solve(){

// }
const int N=2e5 +10;
int n,m,cnt,mx=1;
vector<int> adj[N];
vector<bool> vis(N,false);
void dfs(int u){
    vis[u]=true;
    cnt++;
    for(auto v:adj[u]){
        if(!vis[v]){
            dfs(v);
        }
    }
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
    cin>>n>>m;
    FOR(i,0,m){
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    FOR(i,1,n+1){
        cnt=0;
        if(!vis[i]){
            dfs(i);
            mx=max(mx,cnt);
        }
    }
    cout<<mx;
    return 0;
}

Measured memory_bytes: 20696
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++)
        	arr[i] = sc.nextInt();
        Arrays.sort(arr);
        int lowerBound = arr[n/2-1] + 1;
        int upperBound = arr[n/2];
        int cnt = 0;
        while(lowerBound <= upperBound) {
        	cnt++;
        	lowerBound++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 52744
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
const int mod = 1e9 + 7;

ll mpow(ll x, ll n) {
  ll res = 1;
  while (n) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n /= 2;
  }
  return res;
}

ll inv(ll x) {
  return mpow(x, mod - 2);
}

vl fac(3e5, 1);
vl invfac(fac.size(), 1);

ll bin(int k, int n) {
  if (k < 0 || k > n) return 0;
  return fac[n] * invfac[n-k] % mod * invfac[k] % mod;
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  for (int i = 2; i < (int)fac.size(); ++i) {
    fac[i] = fac[i-1] * i % mod;
    invfac[i] = inv(fac[i]);
  }
  ll inv2 = inv(2);
  vl invpw2(fac.size(), 1);
  for (int i = 1; i < (int)invpw2.size(); ++i) {
    invpw2[i] = invpw2[i-1] * inv2 % mod;
  }
  int b, w;
  cin >> b >> w;
  ll allb = 0, allw = 0;
  for (int i = 0; i < b + w; ++i) {
    if (i >= w) {
      allb = (allb + bin(w - 1, i - 1) * invpw2[i]) % mod;
    }
    if (i >= b) {
      allw = (allw + bin(b - 1, i - 1) * invpw2[i]) % mod;
    }
//    cerr << i << ' ' << allb * 16 % mod << ' ' << allw * 16 % mod << endl;
    ll res = allb + (1 - allb - allw) * inv2;
    cout << (res % mod + mod) % mod << '\n';
  }
  return 0;
}


Measured memory_bytes: 9216
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

S = sys.stdin.readline().rstrip()
N = len(S)
# 23:30
# 2**9=512通りなので全探索で

S = list(S)
ans = 0
for ops in itertools.product(['+', ''], repeat=N - 1):
    f = ''
    for c, op in zip(S[:-1], ops):
        f += c + op
    f += S[-1]
    ans += eval(f)
print(ans)


Measured memory_bytes: 13768
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, k, s;
//ld ;
//string s;

int main() {
    cin >> n >> k >> s;
    ll a[n];
    for(ll i=0;i<n;i++){
        if(k==0){
            if(s == 1){
                cout << 2 << " ";
            }else{
                cout << s-1 << " ";
            }
        }else if(i<k){
            cout << s << " ";
        }else{
            if(s == 1){
                cout << 2 << " ";
            }else{
                cout << s-1 << " ";
            }
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.length();
    int hugs = 0;

    int l = n / 2;
    for (int i = 0; i < l; i++) {
        if (s[i] != s[n - i - 1]) {
            hugs++;
        }
    }
    
    
    cout << hugs;
    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
string get_str(string s) {
	s+=',';
	string ret="";
	for(int i=0; i<s.size(); i++) {
		if(s[i]==',') ret+="=%ld, ";
		else ret+=s[i];
	}
	return ret;
}
#define dump(...) printf(get_str(#__VA_ARGS__).c_str(),__VA_ARGS__);cout<<endl
 
#define endl '\n'
#define IOS()                     \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
 template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
//******************************************************************************
 
int N,MINF=1e17;
vint a;
vint g[5050];
 
 
vector<vector<int>>dfs(int now,int par){
	auto dp = make_v<int>(1,2);
	fill_v(dp,INF);
	dp[0][0] = a[now];
	if(a[now]>0)dp[0][1] = a[now];
	for(auto e:g[now]){
		if(e==par)continue;
		auto tmp = dfs(e,now);
		int n = dp.size();
		int m = tmp.size();
		auto new_dp = make_v<int>(n+m,2);
		fill_v(new_dp,INF);
		rep(i,0,n){
			rep(j,0,m){
				rep(k,0,2){
					rep(l,0,2){
						chmin(new_dp[i+j][k&l],dp[i][k]+tmp[j][l]);
					}
				}
				if(i+j+1>=n+m)continue;
				if(tmp[j][0]<0){
					chmin(new_dp[i+j+1][0],dp[i][0]);
					chmin(new_dp[i+j+1][1],dp[i][1]);
				}
				if(tmp[j][1]<INF/2){
					chmin(new_dp[i+j+1][0],dp[i][0]);
					chmin(new_dp[i+j+1][1],dp[i][1]);
				}
			}
		}
		dp = new_dp;
	}
	return dp;
}
 
signed main()
{
	//IOS();
	cin>>N;
	a.resize(N);
	for(int i = 0;i < N;i++){
		cin>>a[i];
	}
	rep(i,0,N-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	auto dp = dfs(0,-1);
	int ans = INF;
	rep(j,0,N){
		if(dp[j][1]<INF/2)chmin(ans,j);
		if(dp[j][0]<0)chmin(ans,j);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2176
import java.util.Scanner;

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

        while(sc.hasNext()) {
            String s = sc.nextLine();
            s = s.toLowerCase();
            for(int i=0; i<s.length(); i++) {
                if(s.charAt(i) >= 'a' && s.charAt(i) <= 'z') {
                    a[s.charAt(i) - 'a']++;
                }
            }
        }
        for(char i='a'; i<='z'; i++) {
            System.out.println(i + " : " + a[i-'a']);
        }
    }
}



Measured memory_bytes: 26104
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(), v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 1;
vector<int> g[N];
vector<int> vis(N);
int triangle(int a, int b, int c){
    return (a != b and b != c and a != c and a + b > c and a + c > b and b + c > a);
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        int a[n];
        for(int &it : a){
            cin >> it;
        }
        int ans = 0;
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                for(int k = j + 1; k < n; k++){
                    if(triangle(a[i], a[j], a[k])){
                        ans++;
                    }
                }
            }
        }
        cout << ans << '\n';
    }
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 200010
const int MOD = 1000000007;

int v[maxn];
int n;
int k;

bool check(int m) {
    int times = 0;
    for (int i = 0; i < n; i++) {
        times += v[i] / m + (v[i] % m > 0) - 1;
    }
    return times <= k;
}

void solve() {
    cin >> n >> k;

    for (int i = 0; i < n; ++i) cin >> v[i];
    int lo = 1, hi = 1e12, mid, ans = 0;
    while (lo <= hi) {
        mid = lo + hi >> 1;
        if (check(mid)) {
            ans = mid;
            hi = mid - 1;
        } else lo = mid + 1;
    }
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

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


using namespace std;

typedef long long ll;



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

   int n;
   cin>>n;
   for(int i=0;i<3;i++)
   {
       if(n%10==7)
       {
           cout<<"Yes"<<endl;
           return 0;
       }
       n/=10;
   }
   cout<<"No"<<endl;


}



Measured memory_bytes: 3632
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int check(int x) {
	if (x == 2)
		return 1;
	else if (x < 7 && x % 2 == 0 || x > 8 && x % 2)
		return 2;
	else
		return 3;
}

int main() {
	int x, y;
	cin >> x >> y;
	if (check(x) == check(y))
		Yes();
	else
		No();

	return 0;
}

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

int main(void)
{
        int a=0, b=0, c, i;
        char n[99999];

        scanf("%s", n);

        a = strlen(n);

        for(i=0;i<a;i++) {
                if(n[i]=='0') b++;
                else c++;
        }

        if(b>c) printf("%d\n", c*2);
        else printf("%d\n", b*2);

        return 0;
}

Measured memory_bytes: 256
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  N = input()
  ans = 0
  if len(N) == 6:
    ans += 10**5 - 10**4
    ans += 10**3 - 10**2
    ans += 10**1 - 10**0
  elif len(N) == 5:
    ans += int(N) - 10**4 + 1
    ans += 10**3 - 10**2
    ans += 10**1 - 10**0
  elif len(N) == 4:
    ans += 10**3 - 10**2
    ans += 10**1 - 10**0
  elif len(N) == 3:
    ans += int(N) - 10**2 + 1
    ans += 10**1 - 10**0
  elif len(N) == 2:
    ans += 10**1 - 10**0
  elif len(N) == 1:
    ans += int(N)
  print(ans)
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
    ans = (b - a) // 2
else:
    ta = a + ((b - a - 1) // 2)
    tb = n - b + 1 + ((b - a - 1) // 2)
    ans = min(ta, tb)
print(ans)


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

const int N = 123456;
int a[N];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n , q;
    cin >> n >> q;
    string s;
    cin >> s;
    for(int i = 1 ; i < n ; i++) {
        if(s[i] == 'C' && s[i - 1] == 'A') {
            a[i]++;
        }
        a[i + 1] = a[i];
    }
    while(q--) {
        int l , r;
        cin >> l >> r;
        r--;
        l--;
        cout << a[r] - a[l] << endl;
    }
    return 0;
}


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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int  main(){
  string a, b;
  cin >> a >> b;
  
  int num = stoi(a + b);
  bool flag = true;

  for(int i=1;  i<=1000; ++i){
    if(num == i*i){
      flag = true;
      break;
    }
    else flag = false;
  }

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

  return 0;
}

Measured memory_bytes: 256