akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int par1[200001],par2[200001];
vector<pair<int,int>> idx;
map<pair<int,int>,int> cnt;
int rep1(int n)
{
    if(par1[n]==n)
        return n;
    return par1[n]=rep1(par1[n]);
}
int rep2(int n)
{
    if(par2[n]==n)
        return n;
    return par2[n]=rep2(par2[n]);
}
int main()
{
    int i,j;
    int n,k,l;
    int a,b,res=0;
    scanf("%d %d %d",&n,&k,&l);
    for(i=1;i<=n;i++){
        par1[i]=i;
        par2[i]=i;
    }
    for(i=0;i<k;i++){
        scanf("%d %d",&a,&b);
        swap(a,b);
        int r1=rep1(a);
        int r2=rep1(b);
        par1[r1]=r2;
    }
    for(i=0;i<l;i++){
        scanf("%d %d",&a,&b);
        int r1=rep2(a);
        int r2=rep2(b);
        par2[r1]=r2;
    }
    for(i=1;i<=n;i++){
        idx.push_back(make_pair(rep1(i),rep2(i)));
    }

    for(i=0;i<idx.size();i++){
        cnt[idx[i]]++;
        //printf("%d %d\n",idx[i].first,idx[i].second);
    }
    for(i=0;i<idx.size();i++)
        printf("%d ",cnt[idx[i]]);
}


Measured memory_bytes: 15088
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#define N 1000000
using namespace std;

int main(){
	int n,k,s=0,d=0;
	scanf(" %d %d", &n , &k);
	int a[N],h1,h2,h3,h4,h5;
	int i=0;
	for(;n-i>6; i+=5){
		scanf(" %d\n%d\n%d\n%d\n%d\n",&h1,&h2,&h3,&h4,&h5);
		a[i]=h1; a[i+1]=h2; a[i+2]=h3; a[i+3]=h4; a[i+4]=h5;
		s +=(h1+h2+h3+h4+h5)/k;
		d = max( max(h1, max(h2, h3)), max(h4, max(h5, d)));
	}
	for(;i<n;i++){
		scanf(" %d", &h1);
		s += h1/k;
		d = max(d, h1);
		a[i] = h1;
	}
	
	int low=s-1,high,mid;
	high = min(1000000000,(d*n)/k);
	while(1){
		if(high-low <= 1) break;
		mid = (low+high)/2;
		int count=0, bef=0,bag,p;
		bool f = true;
		while(1){
			if(bef == n) break;
			if(count >= k){
				f = false;
				break;
			}
			bag = mid;
			for(p=bef;p<n;p++){
				if(bag >= a[p]) bag-=a[p];
				else break;
			}
			bef = p;
			count++;
		}
		if(f) high = mid;
		else low = mid;
	}
	
	printf("%d\n", high);	
	return 0;
}

Measured memory_bytes: 1592
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#pragma warning(disable : 4996)
using namespace std;
int N; char M[15];
int p[50]; long long power[20];
inline long long div(long long k, int m) {
	long long sum = 0;
	while (k >= 1) {
		k /= m; sum += k;
	}
	return sum;
}
int main() {
	while (true) {
		scanf("%d%s", &N, M); power[0] = 1;
		for (int i = 0; i < 50; i++)p[i] = 0;
		for (int i = 1; i < strlen(M); i++)power[i] = power[i - 1] * N;
		if (N == 0)break;
		long long C = 0;
		for (int i = 0; i < strlen(M); i++) {
			int V = (char)(M[i] - '0'); if (M[i] >= 'A')V = (char)(M[i] - 'A') + 10;
			C += power[strlen(M) - 1 - i] * V;
		}
		int L = N;
		for (int i = 2; i <= L; i++) {
			while (L%i == 0) {
				L /= i; p[i]++;
			}
		}
		long long minx = 1LL << 62;
		for (int i = 2; i <= N; i++) {
			if (p[i] == 0)continue;
			minx = min(minx, div(C, i) / p[i]);
		}
		printf("%lld\n", minx);
	}
	return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,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; }
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound 

int dp[100100];
ll N,M;
Graph G;

int rec(int v)
{
  //dp[v]:=ノードvを始点とした時のGの有効パスの長さの最大値
  if (dp[v]!=-1) return dp[v]; //すでに更新済
  
  int res=0;
  for (auto nv : G[v])
  {
    chmax(res, rec(nv)+1); 
  }
  return dp[v]=res;//メモしながらリターン
}

int main()
{
  cin>>N>>M;
  G.assign(N,vector<ll>());
  for (int i=0;i<M;i++)
  {
    int x,y;cin>>x>>y;
    x--;y--;
    G[x].push_back(y);
  }
  
  //初期化
  for (int v=0;v<N;v++) dp[v]=-1;
  
  //全ノードを一通り更新しながら答えを求める
  int res=0;
  //v起点の最長経路の長さを求める
  for (int v=0;v<N;v++)
    chmax(res,rec(v));
  cout<<res<<endl;
}

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

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  string S; cin>>S;
  sort(S.begin(), S.end());
  YesNo(S[0] ==	S[1] &&	S[1] !=	S[2] &&	S[2] ==	S[3]);
  return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstdio> 
