akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

int main() {
    int n;
    cin >> n;

    int ans = 0;
    map<int,int>mp;
    rep(i,n) {
        int a;
        cin >> a;
        if(a>100000) {
            ans++;
            continue;
        }
        mp[a]++;
    }
    for(int i = 1;i<=100000;i++) {
        if(i<mp[i]) ans += mp[i] - i;
        else if(i > mp[i]) ans += mp[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 8320
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    vector<int> L(N), R(N);
    for (int i = 0; i < N; i++) {
        L[i] = i + A[i];
        R[i] = i - A[i];
    }

    sort(R.begin(), R.end());

    long long ans = 0;
    for (int i = 0; i < N; i++) {
        ans += upper_bound(R.begin(), R.end(), L[i]) - lower_bound(R.begin(), R.end(), L[i]);
    }

    cout << ans << endl;
}


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


Measured memory_bytes: 5604
from fractions import gcd

n, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(x)
a.sort()
b = [a[i + 1] - a[i] for i in range(n)]

ans = b[0]
for i in range(n - 1):
	ans = gcd(ans, b[i + 1])
print(ans)

Measured memory_bytes: 16284
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
        // setw(6) << setfill('0')
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

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

    if (S.size() <= K) {
        cout << S << endl;
    } else {
        rep(i, K) {
            cout << S[i];
        }
        cout << "..." << endl;
    }
}


Measured memory_bytes: 3644
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int x[100000],y[100000],wn[100000];
P a[200002];
int main(void)
{
	int n,w,h,i,j;

	int cnt,flg1,flg2;
	scanf("%d %d %d",&n,&w,&h);
	for(i=0;i<n;i++)	{
		scanf("%d %d %d",&x[i],&y[i],&wn[i]);
	}
	flg1=1;
	for(i=0;i<n;i++)	{
		a[i*2].first=x[i]-wn[i];
		a[i*2].second=0;
		a[i*2+1].first=x[i]+wn[i];
		a[i*2+1].second=1;
	}
	sort(a,a+n*2);
	
//	for(i=0;i<n*2;i++)	printf(" %d %d\n",a[i].first,a[i].second);

	if(a[0].first>0 || a[n*2-1].first<w)	{
		flg1=0;
	}
	else {
		cnt=0;
		for(i=0;i<n*2;i++)	{
			if(a[i].second==0)	cnt++;
			else cnt--;
			if(cnt<=0 && a[i].first<w)	{
				flg1=0;
				break;
			}
		}
	}
	flg2=1;
	for(i=0;i<n;i++)	{
		a[i*2].first=y[i]-wn[i];
		a[i*2].second=0;
		a[i*2+1].first=y[i]+wn[i];
		a[i*2+1].second=1;
	}
	sort(a,a+n*2);
	
//	for(i=0;i<n*2;i++)	printf(" %d %d\n",a[i].first,a[i].second);
	
	if(a[0].first>0 || a[n*2-1].first<h)	{
		flg2=0;
	}
	else {
		cnt=0;
		for(i=0;i<n*2;i++)	{
			if(a[i].second==0)	cnt++;
			else cnt--;
			if(cnt<=0 && a[i].first<h)	{
				flg2=0;
				break;
			}
		}
	}	
//	printf("flg1=%d flg2=%d\n",flg1,flg2);
	
	if(flg1==0 && flg2==0)	{
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 3744
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
	using namespace std;
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	array<string, 3> c;
	for(auto& e : c)cin >> e;
	string ans;
	for(int i = 0; i < 3; ++i)ans += c[i][i];
	cout << ans << endl;
}


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

int main()
{
    int x;
    cin >> x;
    if (x >= 30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3632
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const long long INF = 1e18;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#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(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	cout.setf(ios::fixed);
	cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

const double eps = 1e-10;

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		int a,b;
		cin >> a >> b;
		vector<LL> v(n);
		REP(i,n) cin >> v[i];
		vector<LL> dp(n+1,-INF);
		vector<LL> dpc(n+1,0);
		dp[0] = 0;
		dpc[0] = 1;
		REP(i,n){
			RREP(j,n){
				if(chmax(dp[j+1],dp[j]+v[i])){
					dpc[j+1] = dpc[j];
				}else if(dp[j+1] == dp[j]+v[i]){
					dpc[j+1] += dpc[j];
				}
			}
		}
		dpite(ALL(dpc));
		double ans = -1;
		LL com = -1;
		FOR(j,a,b+1){
			if(abs(ans-dp[j]/j) < 1e-10){
				com += dpc[j];
			}else if(chmax(ans,(double)dp[j]/j)){
				com = dpc[j];
			}
		}
		cout << ans << endl;
		cout << com << endl;
	}
	return 0;
}


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;
    vector< pair<int, int> > a(n);
    int temp;
    rep (i, n)
    {
        cin >> temp;
        a[i] = make_pair(temp, i);
    }
    sort(a.begin(), a.end());

    int ans = 0;
    for (int i = 0; i < n; i += 2)
    {
        if ((i & 1) != (a[i].second & 1)) ++ans;
    }

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



Measured memory_bytes: 1024
N = int(input())
S = list(input())

if len(S)%2 != 0:
    print('No')

else:
    S1 = S[:len(S)//2]
    S2 = S[len(S)//2:]
    
    if S1 == S2:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){

	char str[128] = {0};
	int cnt = 1;
	int data[128][128] = {{0}};
	int q = 1;
	bool f = false;
	bool god = false;
	int hoge = 0;

	memset(data,-1,sizeof(data));

	while(scanf("%s",str) != EOF){

		if(strlen(str) == 2 || strlen(str) == 1)hoge++;

		for(int i = 0;; ){
            if(str[i] == ','){
                i++;
                continue;
            }
            else if (str[i] != ',' && str[i+1] == ','){
                data[cnt][q] = str[i] - 48;
                q++;
                i++;
            }
            else if(str[i] != ',' && str[i+1] == 0){
                data[cnt][q] = str[i] - 48;
                break;
            }
            else if(str[i] != ',' && str[i+1] != ',' && str[i+2] == ','){
                data[cnt][q] = (str[i] - 48)*10 + (str[i+1] - 48);
                q++;
                i += 2;
            }
            else if(str[i] != ',' && str[i+1] != ',' && str[i+2] == 0){
                data[cnt][q] = (str[i] - 48)*10 + (str[i+1] - 48);
                break;
            }
		}
		q = 1;
		cnt++;

		if(hoge == 2)f = true;

		if(f == true){
			q = 2;
			int dp[128][128] = {{0}};
			int x = (cnt/2);

			memset(dp,-1,sizeof(dp));

			dp[1][1] = data[1][1];
			bool flg = false;

			for(int i = 1;i < cnt; i++){
				for(int j = 1;j <= q; j++){
					if(q <= x && flg == false){
						if(j == 1){
							dp[i+1][j] = dp[i][j] + data[i+1][j];
						}
						else if(j == q+1){
							dp[i+1][j] = dp[i][j-1] + data[i+1][j];
						}

						else{
							dp[i+1][j] = max(dp[i][j-1]+data[i+1][j],dp[i][j]+data[i+1][j]);
						}
					}
					else if(flg == true){
						dp[i+1][j] = max(dp[i][j+1]+data[i+1][j],dp[i][j]+data[i+1][j]);
					}
				}
				//printf("q:%d\n",q);
				if(flg == false && q < x)q++;
				else if(q == x){flg = true;q--;}
				else q--;
			}

			printf("%d\n",dp[cnt-1][1]);
			hoge = 0;
			memset(data,-1,sizeof(data));
			cnt = 1;
			q = 1;
		}
		f = false;
	}
	return 0;
}

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

int main(){
  int cx1,cy1,r1;
  int cx2,cy2,r2;
  cin>>cx1>>cy1>>r1;
  cin>>cx2>>cy2>>r2;

  int dx=cx1-cx2;
  int dy=cy1-cy2;
  
  auto sq=[](auto x){return x*x;};
  int sd=sq(dx)+sq(dy);
  
  if(sd>sq(r1+r2)){
    cout<<4<<endl;
    return 0;
  }

  if(sd==sq(r1+r2)){
    cout<<3<<endl;
    return 0;
  }
  
  if(sd<sq(r1-r2)){
    cout<<0<<endl;
    return 0;
  }
  
  if(sd==sq(r1-r2)){
    cout<<1<<endl;
    return 0;
  }
  
  cout<<2<<endl;
  return 0;
}



Measured memory_bytes: 3112
#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 100500;

int A[N];

typedef long long llong;

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    llong ans = 0;
    llong cur = 0;
    for (int i = 0; i <= n; i++) {
        if (A[i] == 0)
            ans += cur / 2, cur = 0;
        else
            cur += A[i];
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 512
N = int(input())

p = list(map(int, input().split()))

ans = 0

for i in range(1,N-1):
    if p[i - 1] < p[i] <= p[i + 1] or p[i - 1] >= p[i] > p[i + 1]:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#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 digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

#define INFL 2147483647

class RMQ {
	vector<ll> data;
	int size;
	int suffix;
	
public:
	RMQ() {}
	RMQ(int n) {
		suffix = -1;
		resize(n);
	}

	void resize(int n) {
		size = 1;
		while (size < n) {
			size <<= 1;
		}
		data.resize(size * 2 - 1, INFL);
	}
	
	ll& operator[](int i) {
		update();
		suffix = i;
		return data[i + size - 1];
	}

	void update() {
		if (suffix < 0)
			return;
		int k = suffix + size - 1;
		suffix = -1;
		while (k > 0) {
			k = (k - 1) / 2;
			data[k] = std::min(data[k * 2 + 1], data[k * 2 + 2]);
		}
	}

	ll min(int a, int b) {
		update();
		suffix = -1;
		return min(a, b, 0, 0, size);
	}

	ll min(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)
			return INFL;
		if (a <= l && r <= b)
			return data[k];
		int m = (l + r) / 2;
		return std::min(min(a, b, k * 2 + 1, l, m), min(a, b, k * 2 + 2, m, r));
	}
};

int main() {
	int n, q, c, x, y;
	cin >> n >> q;
	RMQ rmq(n);
	while (q--) {
		cin >> c >> x >> y;
		if (c) {
			cout << rmq.min(x, y + 1) << endl;
		}
		else {
			rmq[x] = y;
		}
	}

	return 0;
}

Measured memory_bytes: 4968
bilding = [[[0 for x in range(10)] for x in range(3)]for x in range(4)] 
n = int(input())
for k in range(n):
    b, f, r, v = map(int, raw_input().split())
    bilding[b-1][f-1][r-1] += v
 


for b in range(4):
    for f in range(3):
        print(" "+" ".join(map(str, bilding[b][f])))
    if b < 3:
        print("#"*20)

Measured memory_bytes: 6452
#include <bits/stdc++.h>
using namespace std;
int b,c,e;
int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int t;
    cin>>t;
    while(t--){
        cin>>b>>c>>e;
        auto p1=a.begin()+b;
        auto p2=a.begin()+c;
        cout<<count(p1,p2,e)<<endl;
    }
}



Measured memory_bytes: 3108
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
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 (a > b) { a = b; return true; } return false; }

signed main() {
	vector<int> v(200);
	rep(i, 0, 200)v[i] = (i + 1)*(i + 1);
	static int dp[5][40000] = {};
	dp[0][0] = 1;
	rep(i, 0, 199) {
		rep(j, 0, 4) {
			rep(k, 0, 40000) {
				if (k + v[i] >= 40000)break;
				dp[j + 1][k + v[i]] += dp[j][k];
			}
		}
	}
	for (int n; cin >> n&&n;) {
		int ans = 0;
		rep(j, 0, 5) {
			ans += dp[j][n];
		}
		cout << ans << endl;
	}


	return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;


const int mod = 1e9 + 7;

int add(int x) {  
  return x;
}

template<typename... T>
int add(int x, T... y) {  
  x += add(y...);
  if (x >= mod)
        x -= mod;
  return x;
}

template<typename... T>
int udd(int &x, T... y) { 
  return x = add(x, y...);
}

template<typename... T>
int sub(int x, T... y) { 
  return add(x, mod - add(y...));
}

int mul(int x) { 
  return x;
}

template<typename... T>
int mul(int x, T... y) { 
  return 1ll * x * mul(y...) % mod;
}

int bin(int x, int to) { 
  int y = 1;
  while (to) { 
        if (to & 1)
                  y = mul(x, y);
            x = mul(x, x);
                to >>= 1;
  }
  return y;
}

int inv(int x) { 
  assert(x != 0);
  return bin(x, mod - 2);
}

const int M = 200200;
 
int n;
vector<int> a;
int f[M];
int s[M];

int main() {
#ifdef LOCAL
  assert(freopen("b.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  cin >> n;
  int last = -1;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (x != last) {
        a.push_back(x);
        last = x;
        //cerr << x << "!\n";
    }
  }

  n = a.size();

  f[0] = 1;
  for (int i = 1; i <= n; ++i) {
    int cur = a[i - 1];
    f[i] = add(f[i - 1], s[cur]);
    udd(s[cur], f[i - 1]);
  }

  cout << f[n] << "\n";
}



Measured memory_bytes: 2676
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
ll mod = 1000000007;

int main(){
    int n;cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i,0,n){
        int x,y;cin>>x>>y;
        a[i]=x;b[i]=y;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int mi = 0;
    int ma = 0;
    int ans = 0;
    if (n%2==1){
        n--;
        mi = a[(n+1)/2];
        ma = b[(n+1)/2];
        ans = (ma-mi)+1;
    }else{
        n--;
        mi = (a[n/2]+a[n/2+1]);
        ma = (b[n/2]+b[n/2+1]);
        ans = ma-mi+1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4804
import sys
N, M = map(int, input().split())
adj = [[] for _ in range(N)]

for l, r, d in (map(int, input().split()) for _ in range(M)):
    adj[l-1].append((r-1, d))
    adj[r-1].append((l-1, -d))

visited = [0]*N
dist = [0]*N

for i in range(N):
    if visited[i]:  # 探索したことのある(つまり矛盾がなかった)場所なら次の場所へ
        continue
    visited[i] = 1  # 探索したフラグを立てる
    stack = [i]  # 探索候補へ追加
    vset = set()  # 今回(iのターンで)探索する場所のリスト(という名のセット)

    while stack:
        v = stack.pop()  # 今探索する場所をvとする
        vset.add(v)  # 探索する場所を追加する
        for dest, d in adj[v]:
            if visited[dest]:
                continue
            visited[dest] = 1  # 探索したフラグ立てる
            dist[dest] = dist[v] + d  # 今回の情報でとりあえず距離を設定
            stack.append(dest)

    for v in vset:  # 今回探索した場所それぞれについて
        for dest, d in adj[v]:
            if dist[v] + d != dist[dest]:  # ほかの情報と矛盾するか
                print('No')  # 矛盾してたらNoとなる
                exit()

print('Yes')


Measured memory_bytes: 72900
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string S;
    cin >> S;
    string a=S.substr(5,2);
    int num=stoi(a);
    if(num<=4) cout << "Heisei" << endl;
    else cout << "TBD" << endl;



}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int N;
    std::cin >> N;

    std::vector<int> d(N);
    for (int i = 0; i < N; i += 1) {
        std::cin >> d[i];
    }
    std::sort(d.begin(), d.end());

    int left = d[N / 2 - 1];
    int right = d[N / 2];

    std::cout << right - left << std::endl;

    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>

using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n,sum = 1;
  string s;
  cin >> n >> s;
  for (int i = 1; i < n; i++){
    if (s[i] != s[i-1]){
      sum += 1;
    }
  }
  cout << sum << '\n';
  return 0;
}

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

typedef long long ll;
const ll INF = 1e12;

int main() {
	ll i, j, k;
	ll n, ma, mb;
	cin >> n >> ma >> mb;
	vector<vector<ll>> dp(404, vector<ll>(404, INF));
	dp[0][0] = 0;
	for (k = 0; k < n; k++) {
		ll a, b, c;
		cin >> a >> b >> c;
		for (i = 403; i >= a; i--) {
			for (j = 403; j >= b; j--) {
				dp[i][j] = min(dp[i][j], dp[i - a][j - b] + c);
			}
		}
	}
	ll ans = INF;
	for (i = 1; i * max(ma, mb) < 404; i++) {
		ans = min(ans, dp[i * ma][i * mb]);
	}
	if (ans == INF) ans = -1;
	cout << ans << endl;

	return 0;
}

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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	
	int W, a, b; cin >> W >> a >> b;

	int ans = max(a,b) - min(a+W, b+W);
	
	if(ans < 0) cout << 0 << endl;
	else cout << ans  << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define F first
#define S second
#define PB push_back 
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut,pr> ppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
typedef vector<ppr> Vppr;
const int SIZE=1+6*1e+5;
const LL p=7+1e+9;
int N,Q;
VI child[SIZE];
VI nums;
LL sumBIT[SIZE],BIT[SIZE];
LL bs[SIZE],be[SIZE],ne[SIZE],talls[SIZE];
LL master[SIZE][20];
bool Eulered[SIZE];
void Euler(){
	
	stack<int> stacks;
	stacks.push(0);
	while(!stacks.empty()){
		int x=stacks.top();
		if(!Eulered[x]){
			bs[x]=nums.size();
			nums.PB(x);
			REP(i,child[x].size()){
				stacks.push(child[x][i]);
				talls[child[x][i]]=talls[x]+1;
			}
			Eulered[x]=true;
		}
		else{
			ne[x]=nums.size();
			stacks.pop();
		}
	}
}
void add(int x,LL p,LL bit[]){
	while(x<=SIZE){
		bit[x]+=p;
		x+=x&-x;
	}
}
LL sum(int x,LL bit[]){
	LL ans=0;
	while(x>0){
		ans+=bit[x];
		x-=x&-x;
	}
	return ans;
}
LL sum(int a,int b,LL bit[]){
	return sum(b,bit)-sum(a-1,bit);
}
LL dist(int x){
	return sum(bs[x],sumBIT)*talls[x]+sum(bs[x],BIT);
}
int LCA(int a,int b){
	if(talls[a]<talls[b]) return LCA(b,a);
	int need=talls[a]-talls[b];
	REP(i,20)
		if(need&(1<<i))
			a=master[a][i];
	if(a==b) return a;
	REP(i,20){
		int k=20-i-1;
		if(master[a][k]!=master[b][k]){
			a=master[a][k];
			b=master[b][k];
		}
	}
	return master[a][0];
}
int main(){
	cin >> N >> Q;
	int a,b,c;
	nums.PB(0);
	REP(i,N-1){
		scanf("%d%d",&a,&b);
		child[a].PB(b);
		master[b][0]=a;
	}
	Euler();
	FOR(i,1,20)
		REP(j,N)
			master[j][i]=master[master[j][i-1]][i-1];
	REP(i,Q){
		scanf("%d%d%d",&a,&b,&c);
		if(a){
			add(bs[b]+1,c,sumBIT);
			add(ne[b],-c,sumBIT);
			add(bs[b]+1,-c*talls[b],BIT);
			add(ne[b],c*talls[b],BIT);
		}
		else{
			printf("%lld\n",dist(b)+dist(c)-2*dist(LCA(b,c)));
		}
	}

}	

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

int main(){
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	
	int Max = C;
	if(B > Max)	Max = B;
	if(A > Max)	Max = A;
	
	int Pow=Max, i;
	
	for(i=0; i<K; i++)
		Pow *= 2;
	
	int MaxSum = A + B + C - Max + Pow;
	cout << MaxSum << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
p = input().split()
q = input().split()



def kai(s):
    var = s
    for i in range(1, s):
        var = var * i
    return var

def jun (v):
    l = [i for i in range(1, n + 1)]
    vn = 1
    for i in range(len(v)):
        tmp  = int(v[i])
        tmp_l = list(filter(lambda x: x < tmp, l))
        vn += len(tmp_l) * kai(len(l)-1)
        l.remove(tmp)
    return vn

print(abs(jun(p) - jun(q)) )




Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

int main(){
    int h,w;
    cin >> h >> w;
    string s[h];
    for(int i=0; i<h;i++)
        cin >> s[i];
    long long int ans[h][w];
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            ans[i][j] = 0;
        }
    }

    ans[0][0] = 1;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(i>=1 && s[i-1][j]!='#')
                ans[i][j] = (ans[i][j] + ans[i-1][j])%mod;
            if(j>=1 && s[i][j-1]!='#')
                ans[i][j] = (ans[i][j] + ans[i][j-1])%mod;
        }
    }
    cout << ans[h-1][w-1];
    return 0;
}

