akhauriyash/Code-Regression huggingface dataset:
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S;
	int cnt[26] = { 0 };

	cin >> S;
	rep(i, 0, SZ(S))
	{
		cnt[S[i] - 'a']++;
	}

	rep(i, 0, 26)
	{
		if (cnt[i] == 0)
		{
			cout << (char)('a' + i) << endl;
			return 0;
		}
	}

	cout << "None" << endl;

	return 0;
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main(){
    long long N, K;
    cin >> N >> K;

    long long sum;

    long long max = 0, min = 0;

    for(int j = 0; j < K; j++){
        min += j; 
    }

    for(int j = N; j >= N-K+1; j--){
        max += j;
    }

    sum += max - min + 1;

    for(int i = K; i < N+1; i++){
        min += i;
        max += N-i;

        sum += max - min + 1;

    }

    sum = sum % 1000000007;

    cout << sum << endl;


}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll mini = LONG_LONG_MAX;
    ll N;
    cin >> N;
    for(ll i = 0;i < N;i++) {
        ll temp;
        ll count = 0;
        cin >> temp;
        while(temp % 2 == 0) {
            temp /= 2;
            count++;
        }
        mini = min(mini, count);
    }
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) cin >> p.at(i);
	vector<int> q(n);
	for (int i = 0; i < n; i++) cin >> q.at(i);
	vector<int> x = p;
	sort(x.begin(), x.end());
	int a, b;
	int z = 0;
	do {
		if (p == x)a = z;
		if (q == x)b = z;
		z++;
	} while (next_permutation(x.begin(), x.end()));
	cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,i,j;