#include<cstring>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
typedef long long ll;
const ll mod=1e9+7;
const ll INF=0x3f3f3f3f;
const ll maxn=1e6+5;
const double pi = acos(-1.0);
using namespace std;
int main(){
	string s,ss,sss;
	int n;
	cin>>n;
	cin>>s>>ss;
	int ans=0;
	for(int i=0;i<n;i++){
		sss[ans++]=s[i];
		sss[ans++]=ss[i];
	}
	for(int i=0;i<2*n;i++)
	cout<<sss[i];
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int main(void)
{
	vector<int>up, dn;
	int n, m;
	cin >> n >> m;
	up.resize(n, 1);
	dn.resize(n, 1);
	vector<pair<int, int>>xy;
	for (int i = 0; i < m; ++i)
	{
		int x, y; cin >> x >> y;
		xy.push_back(make_pair(-x, y));
	}
	sort(xy.begin(), xy.end());
	for (auto p : xy)
	{
		int d = p.second;
		up[d - 1] += up[d];
		up[d] = 0;
		dn[d] += dn[d - 1];
		dn[d - 1] = 0;
	}
	vector<int>uu, dd;
	for (int i = 0; i < n; ++i)
	{
		while (up[i])
		{
			--up[i];
			uu.push_back(i);
		}
		while (dn[i])
		{
			--dn[i];
			dd.push_back(i);
		}
	}
	for (int i = 0; i < n; ++i)
	{
		cout << dd[i] - uu[i] + 1 << " \n"[i == n - 1];
	}
	return 0;
}

Measured memory_bytes: 7488
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,ans;
char s[2005],t[2005];
int dp[2005],vis[2005];
int add(int x,int y){return (x+y<n)?x+y:x+y-n;}
int mins(int x,int y){return (x>=y)?x-y:x-y+n;}
void solve()
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=n;j++)dp[j]=0,vis[j]=0;
		for(int j=0;j<n;j++)
		{
			if(s[j]=='0')continue;
			int cnt=0;
			int r;
			for(r=add(j,1);s[r]=='0';r=add(r,1))cnt++;
			if(i>=cnt)continue;
			cnt-=i;
			int l=add(j,i+1);
			for(int k=l,u=1;k!=r;k=add(k,1),u++)
			{
				if(u>1)vis[k]=vis[mins(k,1)];
				if(t[k]!=s[add(j,u)])vis[k]=u;
				dp[cnt-u]=max(dp[cnt-u],vis[k]);
			}
		}
		int sum=0,ans2;
		for(int j=0;j<n;j++)if(s[j]!=t[add(j,i)])sum++;
		ans2=100000;
		for(int j=0;j<=n;j++)ans2=min(ans2,2*j+2*dp[j]+i);
		ans=min(ans,ans2+sum);
	}
}
int main()
{
	ans=1000000000;
	scanf("%s%s",t,s);
	n=strlen(s);
	int ok=0;
	for(int i=0;i<n;i++)if(s[i]=='1')ok=1;
	if(ok==0)
	{
		for(int i=0;i<n;i++)if(t[i]=='1')ok=1;
		if(ok)printf("-1\n");
		else printf("0\n");
		return 0;
	}
	solve();
	for(int i=0;i<n/2;i++)swap(s[i],s[n-1-i]),swap(t[i],t[n-1-i]);
	solve();
	printf("%d\n",ans);
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll mod = 1e9 + 7;
#define EPS 1e-1
#define PI 3.14159265

#define iofile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;

ll fastpow(ll base, ll pow)
{
    if (!base)
        return 0;
    if (!pow)
        return 1;
    if (pow == 1)
        return base;
    ll x = fastpow(base, pow / 2) % mod;
    x *= x;
    x %= mod;
    if (pow % 2)
        x *= base;
    return x % mod;
}

ll inverse(ll x)
{
    return fastpow(x, mod - 2) % mod;
}

ll fact[(int)1e6 + 5], inv[(int)1e6 + 5];
void init()
{
    fact[0] = inv[0] = 1;
    for (int i = 1; i <= 1e6; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = inverse(fact[i]);
    }
}

void factorize(ll x, map<int, int> &ss)
{
    while (x % 2 == 0)
        ss[2]++, x /= 2;
    for (int i = 3; i <= sqrt(x); i += 2)
        while (x % i == 0)
            ss[i]++, x/= i;
    if (x > 2)
        ss[x]++;
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

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

int arr[(int)1e5 + 5];
int dp[(int)1e5 + 5];
    int n;

ll solve(int idx)
{
    if (idx >= n - 1)
        return 0;
    if (dp[idx] != -1)
        return dp[idx];
    int c1 = 1e9;
    if (idx + 1 < n)
    {
        c1 = 0;
        c1 = abs(arr[idx] - arr[idx + 1]) + solve(idx + 1);
    }
    int c2 = 1e9;
    if (idx + 2 < n)
    {
        c2 = 0;
        c2 = abs(arr[idx] - arr[idx + 2]) + solve(idx + 2);
    }
    return dp[idx] = min(c1, c2);
}

int main()
{
    fastio
    memset(dp, -1, sizeof dp);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    cout << solve(0);
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>

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

    long long r = 0, g = 0, b = 0;
    for(unsigned int i = 0; i < N; i++){
        if(S.at(i) == 'R') r++;
        if(S.at(i) == 'G') g++;
        if(S.at(i) == 'B') b++;
    }
    
    long long sum = r * g * b;

    for(unsigned int i = 0; i < N; i++){
        for(unsigned int j = i + 1; j < N; j++){
            unsigned int k = j + (j - i);
            if(k < N){
                if(S.at(i) != S.at(j) && S.at(i) != S.at(k) && S.at(j) != S.at(k)){
                    sum--;
                }
            }
        }
    }

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


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
#define int ll
#define INF INT_MAX/10
#define MOD 1000000007

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

signed main() {
  int N, M; cin >> N >> M;
  vector<Pi> T;
  for (int i = 0; i < N; i++) {
    int a, b; cin >> a >> b;
    T.push_back(Pi(a, b));
  }
  auto comparator = [](const Pi &l, const Pi &r) {
                      return l.first < r.first;
                    };
  
  sort(T.begin(), T.end(), comparator);

  int ans = 0;
  int num = 0;
  for (auto x: T) {
    int sec = x.second;
    while (num < M && sec > 0) {
      ans += x.first;
      sec--;
      num++;
    }
  }

  cout << ans << endl;
}


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

const ll INF = 1LL << 60;

ll N;
vector<ll> A;
int main() {
    cin >> N;
    A.resize(N - 1);
    rep(i, N - 1) cin >> A[i];

    map<ll, ll> mp;
    for (int i = N - 2; i >= 0; i--) {
        mp[A[i]]++;  
    }

    // for (auto v : mp) {
    //     cout << v.first << " " << v.second << endl;
    // }

    for (int i = 1; i <= N; i++) {
        cout << mp[i] << endl;
    }
}

Measured memory_bytes: 17212
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,j,n) for(int i=j;i<=n;i++)
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int s;
    cin>>s;
    switch(s){
        case 25:
        cout<<"Christmas ";
        break;
        case 24:
         cout<<"Christmas Eve ";
         break;
        case 23:
         cout<<"Christmas Eve Eve";
         break;
        case 22:
         cout<<"Christmas Eve Eve Eve";
         break;
    }
}   
    
    
     

     
   





Measured memory_bytes: 3548
#include<bits/stdc++.h>
#define bye ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    bye;
    int k,p,q,r,a=0,g;
    cin>>k;
    for(p=1;p<=k;p++)
    {
        for(q=1;q<=k;q++)
        {
            g=__gcd(p,q);
            for(r=1;r<=k;r++)
            {
                a+=__gcd(g,r);
            }
        }
    }
    cout<<a;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  int n, ans=0, i;
  cin >> n;
  int a[n];
  for(i=0; i<n; i++)
    cin >> a[i];
  for(i=0; i<n; i++){
    for(;;){
      if(a[i]%2==0){
	a[i]/=2;
	ans++;
      }
      else break;
    }
  }
  cout << ans;
  return 0;
}


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