Measured memory_bytes: 13260
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,k,c;
char s[maxn];
int f[maxn],g[maxn],ft[maxn];
signed main(){
	n=read(),k=read(),c=read();
	scanf("%s",s+1);
	int pre=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='o'&&pre<i){
			pre=min(i+c,n);
			f[i]=f[i-1]+1;
		}
		else f[i]=f[i-1];
		ft[i]=pre;
	//	printf("%d %d\n",f[i],ft[i]);
	}
	for(int i=n;i>=1;i--){
		if(s[i]=='o'){
			g[i]=g[min(n+1,i+c+1)]+1;
		}
		else g[i]=g[i+1];
	//	printf("%d\n",g[i]);
	}
	for(int i=1;i<=n;i++){
		if(s[i]=='o'){
			//printf("%d %d %d\n",i,f[i-1],g[max(ft[i-1],i)+1]);
			if(f[i-1]+g[max(ft[i-1],i)+1]<k){
				printf("%d\n",i);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4096
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		System.out.println(Math.max(a*b, c*d));
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

long long COM(ll n) {
    if (n < 2) return 0;
    return n * (n - 1) / 2;
}

int main()
{
    ll n;
    cin >> n;
    vector<ll> A(n+10, 0);
    vector<ll> B(n+10, 0);

    rep(i, n) {
        cin >> A[i];
        A[i]--;
        B[A[i]]++;
    }

    ll res = 0;
    rep(i, n) {
        res += COM(B[i]);
    }

    rep(i, n) {
        cout << res - COM(B[A[i]]) + COM(B[A[i]] - 1) << endl;
    }

    return 0;
}

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

using namespace std;

int solve(const std::vector<int>& ps, int a, int b) {
  auto greaterA = std::upper_bound(ps.begin(), ps.end(), a);
  auto greaterB = std::upper_bound(ps.begin(), ps.end(), b);
  int const q1candidates = greaterA - ps.begin();
  int const q2candidates = greaterB - greaterA;
  int const q3candidates = ps.end() - greaterB;
  return std::min(std::min(q1candidates, q2candidates), q3candidates);
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n, a, b;
  std::cin >> n >> a >> b;
  std::vector<int> ps(n);
  for (auto& p : ps) {
    std::cin >> p;
  }
  std::sort(ps.begin(), ps.end());
  std::cout << solve(ps, a, b) << std::endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int M=scan.nextInt();
		int A[]=new int[N];
		String coment="No";
		int total=0;
		for(int i=0;i<N;i++){
			A[i]=scan.nextInt();
		}
		for(int i=0;i<N;i++){
			total+=A[i];
		}
		int count=0;
		double border=(1.0/(4.0*M))*total;
		for(int i=0;i<N;i++){
			if(A[i]>=border){
				count++;
			}
		}
		if(count>=M){
			coment="Yes";
		}
		System.out.println(coment);

	}

}


Measured memory_bytes: 23764
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue>
#include <vector>

using namespace std;

#define REP(I,A,B) for(int I = (A); I < (B); ++I)
#define REPN(I,A,B) for(int I = (A); I > (B); --I)
#define MAX(A,B) ((A) > (B) ? (A) : (B));

int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

int rb[200000];
int lb[200000];

int main() {
	int n,a,b;
	cin >> n >> a>> b;
	REP(i, 0, n) {
		char ch;
		cin >> ch;
		if (ch == 'a' && (a + b) > 0) {
			cout << "Yes" << endl;
			if (a == 0)
				b--;
			else
				a--;
			continue;
		}
		if (ch == 'b' && b > 0) {
			cout << "Yes" << endl;
			b--;
			continue;
		}

		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define maxn 3010
long long f[maxn];
int r,g,b,n,i;
int main()
{
	f[0]=1;
	scanf("%d%d%d%d",&r,&g,&b,&n);
	for (i=0;i<=n-r;i++)
		f[i+r]+=f[i];
	for (i=0;i<=n-g;i++)
		f[i+g]+=f[i];
	for (i=0;i<=n-b;i++)
		f[i+b]+=f[i];
	printf("%lld\n",f[n]);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

typedef struct Card {
    char suit;
    int value;
}Card;

Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(Card A[], int n, int left, int mid, int right){
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;

    for(int i = 0; i < n1; i++){
        L[i] = A[left + i];
    }
    for(int i = 0; i < n2; i++){
        R[i] = A[mid + i];
    }

    L[n1].value = R[n2].value = SENTINEL;
    
    i = 0;
    j = 0;

    for(int k = left; k < right; k++){
        if(L[i].value <= R[j].value){
            A[k] = L[i++];
        }else{
            A[k] = R[j++];
        }
    }
}

void mergeSort(Card A[], int n, int left, int right){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}



int partition(Card A[], int n, int p, int r){
    int i, j;
    Card x, t;
    x = A[r];
    i = p -1;
    for(j = p; j < r; j++){
        if(A[j].value <= x.value){
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i + 1];
    A[i + 1] = A[r];
    A[r] = t;
    return i + 1;
}

void quickSort(Card A[], int n, int p, int r){
    int q;
    if(p < r){
        q = partition(A, n, p, r);
        quickSort(A, n, p, q-1);
        quickSort(A, n, q + 1, r);
    }
}

int main(){
    int n, i, v;
    Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n-1);

    for(i = 0; i < n; i++){
        if(A[i].suit != B[i].suit){
            stable = 0;
        }
    }

    if(stable == 1){
        printf("Stable\n");
    }else{
        printf("Not stable\n");
    }
    for(i = 0; i < n; i++){
        printf("%c %d\n", B[i].suit, B[i].value);
    }
    return 0;
}


Measured memory_bytes: 4932
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        a: f64, b: f64, x: f64,
    }
    let x = x / a;
    let pi = (-1.0f64).acos();
    let ans = if x * 2.0 >= a * b {
        ((b - x / a) * 2.0 / a).atan()
    } else {
        pi / 2.0 - (x / b / b * 2.0).atan()
    };
    puts!("{}\n", ans * 180.0 / pi);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			int a = Integer.parseInt(chr[0]);
			int b = Integer.parseInt(chr[1]);
			System.out.println((a*b)%2==0?"Even"
							  :"Odd");

		}
	}
}

Measured memory_bytes: 25384
gomennnasai = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 
6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 
5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]