string ans="No";
main(){
  cin>>N;
  if(N>3){
    if(N%4==0||N%7==0||N%7%4==0){
      ans="Yes";
    }else{
      for(i=0;i<N/4;++i){
        for(j=0;j<N/7;++j){
          if(N==4*i+7*j){
            ans="Yes";
          }
        }
      }
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[100010];
vector<int> B;
int num[100010];

signed main(){
	int res=0;
	cin>>N;
	REP(i,N){
		cin>>A[i];
		B.push_back(A[i]);
	}
	sort(B.begin(),B.end());
	for(int i=0;i<N;i++){
		int pos=distance(B.begin(),lower_bound(B.begin(),B.end(),A[i]));
		A[i]=pos;
	}
	for(int i=1;i<N;i+=2){
		num[i]++,num[A[i]]++;
	}
	for(int i=1;i<N;i+=2){
		if(num[i]==2){
			res++;
		}
	}
	cout<<N/2-res<<endl;
	return 0;
}


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

int main()
{
    bool cards[4][14];
    int n, rank;
    char suit;

    for(int s = 0; s < 4; s++){
        for(int r = 1; r <= 13; r++){
            cards[s][r] = 0;
        }
    }

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> suit >> rank;
        if(suit == 'S') cards[0][rank] = 1;
        if(suit == 'H') cards[1][rank] = 1;
        if(suit == 'C') cards[2][rank] = 1;
        if(suit == 'D') cards[3][rank] = 1;
    }

    for(int s = 0; s < 4; s++){
        for(int r = 1; r <= 13; r++){
            if(cards[s][r]) continue;     /* In case of cards[s][r] == 1 */
            if(s == 0) suit = 'S';
            if(s == 1) suit = 'H';
            if(s == 2) suit = 'C';
            if(s == 3) suit = 'D';
            cout << suit << " " << r << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3060
/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;


vi dp(N);

void solve()
{
    int n;
    scn(n);

    rep(i, 0, N)
        dp[i] = (int) 2e9 + 2;

    dp[0] = 0;

    for(int i=1; i<=n; i++) {
        dp[i] = min(dp[i], 1 + dp[i-1]);

        for(int j=6; j<=i; j*=6) 
            dp[i] = min(dp[i], 1 + dp[i-j]);
        for(int j=9; j<=i; j*=9) 
            dp[i] = min(dp[i], 1 + dp[i-j]);

    }

    prin(dp[n]);
}

int main()
{
    int t = 1;
    // scn(t);
    
    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3848
#include<iostream>
#include<string>
#include<algorithm> 
using namespace std;
int main(){
  int n,tnow=0,tot,xnow=0,ynow=0,tox,toy;
  bool k=1;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>tot>>tox>>toy;
    for(int j=tnow;j<tot;j++){
      if(xnow<tox){
        xnow++;
      }
      else
        if(ynow<toy){
          ynow++;
        }
        else
          if(xnow>tox){
              xnow--;
          }
          else            
            if(ynow>toy){
              ynow--;
            }
            else
              if(xnow<=tox){
                xnow++;
              }
    }
    tnow=tot;
    if(tox==xnow && toy==ynow)
      k=k;
    else
      k=0;  
  }
  if(k)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1e9;

int main(){		
	int n;scanf("%d",&n);
	for(int i=1;i<=9;i++)
		for(int j=1;j<=9;j++)
			if(i*j==n)return puts("Yes"),0;
	puts("No");

	return 0;
}


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

int main(){
	ios::sync_with_stdio(false);

	int N,X; cin>>N>>X;
	vector<int> m(N);
	
	int sum=0,ming=1000;
	rep(i,N){
		int x; cin>>x;
		sum += x;
		ming = min(ming, x);
	}

	int ans = N + (X-sum)/ming;
	cout << ans << endl;

}


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

int main(){
	int k;
	cin >> k;
	int a, b;
	cin >> a >> b;
	
	if (a/k < b/k) {
		cout << "OK" << endl;
	} else if (a%k==0 || b%k == 0) {
		cout << "OK" << endl;
	} else cout << "NG" << endl;
}


Measured memory_bytes: 3624
// [AT3723 Round Up the Mean] https://www.luogu.org/problem/AT3723
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

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

    cout << ceil((a+b)/2.0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<stack>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
#define in 1000000007
int main()
{
    int n,m,p;
    cin>>n>>m>>p;
    set<int >s;
    s.insert(0);
    for(int i=1;i<=n;i++)
    {
        s.insert(i*m);
        for(int j=1;j<=m;j++)
        {
            int t=i*m+j*(n-2*i);
            s.insert(t);
        }
    }
    for(int j=1;j<=m;j++)
    {
        s.insert(j*n);
        for(int i=1;i<=n;i++)
        {
            int t=j*n+i*(m-2*j);
            s.insert(t);
        }
    }
    if(s.count(p)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 13056
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



// AABBの繰り返しでできた閉路が存在すればYES そうでなければNO
// 行き先の文字が1種類しかない頂点を全て消して、最後に頂点が残ればYES 全部消えたらNO
int n, m, x, y, a[200200], b[200200], v;
string s;
set<int> e[200200], q;

signed main() {
	cin >> n >> m >> s;
	v = n;
	rep(i,m) {
		cin >> x >> y;
		x--, y--;
		e[x].insert(y), e[y].insert(x);
	}
	rep(i,n) {
		each(j,e[i]) (s[j]=='A' ? a : b)[i]++;
		if (a[i]==0 || b[i]==0) q.insert(i);
	}
	while (!q.empty()) {
		int u = *q.begin(); q.erase(q.begin());
		v--;
		each(i,e[u]) if (i!=u) {
			e[i].erase(u);
			(s[u]=='A' ? a : b)[i]--;
			if (a[i]==0 || b[i]==0) q.insert(i);
		}
	}
	cout << (v ? "Yes" : "No") << endl;
}

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

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007

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

using namespace std;
/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

int main() {
    int x,a;
    cin >> x >> a;
    if(x < a)cout << 0 << endl;
    else cout << 10 << endl;

}



Measured memory_bytes: 256
#include<stdio.h>

int max(int a, int b){
    if(a > b){return a;}
    else{return b;}
}
int main(void){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int ans = a+b+c - max(a, max(b, c));
    printf("%d\n",ans);
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  if(n%10 == 2 || n%10 == 4 || n%10 == 5 || n%10 == 7 || n%10 == 9) cout << "hon" << endl;
  else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8) cout << "pon" << endl;
  else if(n%10 == 3) cout << "bon" << endl;
}


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


int main () {
    char s[100];
    scanf("%s", s);
    int len = strlen(s);
    int ct=0;
    int no=0;
    int a=0;
    int yes=0;
    for (int i=0; i<len;i++) {
        //printf("%d ", i);
        if (ct==6) {
            no = 1;
            break;
        }

        if (ct==5 && s[i]=='A') ct++;
        else if (ct==5) {
            no = 1;
            break;
        }

        if (ct==4 && s[i]=='A' && a==0) {
            a++;
            continue;
        }
        else if (ct==4 && s[i]=='R') {
            yes=1;
            ct++;
            a=0;
        }
        else if (ct==4) {
            no = 1;
            break;
        }

        if (ct==3 && s[i]=='A' && a==0) {
            a++;
            continue;
        }
        else if (ct==3 && s[i]=='B') {
            ct++;
            a=0;
        }
        else if (ct==3) {
            no = 1;
            break;
        }

        if (ct==2 && s[i]=='H') {
            ct++;
            a=0;
        }
        else if (ct==2) {
            no = 1;
            break;
        }

        if (ct==1 && s[i]=='I') {
            ct++;
            a=0;
        }
        else if (ct==1) {
            no = 1;
            break;
        }

        if (ct==0 && s[i]=='A' && a==0) {
            a++;
            continue;
        }
        else if (ct==0 && s[i]=='K') {
            ct++;
            a=0;
        }
        else if (ct==0) {
            no=1;
            break;
        }

    }
    if (yes==1 && no==0) printf("YES\n");
    else printf("NO\n");
    return 0;
}

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

using lint = long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

constexpr lint INF = 1'010'000'000'000'000'017LL;
constexpr lint MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(lint i = (start); i < end; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }

lint mod(lint val, lint m){ lint res = val % m; if(res < 0) res += m; return res;}
lint modinv(lint a, lint m) { lint b = m, u = 1, v = 0; while (b) { lint t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u;}
lint modpow(lint a, lint n, lint mod) { lint res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
lint gcd(lint a, lint b){ if(a < b) swap(a, b); if(b == 0) return a; return gcd(b, a%b);}
lint lcm(lint a, lint b){ return a * b / gcd(a, b);}


//---------------------------------------------------------------

void Main()
{
    int K, X;
    cin >> K >> X;
    Yes(500*K >= X);
    // cout << ans << endl;
}

//---------------------------------------------------------------
int main()
{
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<string>
using namespace std;
int main(){
    string str;
    getline(cin,str);
    int i;
    for(i=0;i<str.size();i++){
        if(str[i]>='a' && str[i]<='z')str[i]+='A'-'a';
        else if(str[i]>='A' && str[i]<='Z')str[i]+='a'-'A';
    }
    cout << str <<endl;
    return 0;
    
    
}


Measured memory_bytes: 3180
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }

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

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


#line 2 "tmp.cpp"

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

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

  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  REP(i, h) { cin >> grid[i]; }

  vector<vi> ans(h, vi(w, h + w + 1));
  queue<pair<int, int>> q;
  REP(i, h) {
    REP(j, w) {
      if (grid[i][j] == '#') {
        ans[i][j] = 0;
        q.push({i, j});
      }
    }
  }
  while (!q.empty()) {
    auto p = q.front();
    int ci = p.first, cj = p.second;
    q.pop();
    REP(k, 4) {
      int ni = ci + dx[k], nj = cj + dy[k];
      if (0 <= ni && ni < h && 0 <= nj && nj < w && ans[ni][nj] > ans[ci][cj] + 1) {
        chmin(ans[ni][nj], ans[ci][cj] + 1);
        q.push({ni, nj});
      }
    }
  }

  int ret = 0;
  REP(i, h) {
    REP(j, w) { chmax(ret, ans[i][j]); }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 13456
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    import collections
    counter = collections.Counter(A)
    total = 0
    for k, v in counter.items():
        total += v*(v-1)//2
    
    for a in A:
        cnt = counter[a]
        cntm1 = cnt - 1
        print(total - cnt*(cnt-1)//2 + cntm1*(cntm1-1)//2)


if '__main__' == __name__:
    resolve()

Measured memory_bytes: 101016
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vpint a(n);
	rep(i, n) {
		cin >> a[i].first;
		a[i].second = i;
	}
	vint ans(n);
	sort(a.begin(), a.end());
	int tmp1 = a[n / 2 - 1].first, tmp2 = a[n / 2].first;
	rep(i, n) {
		if (a[i].first <= tmp1) {
			ans[a[i].second] = tmp2;
		}
		else {
			ans[a[i].second] = tmp1;
		}
	}
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 4480
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db long double
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
const int mxn=1e5+7;
int n,k;
int a[mxn],b[mxn],c[mxn],dp[mxn][3];
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    for (int i=1;i<=n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][2],dp[i-1][0])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    cout<<max({dp[n][0],dp[n][1],dp[n][2]});
    return 0;
}

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

#define int long long int
#define MOD 1000000007
#define N 100001
#define pii pair<int,int>
#define MAX 1000000000000000000
#define _mp make_pair
#define pb push_back
#define _sort(v) sort(v.begin(),v.end())
#define _rsort(v) sort(v.rbegin(),v.rend())
using namespace std;

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

int32_t main(){

vector<int> v(5);
int n=5;
for(int i=0;i<n;i++){
    cin>>v[i];
}
for(int i=0;i<n;i++){
    if(v[i]==0){
        cout<<i+1;
    }
}
    
    // end_timer = std::chrono::high_resolution_clock::now();
    // ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_timer - start_timer).count();

return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <assert.h>
#include <vector>

void dfs(int32_t node, std::vector<std::vector<int32_t>>& graph,
        std::vector<bool>& visiting, int32_t& numVisit, int32_t& res) {
  if (visiting[node]) { return;}
  visiting[node] = true;
  numVisit++;
  if (numVisit == (int32_t)graph.size()) {
    res++;
  } else {
    for (auto next : graph[node]) {
      dfs(next, graph, visiting, numVisit, res);
    }
  }
  visiting[node] = false;
  numVisit--;
  return;
}

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

  int32_t N, M;
  std::cin >> N >> M;
  std::vector<std::vector<int32_t>> graph(N);
  for (int32_t i = 0; i < M; i++) {
    int32_t a,b;
    std::cin >> a >> b;
    graph[a-1].emplace_back(b-1);
    graph[b-1].emplace_back(a-1);
  }

  std::vector<bool> visiting(N,false);
  int32_t numVisit = 0;
  int32_t res = 0;
  dfs(0, graph, visiting, numVisit, res);
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int main(){
    string S;
    string ans = "NO";

    cin >> S;

    for(int i = 0;i < S.length();i++){
        string s = "";
        for (int j = 0;j < S.length();j++){
            if(i <= j && j < i + (S.length() - 7))continue;
            s += S[j];
        }
        if(s == "keyence")ans = "YES";
    }
    cout << ans << endl;
    return 0;
}

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

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N, K, Q;
    cin >> N >> K >> Q;

    vector<ll> S(N, 0);

    REP(i, Q) {
        int a; cin >> a;
        a--;
        S[a]++;
    }

    REP(i, N) {
        if (K - Q + S[i] > 0) print("Yes");
        else print("No");
    }
    
}


Measured memory_bytes: 3872
//  Created by conan1024hao in 2020.
//  Copyright © 2020 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e17
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------
double dp[3000][3000];
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ! llか? 统一类型 memset()! ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
	int n;cin>>n;
	vector<double>p(n);
	for(int i=0;i<n;i++)cin>>p[i];
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=n;j++){
			dp[i+1][j]=dp[i][j]*(1-p[i]);
			if(j)dp[i+1][j]+=dp[i][j-1]*p[i];
		}
	}
	double ans=0;
	for(int j=n/2+1;j<=n;j++)
		ans+=dp[n][j];
	printf("%.10lf\n",ans);
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------

Measured memory_bytes: 70528
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int N;
ll A[200010];

bool ok(ll m,vector<ll>& S){
    for(int i=1;i<=N;i++){//iと+1の間で切る
        int s = lower_bound(S.begin(),S.end(),S[i]+m)-S.begin();
        if(s>=i+N) continue;
        int r = lower_bound(S.begin(),S.end(),S[s]+m)-S.begin();
        if(r<i+N && S[i+N]-S[r]>=m) return true;
    }
    return false;
}

int main(){
    cin >> N;
    vector<ll> S(2*N+2,0);
    for(int i=1;i<=N;i++){
        cin >> A[i];
        A[i+N] = A[i];
    }
    for(int i=1;i<=2*N;i++) S[i] = S[i-1]+A[i];
    S[2*N+1] = (ll) 1e18;
    ll l = 0,r = 1e15;
    while(l+1<r){
        ll m = (l+r)/2;
        if(ok(m,S)) l = m;
        else r = m;
    }
    cout << l << endl;
}


Measured memory_bytes: 5968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<P> ans;
    rep (i, 1, n) {
        rep (j, i + 1, n + 1) {
            if (i + j + (n % 2 == 1) == n + 1) continue;
            // cout << i << " " << j << "\n";
            ans.emplace_back(i, j);
        }
    }
    cout << (int)ans.size() << "\n";
    for (P p : ans) cout << p.first << " " << p.second << "\n";
    return 0;
}

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

const int MOD = 1000000007;


int gcd(int a, int b) {
    if (b==0) return a;
   	else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}


int main(){
	ll N;
	cin>>N;
	vector<ll> L(2*N);
	rep(i,2*N) cin>>L[i];
	sort(L.begin(),L.end());
	
	ll ans=0;
	rep(i,N) ans+=L[2*i];
	
	cout<<ans<<endl;
	
	return 0;
}

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

using namespace std;

vector<int> G[32];
int pat[32];

char str[128];

int makeTree(int &p, int &num, int &intnum)
{
    if (isdigit(str[p])) return (str[p++] - '0');
    
    int v = num++;
    if (str[p] == '('){
        intnum++;
        p++; // (
        int u1 = makeTree(p, num, intnum);
        p++; // Space
        int u2 = makeTree(p, num, intnum);
        p++; // )
        G[v].push_back(u1);
        G[v].push_back(u2);
    }
    
    return (v);
}

int dfs(int v, int &pt)
{
    if (G[v].size() == 0) return (pat[v]);
    
    int p1 = dfs(G[v][0], pt);
    int op = pt % 3;
    pt /= 3;
    int p2 = dfs(G[v][1], pt);
    
    if (op == 0) return (p1 | p2);
    if (op == 1) return (p1 & p2);
    return (p1 ^ p2);
}

int main()
{
    
    while (fgets(str, sizeof(str), stdin) && str[0] != 'E'){
        for (int i = 0; i < 32; i++) G[i].clear();
        int intnum = 0;
        int v = 10;
        int p = 0;
        makeTree(p, v, intnum);
        
        int n;
        scanf("%d", &n); getchar();
        for (int i = 0; i < n; i++){
            pat[i + 1] = 0;
            for (int j = 0; j < 4; j++){
                int t;
                scanf("%d", &t); getchar();
                pat[i + 1] = pat[i + 1] * 2 + t;
            }
        }
        
        int pattern = 1;
        for (int i = 0; i < intnum; i++) pattern *= 3;
        
        int ret = 0;
        for (int i = 0; i < pattern; i++){
            int tmp = i;
            if (dfs(10, tmp) == 15) ret++;
        }
        
        printf("%d\n", ret);
    }
    
    return (0);
}

Measured memory_bytes: 1212
/* ex5_3
  sachiyan */

#include <stdio.h>

int main(void){
    int height, width; //変数の定義
    int i, j;
    scanf("%d %d", &height, &width);
    char matrix[height][width]; //入力の表を記憶する二次元配列
    int row[height], col[width]; //各行列に#が入っているか記憶する配列

    
    for(i=0; i<height; i++){ //入力の表を二次元配列に記憶
        for(j=0; j<width; j++){
            scanf(" %c", &matrix[i][j]);
        }
    }

    for(i=0; i<height; i++){ //二次元配列を全探索して、#がある行、列を記憶
        for(j=0; j<width; j++){
            if (matrix[i][j] == '#'){
                row[i] = 1;
                col[j] = 1;
            }
        }
    }
    for(i=0; i<height; i++){
        if(row[i]==1){ //i番目の行に#が含まれている
            for(j=0; j<width; j++){
                if(col[j]==1){ //j番目の列にも#が含まれている
                    printf("%c", matrix[i][j]);//出力
                }
            }
            printf("\n"); //一行出力したら改行
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

#define y0 qegipqp
#define y1 egknqepm

const double PI=acos(-1);
ll x0,x1,y0,y1;int n;double r;int l;
vector<pair<ll,ll> > w;
ll t[200005];

int main(){
	scanf("%lld%lld%lld%lld%d",&x0,&y0,&x1,&y1,&n);
	fore(i,0,n){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		if(x>=min(x0,x1)&&x<=max(x0,x1)&&y>=min(y0,y1)&&y<=max(y0,y1)){
			w.pb(mp(x,y));
		}
	}
	r=abs(x0-x1)+abs(y0-y1);
	if(!SZ(w)){printf("%.15lf\n",r*100);return 0;}
	if(x0==x1||y0==y1){printf("%.15lf\n",(r-.2+.1*PI)*100);return 0;}
	if(x0>x1)fore(i,0,SZ(w))w[i].fst*=-1;
	if(y0>y1)fore(i,0,SZ(w))w[i].snd*=-1;
	sort(w.begin(),w.end());
	t[0]=-(1LL<<60);
	fore(i,1,200005)t[i]=(1LL<<60);
	fore(i,0,SZ(w)){
		ll x=w[i].snd;
		int k=lower_bound(t,t+200005,x)-t;
		l=max(l,k);
		t[k]=min(t[k],x);
	}
	ll d=min(abs(x0-x1),abs(y0-y1));
	if(l==d+1){
		r-=.2*d;r+=.1*PI/2*d;
		r-=.2;r+=.1*PI;
	}
	else {
		r-=.2*l;r+=.1*PI/2*l;
	}
	printf("%.15lf\n",r*100);
	return 0;
}

Measured memory_bytes: 6512
#include "vector"
#include "set"
#include "map"
#include "unordered_set"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define INF2 4611686018427387904
//#define MOD 1000000007
#define MOD 998244353
#define MAX_SIZE 1000000000

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { bool first = true; for (const auto& j: v) { if (!first) { os << " "; } first = false; os <<j; } os << "\n"; return os; }
template<typename T>
istream& operator>>(istream& is, vector<T>& v) { for (auto& elem : v) { is >> elem; } return is; }

vector<ll> f;
void set_f(int n) { f.resize(n+1); f[0] = 1; for (int i=1; i<= n; i++) { f[i] = (f[i-1] * i) % MOD;} }
ll nod(ll a, ll b) { if (b == 0) { return a; } else { return nod(b, a % b); } }
ll pw(ll x, ll n, ll m=MOD) { if (n == 0) { return 1;} if (n%2 == 0) { return pw((x*x) % m, n/2, m); } return (pw(x, n-1, m) * x) % m; }
ll dv(ll a, ll b) { return (a * pw(b, MOD - 2)) % MOD; }
ll c_n_k(int n, int k) { if (k > n) { return 0; } if (k < 0) { return 0; } return dv(dv(f[n], f[k]), f[n-k]); }

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

    map<int, int> m;
    for (int i=0; i<k; i++) {
        int d;
        cin >> d;
        for (int j=0; j<d; j++) {
            int x;
            cin >> x;
            m[x] = 1;
        }
    }

    cout << n - m.size();
}

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

    if (0) {
        int tests;
        cin >> tests;
        for (int t = 1; t <= tests; t++) {
            //cout << "Case #" << t << ": ";
            solve();
            //cout << "\n";
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a[1000][999],indeg[499500],ans=0,tmp=0,func[1000][1000];
vector<int>G[499500],v;
queue<int>q;
signed main(){
    cin>>n;
    for(int i=0;i<n-1;i++)
        for(int j=i+1;j<n;j++)
            func[i][j]=func[j][i]=tmp++;
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1;j++){
            cin>>a[i][j];
            a[i][j]--;
            if(j!=0){
                G[func[i][a[i][j-1]]].push_back(func[i][a[i][j]]);
                indeg[func[i][a[i][j]]]++;
            }
        }
    }
    for(int i=0;i<tmp;i++)
        if(indeg[i]==0)
            q.push(i);
    ans=0;
    while(!q.empty()){
        while(!q.empty()){
            v.push_back(q.front());
            q.pop();
        }
        while(!v.empty()){
            for(int i=0;i<G[v.back()].size();i++){
                indeg[G[v.back()][i]]--;
                if(indeg[G[v.back()][i]]==0)
                    q.push(G[v.back()][i]);
            }
            v.pop_back();
        }
        ans++;
    }
    for(int i=0;i<tmp;i++)
        if(indeg[i]!=0)
            ans=-1;
    cout<<ans<<endl;
}


Measured memory_bytes: 47104
#include <set>
#include <queue>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int n,a,b,c,d;
char s[200010];
int main() {
	cin>>n>>a>>b>>c>>d;
	cin>>(s+1);
	int ok1 = 1;
	for(int i=a;i<=c-1;i++){
		if(s[i] == s[i+1] && s[i]!='.'){
			ok1 = 0;
		}
	}
	for(int i=b;i<=d-1;i++){
		if(s[i] == s[i+1] && s[i]!='.'){
			ok1 = 0;
		}
	}
	if(c>d){
		int cok = 0;
		for(int i = d-1;i>=b-1;i--){
			if(s[i] == s[i+1] && s[i] == s[i+2] && s[i]=='.'){
				cok = 1;
			}
		}
		if(!cok)ok1 = 0;
	}
	if(ok1){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

const int N = 200005;
vector<int>g[N];
LL value[N],answer[N];
int n,q;

void dfs(int node,int pre,LL s)
{
    s = s + value[node];
    answer[node] = s;
    for(int i : g[node]){
        if(i == pre)continue;
        dfs(i,node,s);
    }
}
int main()
{
    cin >> n >> q;
    for(int i = 1;i < n;i++){
        int a,b;
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    while(q--){
        int p , x;
        cin >> p >> x;
        value[p] += x;
    }
    dfs(1,1,0);
    for(int i = 1;i <= n;i++){
        if(i > 1)cout << " ";
        cout << answer[i];
    }
    cout << "\n";
}



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

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

int main() {
    int K;
    cin >> K;
    
    long long ans = 0;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                ans += gcd(gcd(i, j), k);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define MOD 1000000007
#define DEBUG 0
#define REP(i,n) for(int i=0;i<n;i++)

int main(){

	lli n,h;
	cin>>n>>h;

	vector<lli> a,b;
	a.resize(n);
	b.resize(n);
	REP(i,n)cin>>a[i]>>b[i];

	lli maxA = 0;
	sort(b.begin(),b.end(),greater<lli>());
	REP(i,n)maxA = max(maxA,a[i]);

	lli ans=0;

	REP(i,n){
		if(h<=0)break;
		if(b[i]>=maxA){
			h -= b[i];
			ans++;
		}
		else break;
	}

	if(h>0){
		ans += h/maxA + (h%maxA != 0);
	}

	cout<<ans<<endl;

	return 0;

}
 

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

long long sum(int size,int ary[]);
int min(int size,int ary[]);
int max(int size,int ary[]);
int main(){
	int size=0;
	cin >>size;
	int nums[size];
	for(int i=0;i<size;i++){
		cin >> nums[i];
	}
	
	int a=0,b=0;
	long long c=0;
	a=min(size,nums);
	b=max(size,nums);
	c=sum(size,nums);
	cout <<a<<" "<<b<<" "<<c<<endl;

	return 0;	
}

long long sum(int size,int ary[]){
	long long ret=0;
	for(int i=0;i<size;i++){
		ret +=ary[i];
	}
	return ret;
}

int min(int size,int ary[]){
	int ret=ary[0];
	for(int i=1;i<size;i++){
		if(ary[i]<ret) ret = ary[i];
	}
	return ret;
}

int max(int size,int ary[]){
	int ret=ary[0];
	for(int i=1;i<size;i++){
		if(ary[i]>ret) ret = ary[i];
	}
	return ret;
}

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

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

int main(){
  int n;
  cin>>n;
  vector<int> num(100010);
  int m = 0;
  rep(i,n){
    int tmp;
    cin>>tmp;
    m = max(tmp,m);
    num.at(tmp)++;
    num.at(tmp+1)++;
    if(tmp!=0)num.at(tmp-1)++;
  }
  int ans = 0;
  rep(i,m+2){
    ans=max(ans,num.at(i));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	string s, t;
	cin >>n>> s >> t;
	int l = s.length();
	for (int i = 0; i < l; i++)
		cout<< s[i]<<t[i] ;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000007;
const int mod=1000000007;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}
ll modpower(ll a,ll b){  //aのb乗
  ll ans=1;
  while(b>0){
    a%=mod;
    if((b&1)==1){
      ans=ans*a%mod;
    }
    b>>=1;
    a*=a;
  }
  return ans;
}
ll modfacts(ll a){      //aの階乗
  ll ans=1;
  for(ll i=2;i<=a;i++)ans=ans*i%mod;
  return ans;
}
ll inv(ll a){           //aの逆元
  return modpower(a,mod-2);
}
ll modcom(ll a,ll b){   //aCb
  if(b>a)return 0;
  if(a<0||b<0)return 0;
  if(b*2>a)b=a-b;
  ll ans=inv(modfacts(b));
  rep(i,b)ans=ans*(a-i)%mod;
  return ans;
}
int main(){
  int n,k;cin>>n>>k;
  rep(i,k)cout<<modcom(n-k+1,i+1)*modcom(k-1,i)%mod<<endl;
}


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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> cnt(n + 1, 0);
  for (int i = 0, a; i < n; i++) {
    cin >> a;
    cnt[a]++;
  }
  sort(cnt.begin(), cnt.end(), greater<int>());
  int ans = 0;
  for (int i = k; i <= n; i++) {
    ans += cnt[i];
  }
  debug(cnt);
  cout << ans << '\n';
  return 0;
}

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

struct Data {
  ll A, B;
  Data(ll A, ll B) : A(A), B(B){}
  bool operator< (const Data& d) const {
    return B < d.B;
  } 
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  ll A[N], B[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  vector<Data> v;
  for (int i = 0; i < N; i++) {
    v.push_back(Data(A[i], B[i]));
  }
  sort(v.begin(), v.end());
  ll t = 0;
  for (int i = 0; i < N; i++) {
    if (t + v[i].A <= v[i].B) {
      t += v[i].A;
    } else {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 9712
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    ll n;
    cin>>n;
    if(n==2){
        cout<<1<<endl;
        return 0;
    }
    ll ans=2;
    for(ll i=2;i*i<=n;++i){
        if(n%i==0){
            ll k=i;
            ll t=n;
            while(t%k==0){
                t/=k;
            }
            if((t-1)%k==0)++ans;
            if(i*i==n)continue;
            k=n/i;
            t=n;
            while(t%k==0){
                t/=k;
            }
            if((t-1)%k==0)++ans;
        }
    }
    --n;
    for(ll i=2;i*i<=n;++i){
        if(n%i==0){
            ans+=2;
            if(i*i==n)--ans;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256