ans = 0

for i in range(1, N + 1):
    a = list(set(S[:i]))
    b = list(set(S[i:]))
    ans_ = sum([b.count(x) for x in a])
    # print(ans_)
    ans = max(ans, ans_)

print(ans)


Measured memory_bytes: 65584
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    ll N, K, Q;
    cin >> N >> K >> Q;
    vl A(Q);
    for (auto &x : A) cin >> x;
    ll cnt[N] = {};
    FOR(i, 0, Q) {
        cnt[A[i] - 1]++;
    }
    FOR(i, 0, N) {
        cerr << i << ' ' << cnt[i] << endl;
        Yes(K-Q+cnt[i] > 0);
    }
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int A, B;
    cin >> A >> B;
    cout << A * B << endl;
}


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

int n, a[100000];

int gcd(int a, int b) {
    return (a ? gcd(b % a, a) : b);
}

int main() {
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    int g = a[0];
    for(int i = 1; i < n; ++i)
        g = gcd(g, a[i]);
    cout << g << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;
const int INF = 1e9;

string s;
main() {
  int n, cnt = 0;
  cin >> s;
  n = s.size();
  vector<int> ans(n);
  for (int k = 0; k < 2; ++k) {
    for (int i = 0; i < n; ++i) {
      if (s[i] == 'R')
        cnt++;
      else {
        ans[i] += cnt / 2;
        ans[i - 1] += (cnt + 1) / 2;
        cnt = 0;
      }
    }

    reverse(s.begin(), s.end());
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < n; ++i) {
      if (s[i] == 'L')
        s[i] = 'R';
      else
        s[i] = 'L';
    }
  }

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

Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    cout<<(in()==in()?"Yes":"No")<<endl;
}


Measured memory_bytes: 764
#include <stdio.h>