k = int(input())
print(gomennnasai[k-1])

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

int main(){
	ll a, b, c, k;
	cin >> a >> b >> c >> k;

	ll res;
	if (k%2 == 0) res = a - b;
	else res = b - a;

	if (abs(res) > 1e18) {
		cout << "Unfair" << endl;
	} else {
		cout << res << endl;
	}

	return 0;
}


Measured memory_bytes: 256
N, M, X = map(int, input().split())
Ca = [list(map(int, input().split())) for _ in range(N)]
pattern = []
for i in range(2**N):
    lis = []
    for j in range(N):
        if ((i>>j)&1):
            lis.append(Ca[j])
    pattern.append(lis)

cnt = []
for i in range(2**N):
    g = [0] * (M+1)
    for j in range(len(pattern[i])):
        for k in range(M+1):
            g[k] += pattern[i][j][k]
    if M==1 and g[1]< X:
        continue
    elif M>1 and min(g[1:M+1]) < X:
        continue
    else:
        cnt.append(g[0])
if len(cnt) ==0:
    print(-1)
else:
    print(min(cnt))

Measured memory_bytes: 9704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int first=-1,end=-1;
    string s;
    cin >> s;
    rep(i,s.length()){
        if(first<0&&s[i]=='A')first=i;
        if(s[i]=='Z')end=i;
    }
    cout << end-first+1 << endl;
}


Measured memory_bytes: 640
#include<bits/stdtr1c++.h>
#include<list>
#include<algorithm>
#include<cstdlib>
using namespace std;

int main(){
    string N;
    cin >> N;
    if((N[0]==N[1] && N[1] == N[2])||(N[1] == N[2] && N[2] == N[3])){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll powmod(ll x, ll n) { // like pow(x, n)
  ll r = 1;
  while (n) {
    if (n & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return r;
}

int main(int argc, char** argv) {
  int N;
  cin >> N;
  string S;
  cin >> S;

  // Check the count of chars from last.
  int cnts[26]; // The count of each chars. The index is chr - 'a'.
  memset(cnts, 0, sizeof(cnts));

  rep(i, N) {
    int cur = S[i] - 'a';
    ++cnts[cur];
  }

  ll ans = 1;
  rep(j, 26) {
    ans *= (cnts[j] + 1); // Each chars or nothing.
    ans %= MOD;
  }
  ans -= 1;
  (ans += MOD) %= MOD;

  cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
#include<unordered_map>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(int i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
/* Coding Space*/
int main(){
  ll n,m; cin >> n >> m;
  ll ans = 0;
  vector<ll> x(n+1),y(m+1);
  rep(i,n) cin >> x[i+1];
  rep(i,m) cin >> y[i+1];
  ll xx=0,yy=0;
  for(int i = 1; i <= n; i++){
    xx += (i-1)*x[i] - (n-i)*x[i];
    xx %= DIV;
  }
  for(int i = 1; i <= m; i++){
    yy += (i-1)*y[i] - (m-i)*y[i];
    yy %= DIV;
  }
  cout << (xx*yy)%DIV << endl;
}

Measured memory_bytes: 1792
#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 long long ll;

const int mod=1e9+7;
const int inf=-1;
const int sz=2e5;

#define pi acos(-1);
#define pb push_back;
#define mp make_pair;
#define ff first;
#define ss second;
#define gap ' ';
#define lb lower_bound;
#define ub upper_bound;
#define clr(x) memset(x,0,sizeof(x));
#define all(x) x.begin(),x.end();
#define rall(x) x.begin(),x.end();
#define dbg puts("finding wrong");
#define case(x,y) printf("Case %lld: %lld\n",++x,y);
#define fastio ios::sync_with_stdio(false);cin.tie(0);

typedef vector<ll> v;
typedef map<ll,ll>use;
typedef set<ll>st;
typedef queue<ll>q;
typedef deque<ll>dq;
typedef pair<ll,ll>pa;
typedef vector<pa>vii;

int ar[sz];

int main()
{
  fastio;
  ll r=0, w=0, ans=0, i, n, j;
  string s;

  cin>>n>>s;

  for(i=0, j=n-1; i<n and j>=0; i++, j--)
  {
   while(s[i]=='R' and i<n) i++;

   while(s[j]=='W' and j>=0) j--;

   if(i<j and i<n and j>=0)
   {
   	ans++;	
   	swap(s[i],s[j]);
   }
  }

  printf("%lld\n",ans);
}


Measured memory_bytes: 3852
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstdlib>
using namespace std;
int n,m;
int dis[16][16];
int dp[1<<16][16];
int subres[1<<16];
int sum;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		x--;y--;
		dis[x][y]=dis[y][x]=z;
		sum+=z;
	}
	for(int i=1;i<(1<<n);i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i>>j&1)
			{
				for(int k=j+1;k<n;k++)
				{
					if(i>>k&1)subres[i]+=dis[j][k];
				}
			}
		}
	}
	for(int i=0;i<(1<<n);i++)
	{
		for(int j=0;j<n;j++)dp[i][j]=-1;
	}
	for(int i=1;i+1<(1<<n);i++)
	{
		if(i>>(n-1)&1)continue;
		if(i&1)
		{
			dp[i][0]=0;
			for(int j=0;j<n;j++)
			{
				if(i>>j&1)
				{
					for(int k=j+1;k<n;k++)
					{
						if(i>>k&1)dp[i][0]+=dis[j][k];
					}
				}
			}
		}
	}
	for(int i=1;i+1<(1<<n);i++)
	{
		for(int j=0;j<n;j++)
		{
			if(dp[i][j]==-1)continue;
			int st=((1<<n)-1)^i;
			if(dis[j][n-1])
			{
				dp[(1<<n)-1][n-1]=max(dp[(1<<n)-1][n-1],dp[i][j]+subres[st]+dis[j][n-1]);
			}
			for(int k=(st-1)&st;k;k=(k-1)&st)
			{
				if(k>>(n-1)&1)continue;
				for(int l=0;l<n;l++)
				{
					if(k>>l&1)
					{
						if(dis[j][l])
						{
							dp[i|k][l]=max(dp[i|k][l],dp[i][j]+subres[k]+dis[j][l]);
						}
					}
				}
			}
		}
	}
	printf("%d",sum-dp[(1<<n)-1][n-1]);
	return 0;
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    string S;
    cin >> S;
    string left, right;
    if (S.length() % 2 == 0) {
        left = S.substr(0, S.length()/2);
        right = S.substr(S.length()/2, S.length()/2);
    } else {
        left = S.substr(0, (S.length()-1)/2);
        right = S.substr((S.length()+1)/2, (S.length()-1)/2);
    }
    int ans = 0;
    reverse(right.begin(), right.end());
    for (int i = 0; i < left.length(); ++i) {
        if (left[i] != right[i]) {
            ans++;
        }
    }
    print(ans);
}

signed main() {
    solve();
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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 U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, M;
	cin >> N;
	vector<string> S(N);
	REP(i, N) cin >> S[i];
	string s, t;
	map<string, int64> cnt;
	int64 mx = 0;
	REP(i, N) {
	  cnt[S[i]]++;
	  chmax(mx, cnt[S[i]]);
	}
	vector<string> res;
	for (auto &x : cnt) {
	  if (x.sc == mx) {
	    res.push_back(x.fs);
	  }
	}
	sort(all(res));
	REP(i, res.size()) {
	  cout << res[i] << endl;
	}
}


Measured memory_bytes: 27120
from itertools import permutations

N,M = map(int,input().split())

mat = [[0 for i in range(N)] for j in range(N)]

for _ in range(M):
    a,b = map(int,input().split())
    mat[a-1][b-1] = 1
    mat[b-1][a-1] = 1

ans = 0
for i in permutations(range(N)):
    if i[0] != 0:
        continue
    else:

        flag = True
        for j in range(N-1):
            if not mat[i[j]][i[j+1]]:##つながってない
                flag = False
                break
        if flag:
            ans += 1 

print(ans)

Measured memory_bytes: 9228
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import sys

N = int(input())

tt = 0
for i in range(5000):
    tmp = i * (i-1) // 2
    if tmp >= N:
        tt = i
        ans = tmp - N
        break

for t in range(1, tt):
    if t == ans:
        continue
    print(t)


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

using namespace std;

#define sz(c) ((int)c.size())
#define	pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;

constexpr int MAX_N = 200'074;
constexpr int SIGMA = 30;
constexpr ll INF = 1'000'000'000LL;
constexpr ll P = 9'982'443'53;
constexpr double PI = 3.14159265359;
constexpr double TO_RAD = PI/180.;
constexpr long double EPS = 1e-6;

int main(){
	int a, b;
	cin >> a >> b;
	cout << a*b << "\n";

	return 0;
}

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

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

	int N;
	scanf("%d", &N);

	vector<int> C(N + 1, 0);
	int tmp;
	for (int i = 1; i < N + 1; i++) {
		scanf("%d", &tmp);
		// printf("[%d]", tmp);
		if (tmp <= N) {
			C[tmp]++;
		}
	}
	int len = 0;
	for (int i = 1; i < N + 1; i++) {
		len += C[i] >= i ? i : 0;
	}
	printf("%d", N - len);
	return 0;

	// vector<int> A(N);
	// for (int i = 0; i < N; i++) {
	// 	scanf("%d", &A[i]);
	// 	// printf("[%d]", A[i]);
	// }

	// int len = 0;
	// for (int i = 0; i < N + 1; i++) {
	// 	// printf("%d, %d\n", i, (int)count(A.begin(), A.end(), i));
	// 	len += (int)count(A.begin(), A.end(), i) >= i ? i : 0;
	// }

	// printf("%d", N - len);
	// return 0;
}

Measured memory_bytes: 640