int main(void)
{
    int moji;
    scanf("%d",&moji);
    int a,b;
    a=moji/100;
    b=moji%100;

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

    if(a>0 && a<13 && b>0 && b<13){
        printf("AMBIGUOUS\n");
    }else if(a<100 && b>0 && b<13){
        printf("YYMM\n");
    }else if(a>0 && a<13 && b<100){
        printf("MMYY\n");
    }else{
        printf("NA\n");
    }

    return 0;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

static const ll MOD = 998244353;

ll modPow(ll a, ll b) {
  ll res = 1;
  rep(i, b) {
    res = res * a % MOD;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) {
    int dd;
    cin >> dd;
    // なくても出力時の0以外を含めたチェックではじける
//    if (i == 0 && dd != 0) {
//      cout << 0 << endl;
//      return 0;
//    }
    // 0番目以外が0のとき
    if (i != 0 && dd == 0) {
      cout << 0 << endl;
      return 0;
    }
    d.at(i) = dd;
  }
  map<int, int> mp;
  for (int dd : d) {
    mp[dd]++;
  }
  ll res = 1;
  rep(i, mp.size()) {
    ll tmp = (ll) mp[i];
    // 途中が0なら成立しない
    if (tmp == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (i == 0) {
      if (tmp != 1) {
        cout << 0 << endl;
      }
      continue;
    }
    ll tmp2 = (ll) mp[i - 1];
    res = res * modPow(tmp2, tmp) % MOD;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 8180
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  map<string, int> mp;
  mp["SUN"] = 7;
  mp["MON"] = 6;
  mp["TUE"] = 5;
  mp["WED"] = 4;
  mp["THU"] = 3;
  mp["FRI"] = 2;
  mp["SAT"] = 1;
  string S;
  cin >> S;
  int ans = mp[S];
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main()
{
	int n, moto, qnt=0, menor=50000000;

	cin>>n>>moto;

	int gramas[n];

	for(int i=0; i<n; i++)
	{
		cin>>gramas[i];
		if(gramas[i] < menor)
		{
			menor = gramas[i];
		}
	}


		for (int j=0; j<n; j++ )
		{
			moto -= gramas[j];
			qnt++;
		}

		while(moto>0)
		{
			if (moto - menor >=0)
			{
				moto -= menor;
				qnt++;
			}
			else
			{
				break;
			}

	}

	cout<<qnt<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#define size 500010
#define debug(x) cerr<<#x<<"="<<x
#define gc getchar()
#define db double
#define ll long long
#define rep(i,s,n) for (register int i=s;i<=n;i++)
#define drep(i,n,s) for (register int i=n;i>=s;i--)
#define il inline
using namespace std;

il ll r()
{
	char c; ll x,f=1;
	for (c=gc;!isdigit(c);c=gc) if (c=='-') f=-1; x=c-'0';
	for (c=gc;isdigit(c);c=gc) x=(x<<1)+(x<<3)+c-'0';
	return f*x;
}

int main()
{
	int  n=r(); 
	cout<<n/3<<endl;

	return 0;
}


















Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_A
# Graph
# Result:
import sys

size = int(sys.stdin.readline().strip())
matrix = [0] * (size * size)

for _ in range(0, size):
    vals = [int(x) for x in sys.stdin.readline().strip().split(' ')]
    if vals[1] == 0: continue
    idx = vals[0] - 1
    for i in range(0, vals[1]):
        av_idx = vals[2 + i] - 1
        matrix[size * idx + av_idx] = 1

for i in range(0, size):
    str_ = ''
    for j in range(0, size):
        str_ += '%d' % matrix[size * i + j]
        if j != size - 1:
            str_ += ' '
    print str_

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define nxtr (1ll<<53)
ll n;
char bs[255];
ll mk[11][11],kt[11];
ll ans,a,b;
ll i, j, k;



int main(){
    
    scanf("%lld", &n);
    //printf("a%lld", n);
    while(n){
        scanf("%s", bs);
        a = 1;
        b = 0;
        ans = 1;
        //printf("a");
        fornum(i,0,52){
            ans *= 2;
            a *= 2;
            ans += bs[i] == '1' ? 1 : 0;
            a += bs[i] == '1' ? 1 : 0;
        }
        i = 0;
        //printf("a");
        while(true){
            ll aa = nxtr - ans;
            //printf("%lld\n", aa);
            ll ai = (aa / a + (aa%a?1:0));
            if(ai+i<=n){
                ans += ai * a;
            }else{
                ans += (n-i) * a;
                break;
            }
            i += ai;
            b++;
            ans /= 2;
            a /= 2;
            if(a==0){
                break;
            }
        }
        //printf("%lld\n", b);
        fornum(i,0,12){
            printf("%lld", ((b >> (11ll - i)) & 1ll) ? 1ll : 0ll);
        }
        fornum(i,0,52){
            printf("%lld",((ans >> (51ll - i)) & 1ll) ? 1ll : 0ll);
        }

        printf("\n");
        scanf("%lld", &n);
    }
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int r, D, x;
    cin >> r >> D >> x;
    vector<int> A(10);
    A[0] = r * x - D;
    for (int i = 1; i < 10; i++)
    {
        A[i] = A[i - 1] * r - D;
    }
    for (int i = 0; i < 10; i++)
    {
        cout << A[i] << endl;
    }
}


Measured memory_bytes: 256
main(n,k,m,i){
  for(;scanf("%d%d",&n,&k),n;printf("%d\n",m)){
    for(i=1;i<=k;i++)
      scanf("%d",a+i),b[i]=b[i-1]+a[i];
    for(m=b[i];i<=n;i++){
      scanf("%d",a+i),b[i]=b[i-1]+a[i]-a[i-k];
      if(m<b[i])m=b[i];
    }
  }
  return 0;
}

Measured memory_bytes: 0
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    S = input()
    sl = ['Sunny', 'Cloudy', 'Rainy']

    if S == 'Sunny':
        i = 1
    elif S == 'Cloudy':
        i = 2
    elif S == 'Rainy':
        i = 0

    print(sl[i])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#define int long long
#define endl '\n'
typedef long long ll;


const double PI=acos(-1);
typedef complex<double> base;
inline void fft (vector<base> & a, bool invert) {
	int n=(int) a.size();
	for (int i=1, j=0; i<n; ++i) {
		int bit=n>>1;
		for (;j>=bit;bit>>=1)
			j-=bit;
		j+=bit;
		if(i<j)
			swap(a[i],a[j]);
	}
	for (int len=2; len<=n; len<<=1) {
		double ang = 2*PI/len * (invert ? -1 : 1);
		base wlen(cos(ang), sin(ang));
		for (int i=0; i<n; i+=len) {
			base w(1);
			for (int j=0; j<len/2; ++j) {
				base u=a[i+j], v=a[i+j+len/2]*w;
				a[i+j]=u+v;
				a[i+j+len/2]=u-v;
				w*=wlen;
			}
		}
	}
	if (invert)
		for(int i=0;i<n;++i)
			a[i]/=n;
}

// a, b => coefs to multiply,  res => resulting coefs
// a[0], b[0], res[0] = coef x^0
inline void multiply (const vector<int> & a, const vector<int> & b, vector<int> & res) {//change res to ll if needed
	if(a.size() * b.size() <= 256) {
		res.resize(a.size() + b.size()+1, 0);
		for(int i = 0; i < (int)a.size(); i++)
			for(int j = 0; j < (int)b.size(); j++)
				res[i + j] += 1LL * a[i] * b[j];
		while(res.size()>1 && res.back() == 0) res.pop_back();
		return;
	}
	vector<base> fa (a.begin(), a.end()),  fb (b.begin(), b.end());
	size_t n=1;
	while (n<max(a.size(),b.size())) n<<=1;
	n<<=1;
	fa.resize(n),fb.resize(n);
	fft (fa,false);  fft(fb,false);
	for (size_t i=0; i<n; ++i)
		fa[i]*=fb[i];
	fft (fa, true);
	res.resize (n);
	for(size_t i=0; i<n; ++i)
		res[i]=(int)(fa[i].real()>0 ? fa[i].real()+0.5 : fa[i].real()-0.5);
	while(res.size()>1 && res.back() == 0) res.pop_back();
}

//returns a^pw % mod
ll fastPow(ll a, ll pw, ll mod) {
	ll res = 1;
	a %= mod;
	while(pw > 0) {
		if(pw & 1) res = (res*a)%mod;
		a = (a*a)%mod;
		pw >>= 1;
	}
	return res;
}

const int p = 200003;
const int g = 5;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	/*
	vector<int> facs = {1 , 2 , 11 , 22 , 9091 , 18182 , 100001};
	for(int i = 2; i < p; ++i) {
		bool gen = true;
		for(int power : facs) {
			if(fastPow(i,power,p) == 1) {
				gen = false;
			}
		}
		if(gen) {
			cout << "generator: " << i << endl;
		}
	}
	return 0;
	*/
	int n;
	cin >> n;
	vector<int> arr;
	for(int i = 0; i < n; ++i) {
		int val;
		cin >> val;
		if(val > 0) arr.push_back(val);
	}
	n = arr.size();


	vector<int> order(2*p,0);
	int powG = g;
	for(int i = 1; i < 2*p; ++i) {
		order[i] = powG;
		powG = (powG * g) % p;
	}
	vector<int> inv(p,0);
	for(int i = 1; i < p; ++i) {
		inv[order[i]] = i;
	}
	vector<int> cnts(p,0);
	for(int val : arr) {
		++cnts[inv[val]];
	}
	vector<int> product;
	multiply(cnts,cnts,product);
	int res = 0;
	for(int i = 0; i < product.size(); ++i) {
		res += order[i] * product[i];
	}
	for(int val : arr) {
		res -= (val*val)%p;
	}
	cout << res/2;
}


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

int main(){
    int A,B;
    cin >> A>>B;
    if (A<=5){
        cout<<B*0<<endl;
    }
    else{
        if(A<=12){
            cout<<B/2<<endl;
        }
        else{
            cout<<B<<endl;
        }
    }
    return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define f first
#define s second

using namespace std;

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
ll comb[2001][2001];
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,k;
    cin>>n>>k;


    

    ll r = n-k;
    ll b = k;

    comb[0][0] = 1;
    for(ll i =1;i<=n;i++){
    	comb[i][0] = comb[i][i] = 1;

    	for(ll j = 1;j<i;j++){
    		comb[i][j] = (comb[i-1][j] + comb[i-1][j-1])%mod;
    	}
    }

    for(ll i =1;i<=k;i++){
    	ll x = comb[r+1][i]%mod;
    	ll y = comb[b-1][i-1]%mod;

    	cout<<(x*y)%mod<<endl;
    }


	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

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

const ll mod=1000000007;
//head

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

    int n;
    cin >> n;
    vi a(n);
    vi b(n);
    vi c(n);
    rep(i,0,n) cin >> a[i] >> b[i] >> c[i];
    vector<vi> dp(n,vi(3));
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for(int i = 1; i < n; i++) {
        for(int j = 0; j < 3; j++) {
            if(j == 0) {
                dp[i][j] = max(dp[i-1][1], dp[i-1][2]) + a[i];
            } else if(j == 1) {
                dp[i][j] = max(dp[i-1][0], dp[i-1][2]) + b[i];
            } else {
                dp[i][j] = max(dp[i-1][0], dp[i-1][1]) + c[i];
            }
        }
    }
    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;
    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> data(N, vector<int>(2));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            cin >> data.at(i).at(j);
        }
    }
    for (int i = 0; i < N - 2; i++)
    {
        if (data.at(i).at(0) == data.at(i).at(1) && data.at(i + 1).at(0) == data.at(i + 1).at(1) && data.at(i + 2).at(0) == data.at(i + 2).at(1))
        {
            cout << "Yes" << endl;
            return (0);
        }
    }
    cout << "No" << endl;
    return (0);
}


Measured memory_bytes: 3644
n, m = input().split()
a = [False] * int(n)
penalty = [0] * int(n)
AC = 0
WA = 0
for i in range(int(m)):
  p, s = input().split()
  if(s == "AC" and a[int(p) - 1] == False):
    a[int(p) - 1] = True
    WA += penalty[int(p) - 1]
    AC += 1
  if(s == "WA" and a[int(p) - 1] == False):
    penalty[int(p) - 1] += 1

print(AC, WA)


Measured memory_bytes: 4596
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef long long i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
#pragma endregion

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, m, c;
	cin >> n >> m >> c;
	vector<int> b(m);
	int ans = 0;
	for(int i = 0; i < m; ++i) cin >> b[i];
	for(int i = 0; i < n; ++i){
		int res = c;
		for(int j = 0; j < m; ++j){
			int a;
			cin >> a;
			res += a * b[j];
		}
		if(res > 0) ++ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long
#define ld long double
ld dp[301][301][301];
ll n;
ld solve(ll x,ll y,ll z){
  if(x<0||y<0||z<0)return 0;
  if(x==0&&y==0&&z==0)return 0;
  if(dp[x][y][z]>=0)return dp[x][y][z];
  return dp[x][y][z]=(ld)((n + x * solve(x-1,y,z) + y * solve(x+1,y-1,z) + z*solve(x,y+1,z-1))/(ld)(x+y+z));
}

int main(){
  ll i,j,x,y,z;
  cin>>n;
  x=y=z=0;
  for(i=0;i<n;i++){
    cin>>j; x+=(j==1); y+=(j==2); z+=(j==3);
  }
  memset(dp,-1.0,sizeof(dp));
  cout<<fixed<<setprecision(12)<<solve(x,y,z);
}

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

int main() {
 string S;
 cin >> S;
  if(S.at(0) != S.at(1)||S.at(1) != S.at(2)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
string T;
main()
{
	cin>>T;
	long ans=0;
	int one=0;
	for(int i=0;i<T.size();i++)
	{
		if(T[i]=='1')
		{
			one++;
			ans+=(one+1)/2;
		}
	}
	int pre=0;
	for(int i=0;i<T.size();i++)
	{
		if(T[i]=='0')
		{
			if(pre%2==1)
			{
				pre++;
				ans+=(one+pre+1)/2;
				T[i]='?';
			}
		}
		else
		{
			pre++;
			one--;
		}
	}
	int c[2]={},ad=0;
	for(int i=T.size();i--;)
	{
		if(T[i]=='0')
		{
			ans+=(pre+1)/2;
			ans+=c[(T.size()-i)%2];
		}
		else
		{
			pre--;
			if(T[i]=='1')c[(T.size()-i)%2]++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3764
icase=0
if icase==0:
    aset=set()
    s=int(input())
    aset.add(s)
    for m in range(2,1000001):
        if s%2==0:
            s=s//2
        else:
            s=3*s+1
        if s in aset:
            print(m)       
            break
        else:
            aset.add(s)

Measured memory_bytes: 3060
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  #resource.setrlimit(RLIMIT_STACK, (128*1024*1024,hard))

a,b = inm()
if (a+b)%2 == 0:
    print((a+b)//2)
else:
    print("IMPOSSIBLE")


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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vll vector<long long>
#define inf 1000000100
#define infll 1LL << 50

int main()
{
    int x, n;
    cin >> x >> n;
    set<int> s;
    for(int i =0; i < n; ++i)
    {
        int p;
        cin >> p;
        s.insert(p);
    }
    ll ans = -1;
    for(int d = 0; ; ++d)
    {
        if(!s.count(x-d))
        {
            ans = x-d;
            break;
        }
        if(!s.count(x+d))
        {
            ans = x+d;
            break;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		for(int i=1;i<10001;i++){
			int x = sc.nextInt();
			if(x == 0) break;
			System.out.println("Case " + i + ": " + x);
		}
	}
}

Measured memory_bytes: 40876
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int K,S;
    int X=0,Y=0,Z=0;
    cin >> K >> S;
    
    int count=0;
    
    for(int X=0;X<=K;X++){
        for(int Y=0;Y<=K;Y++){
                Z = S - ( X + Y );
                int sum = X + Y + Z;
                if (sum==S&&Z>=0&&Z<=K) count++;
        }
    }
    
    cout << count;
    
}


Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

ll N, K;
ll p, r, s;

int main(){

    cin >> N >> K;    
    cin >> r >> s >> p;
    string S;
    cin >> S;
    ll ans = 0;

    for(ll i = 0; i < N && i < K; i++){
        for(ll j = i; j < N; j += K){
            if(j - K >= 0 && S[j] == S[j - K]){
                S[j] = '*';
                continue;
            }
            if(S[j] == 'r')ans += p;
            if(S[j] == 's')ans += r;
            if(S[j] == 'p')ans += s;
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;
const int N = 2e5 + 1;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

I int lowbit(cr x) {return x & -x;}

char ss[N];
int f[N], hh[N];
map<int, int> g;

int main() {
	scanf("%s", ss + 1);
	reg n = strlen(ss + 1);
	fo(i, 1, n) {
		reg c = ss[i] - 'a';
		hh[i] = hh[i - 1] ^ (1 << c);
	} memset(f, 63, sizeof(f));
	f[0] = 0; g[0] = 0;
	fo(i, 1, n) {
		if(g.count(hh[i])) f[i] = _min(f[i], g[hh[i]] + 1);
		fo(j, 0, 25) if(g.count(hh[i] ^ (1 << j))) 
		f[i] = _min(f[i], g[hh[i] ^ (1 << j)] + 1);
		if(!g.count(hh[i])) g[hh[i]] = f[i];
		else g[hh[i]] = _min(g[hh[i]], f[i]);
	} pr2(f[n]);
	return 0;
}



Measured memory_bytes: 11392
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] s_char = s.toCharArray();
		Arrays.sort(s_char);
		
		String t = sc.next();
		char[] t_char = t.toCharArray();
		Arrays.sort(t_char);
		for(int i = 0 ; i < t_char.length/2 ; i ++){
			char temp = t_char[t_char.length - i - 1];
			t_char[t_char.length - i - 1] = t_char[i];
			t_char[i] = temp;
		}
		
		//determin all characters 
		boolean loopFlag = false;
		
		
		boolean result = false;
		
		for(int i = 0 ;i < Math.min(s_char.length,t_char.length);i ++ ){
			if(s_char[i] != t_char[i]){
				result = s_char[i] < t_char[i];
				break;
			}
			loopFlag = (i == Math.min(s_char.length,s_char.length) - 1);
		}
		
		if(loopFlag){
			result = (s_char.length < t_char.length);
		}
		
		System.out.println( result ? "Yes" : "No" );
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>




int main() {
	int n, m;

	std::cin >> n >> m;

	std::vector<std::vector<int>> g(n);

	for (int i{}; i < m; ++i) {
		int x, y;
		std::cin >> x >> y;
		g[x - 1].emplace_back(y - 1);
	}

	std::vector<int> dist(n, -1);

	for (int i{}; i < n; ++i) {

		[&](const auto& f, int index) {
			return 
				f(f, index);
		}(
			[&](const auto& f, int index)->int {

				if (dist[index] != -1)// has NOT visited yet
					return dist[index];


				std::decay_t<decltype(dist[index])> ans{ 0 };
				for ( auto e : g[index])
					ans = std::max( f(f, e) + 1, ans);
				

				return
					dist[index] = ans;
			}
			,i
		); 
		//std::cout << "\n";
		//std::cout << dist[i] << "\n";

	}//for

	std::cout << *std::max_element(std::cbegin(dist), std::cend(dist) ) << "\n";

	return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    string s; cin >> s;
    int k = 15 - s.length();
    int n = 0;
    rep(i,s.length()) if(s[i]=='o') n++;
    if(k+n >= 8) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using  namespace std;
typedef long long int ll;
int main()
{
   ll n;
   cin>>n;
   vector<ll> arr(n,0);
   for(ll i=0;i<n;i++)
   {
       cin>>arr[i];
   }
   unordered_map<string,int> s;
   ll count=0;
   if(n<3) {
    cout<<0<<endl; 
   }
   else
   {
       for(ll i=0;i<n;i++)
   {
       for(ll j=0;j<i;j++)
       {
           for(ll k=0;k<j;k++)
           {
               if(arr[i]!=arr[j]&&arr[j]!=arr[k]&&arr[i]!=arr[k])
               {
                //    string str;
                //    str+=arr[k]+'0';
                //    str+=' ';
                //    str+=arr[j]+'0';
                //    str+=' ';
                //    str+=arr[i]+'0';
                //    str+=' ';
                //    cout<<k<<" "<<j<<" "<<i<<endl;
                  if(arr[k]+arr[j]>arr[i]&&arr[i]+arr[j]>arr[k]&&arr[i]+arr[k]>arr[j]) {count++; }
               }
           }
       }
   }
   cout<<count<<endl;
   }
   
   
}

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

const int maxn = 2000, inf = 1e9;

int n, k, q;
int a[maxn];
int val[maxn], cntv;

bool Solve(int l, int r) {
  int cnt0 = 0, cnt1 = 0, cntop = 0;
  for (int i = 0; i <= n; ++i) {
    if (i == n || a[i] < l) {
      cntop += max(0, min(cnt0 + cnt1 - k + 1, cnt0));
      cnt0 = cnt1 = 0;
    } else if (a[i] <= r) {
      ++cnt0;
    } else {
      ++cnt1;
    }
  }
  return cntop >= q;
}

int main(void) {
  scanf("%d%d%d", &n, &k, &q);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  copy(a, a + n, val);
  sort(val, val + n);
  cntv = unique(val, val + n) - val;
  int ans = inf;
  for (int i = 0, j = 0; i < cntv; ++i) {
    while (j + 1 < cntv && !Solve(val[i], val[j])) {
      ++j;
    }
    if (j == cntv - 1 && !Solve(val[i], val[j])) {
      break;
    }
    ans = min(ans, val[j] - val[i]);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
// Problem : A - αlphabet
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define w cout
#define e '\n'
#define int long long
#define sz(x) (int)x.size()
#define re return 
#define vi vector<int>
#define vii vector<pair<int ,int > >
#define F first
#define S second
#define pussy push_back
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

const int N = 1e6 , mod = 1e9 + 7;



signed main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);	
	char a;
	cin >> a;
	if(isupper(a)) w << 'A';else w << 'a';
}


Measured memory_bytes: 3600
import Control.Monad
import Control.Applicative
import Data.List


main :: IO()
main = do
  [a, b, c] <- map read . words <$> getLine
  print $ solve [a, b, c]


solve :: [Int] -> Int
solve [a, b, c] = (f a [b, c]) + (f b [a, c]) + (f c [a, b])
    where
      f :: Int -> [Int] -> Int
      f c lst = if c `elem` lst then 0 else c


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

long long S[202020];
long long A[202020];
int N;
int main()
{
  scanf("%d", &N);
  for(int i=1; i<=N; ++i)
  {
    scanf("%lld", A+i);
    S[i] = S[i-1] + A[i];
  }
  long long ans = 0x3f3f3f3f3f3f3f3fll;
  int atp = 1;
  int ctp = 3;
  for(int tp=2; tp<=N-1; ++tp)
  {
    // A: (0, atp]
    // B: (atp, tp]
    // C: (tp, ctp]
    // D: (ctp, N]
    while(true)
    {
      long long Asum = S[atp]-S[0];
      long long Bsum = S[tp]-S[atp];
      long long Asuf = S[1+atp]-S[0];
      long long Bsuf = S[tp]-S[1+atp];
      if(abs(Asum-Bsum)<=abs(Asuf-Bsuf)) break;
      ++atp;
    }
    while(true)
    {
      long long Csum = S[ctp]-S[tp];
      long long Dsum = S[N]-S[ctp];
      long long Csuf = S[1+ctp]-S[tp];
      long long Dsuf = S[N]-S[1+ctp];
      if(abs(Csum-Dsum)<=abs(Csuf-Dsuf)) break;
      ++ctp;
    }
      long long Asum = S[atp]-S[0];
      long long Bsum = S[tp]-S[atp];
      long long Csum = S[ctp]-S[tp];
      long long Dsum = S[N]-S[ctp];
      ans = min(ans, max({Asum, Bsum, Csum, Dsum}) - min({Asum, Bsum, Csum, Dsum}));
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const double pie = 3.14159265358979;

int main(){
    int a, b;
    cin >> a >> b;
    cout << max(0, a - 2 * b) << endl;
    return 0;
}


Measured memory_bytes: 256
#coding:utf-8

def up(nums):
    if len(nums) == nums.count(9):
        nums = [1] + [0] * len(nums)
        return nums
    
    for i in list(reversed(range(len(nums)))):
        if nums[i] > nums[i-1] or nums[i] == 9:
            continue
        else:
            nums[i] += 1
            for j in range(i+1, len(nums)):
                if j == len(nums) - 1:
                    nums[j] = max(nums[j-1]-1, 0)
                else:
                    nums[j] = max(nums[j-1] - 1, 0)
            return nums
          
  
def main():
    k = int(input())
    if k < 10:
        print(k)
        return
    cnt = 11
    nums = [1, 0]
    while cnt <= k:
        cnt += 1
        nums = up(nums)
        #print(nums)
        
    print(''.join([str(num) for num in nums]))
        
    
        
  
if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
N = int(input())
P = [int(input()) for _ in range(N)]
Q = [0]*N
for i in range(N):
    Q[P[i]-1] = i

count = 0
check = 0
maxlen = 0
for i in Q:
    if check < i:
        count += 1
        check = i
    else:
        maxlen = max(count, maxlen)
        count = 1
        check = i
maxlen = max(count, maxlen)
print(N-maxlen)


Measured memory_bytes: 18892