akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  string op;
  for(int i=0;i<s.size();i++)
  {
    if(s[i]=='0')
      op.push_back('0');
    else if(s[i]=='1')
      op.push_back('1');
    else if(op.size()>0)
      op.pop_back();
  }
  cout<<op<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i < (n); ++i)
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; }
template<class T> inline bool change(T& a, T b) { if (a != b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,k){
        bool update=false;
        vector<int> b(n+1);
        rep(j,n){
            int l=max(j-a[j],0);
            int r=min(j+a[j]+1,n);
            b[l]++; b[r]--;
        }
        rep(j,n){
            if(j==0) chmax(update,change(a[0],b[0]));
            else chmax(update,change(a[j],a[j-1]+b[j]));
        }
        if(!update) break;
    }
    rep(i,n) cout << a[i] << endl;
    return 0;
}

Measured memory_bytes: 4788
N, M = map(int, raw_input().split(' '))
A = [map(int, raw_input().split(' ')) for _ in xrange(N)]

answer = N
for _ in xrange(M):
    participants = [0] * M
    for n in xrange(N):
        participants[A[n][0]-1] += 1
    sport_with_max_participants = max(xrange(M), key=lambda x: participants[x])
    answer = min(answer, participants[sport_with_max_participants])
    for n in xrange(N):
        A[n].remove(sport_with_max_participants+1)

print answer

Measured memory_bytes: 3716
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String word = sc.next();
		StringBuilder str = new StringBuilder();
		for (int i=0; i<word.length();i=i+2)
		{
			str.append(word.substring(i,i+1));
		}
		System.out.println(str.toString());
	}
}

Measured memory_bytes: 41432
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int k = sc.nextInt();
  if(k%2==1){
     System.out.println((k/2)*(k/2)+k/2);
  }else{
     System.out.println((k/2)*(k/2));}}}
    

Measured memory_bytes: 23508
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int n,k;
    cin >> n >> k;
 	int a;
    REP(i, n){
        cin >> a;
    }
	pr((n-2)/(k-1)+1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

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

  int N;
  cin >> N;
  string S=to_string(N);
  int Sum=0;
  for(auto itr=S.begin();itr!=S.end();++itr){
    Sum += *itr-'0';
  }
  if(N%(Sum)==0) cout << "Yes";
  else cout << "No";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
const LL mod=1000000007;
typedef pair<LL,LL>pa;
LL gcd(LL a,LL b){
	if(a%b==0)return b;
	return gcd(b,a%b);
}
int R(LL x){
	if(x<0)return -1;
	if(x==0)return 0;
	return 1;
}
LL pow(LL x,LL p){
	LL ret=1ll;
	while(p){
		if(p&1)ret*=x,ret%=mod;
		p/=2;
		x*=x;x%=mod;
	}
	return ret;
}
map<pa,int>mp;
map<pa,bool>bk;
LL a[N],b[N],ax[N],bx[N],ans,n,tot;
LL st1[N],st2[N],cnt,cnt00,cnta0,cntb0;
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&a[i],&b[i]);
		int flag=R(a[i])*R(b[i]);
		if(flag==0){
			ax[i]=0;bx[i]=0;
			if(a[i]==0&&b[i]==0)cnt00++;
			else if(a[i]==0)cnta0++;
			else cntb0++;
			continue;
		}
		ax[i]=abs(a[i]);bx[i]=abs(b[i]);
		LL tmp=gcd(ax[i],bx[i]);ax[i]/=tmp;bx[i]/=tmp;
		pa now=make_pair(ax[i]*flag,bx[i]);
		mp[now]++;
	}
	for(int i=1;i<=n;i++){ 
		if(ax[i]==0)continue;
		if(!bk[make_pair(ax[i]*R(a[i])*R(b[i]),bx[i])]){
			bk[make_pair(ax[i]*R(a[i])*R(b[i]),bx[i])]=1;
			bk[make_pair(bx[i]*R(a[i])*R(b[i])*(-1),ax[i])]=1;
			LL tmp1=1ll*mp[make_pair(bx[i]*R(a[i])*R(b[i])*(-1),ax[i])];
			LL tmp2=1ll*mp[make_pair(ax[i]*R(a[i])*R(b[i]),bx[i])];
			if(tmp1==0)continue;
			st1[++tot]=tmp1;st2[tot]=tmp2;
			cnt+=tmp1+tmp2;
		}
	}	
	cnt+=cnta0+cntb0+cnt00;
	if(cnta0==0)cnt-=cntb0;
	else if(cntb0==0)cnt-=cnta0;
	else{
		st1[++tot]=cnta0,st2[tot]=cntb0;
	}
	ans=pow(2ll,n-cnt)%mod;
	for(int i=1;i<=tot;i++){
		//cout<<st1[i]<<" "<<st2[i]<<endl;
		LL tmp=(pow(2ll,st1[i])%mod+pow(2ll,st2[i])%mod-1)%mod;
		ans*=tmp;ans%=mod;
	}
	//if(cnt0)ans*=2;ans%=mod;
	ans=ans-1+cnt00;
	if(ans<0)ans+=mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 59780
/*
±¾±¦µÄ³ÌÐòÍâÈË±ðÏë¿´£¡£¡

name: [ÏÄ±¦±¦]
run time£º[] ms
compilation time: [] ms
output memory: [] MiB
where: []
state: []
*/
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

inline int read()
{
	int s=0, w=1;

	char ch=getchar();

	while(ch<'0' || ch>'9')
	{
		if(ch='-')
		{
			w=-w;
		}

		ch=getchar();
	}

	while(ch>='0' && ch<='9')
	{
		s=(((s*10ll))+(ch-'0'));

		ch=getchar();
	}

	return s;
}

long long int n, a, b;

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	
	cout.sync_with_stdio(false);
	ios::sync_with_stdio(0);
	cin.tie(0);
	long long int ksm(long long int x, long long int y);
	long long int xcj(long long int n, long long int m);
	
	n=read();
	a=read();
	b=read();
	
	cout<<(ksm(2, n)-1-xcj(n, a)-xcj(n, b)+mod+mod)%mod<<endl;
	
	return 0;
}

long long int ksm(long long int x, long long int y)
{
	long long int ans=1;
	
	for( ; y; y>>=1, x=x*x%mod)
	{
		if(y&1)
		{
			ans=ans*x%mod;
		}
	}
	
	return ans;
 } 
 
 long long int xcj(long long int n, long long int m)
{
	long long int a1=1, a2=1;
	
	for(long long int i=n; i>=n-m+1; i--)
	{
		a1=a1*i%mod;
	}
	
	for(long long int i=2; i<=m; i++)
	{
		a2=a2*i%mod;
	}
	
	return a1*ksm(a2, mod-2)%mod;
 }

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

int main(){
   int n;
   string s;
   cin >> n >> s;
   int wcount=0;
   int rcount=0;
   int count=0;
   rep(i,n) if(s[i]=='W') wcount++;
   rep(i,n) if(s[i]=='R') rcount++;
   rep(i,rcount) {
      if(s[i]=='W'){
         count++;
      }
   }
   int ans = min(wcount,rcount);
   ans = min(ans,count);
   cout << ans << endl;
   return 0;  
}

Measured memory_bytes: 3716
#include <iostream>
using namespace std;
int N;
const int MOD = 1000000007;
int Fact[1000005], Inv[1000005];
int V[1000005];
int power(int n, int p)
{
    int sol = 1;
    while(p)
    {
        if((p & 1))
        {
            sol = (1LL * sol * n) % MOD;
        }
        n = (1LL * n * n) % MOD;
        p /= 2;
    }
    return sol;
}
void precalcFact()
{
    Fact[0] = 1;
    for(int i = 1; i <= N; i++)
    {
        Fact[i] = (1LL * Fact[i - 1] * i) % MOD;
    }
    Inv[N] = power(Fact[N], MOD - 2);
    for(int i = N - 1; i >= 0; i--)
    {
        Inv[i] = (1LL * Inv[i + 1] * (i + 1)) % MOD;
    }
}

int Comb(int n, int k)
{
    return (((1LL * Fact[n] * Inv[k]) % MOD) * Inv[n - k]) % MOD;
}
inline void Add(int& x, int y)
{
    x += y;
    if(x >= MOD)
        x -= MOD;
}
inline void Sub(int& x, int y)
{
    x -= y;
    if(x < 0)
        x += MOD;
}
void Solve()
{
    --N;
    for(int i = 1; i <= N; i++)
    {
        if(i < N - i)
            continue;
        int aux = Comb(i - 1, N - i);
        aux = (1LL * aux * Fact[i]) % MOD;
        aux = (1LL * aux * Fact[N - i]) % MOD;
        V[i] = aux;
    }
    int ans = 0;
    for(int i = N; i >= 1; i--)
    {
        Sub(V[i], V[i - 1]);
        Add(ans, (1LL * V[i] * i) % MOD);
    }
    cout << ans << "\n";
}
int main()
{
    cin >> N;
    precalcFact();
    Solve();
    return 0;
}


Measured memory_bytes: 11904
#include  <bits/stdc++.h>
using namespace std;
 
#define IOS         ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define mem(a,v)    memset((a), (v), sizeof (a))
#define FOR(i,a,n)  for(int i = (a); i<(n); ++i) 
#define FORE(i,a,n) for(int i = (a); i<=(n); ++i)
#define mp(a , b)   make_pair(a , b)
#define eb(a)       emplace_back(a)

#define anal         '\n'

#define mod 1000000007


typedef long long ll;

vector<int> v;

int main(){
     
 IOS;
 
//#ifndef ONLINE_JUDGE  
   // freopen("input.in", "r", stdin);
   // freopen("output.in", "w", stdout);
//#endif 

 // -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
  
   ll a, b, c, k;
   cin >> a >> b >> c  >> k;
   if(k <= a){
   	  cout << k;
   	  return 0;
   }
   else{
   	  ll sum = a;
   	  k -= a;
   	  if(k <= b){
   	  	 cout << sum;
   	  	 return 0;
   	  }
   	  else{
   	  	 k -= b;
   	  	 cout << sum - k;
   	  }
   }
 return  0 ;      
}        





Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a % 2 == 1 && b % 2 == 1) {
			System.out.print("Yes");
		} else {
			System.out.print("No");
		}
	}
}

Measured memory_bytes: 21716
#include <iostream>


using namespace std;
int H, W, h ,w;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H;
    cin >> W;
    cin >> h;
    cin >> w;
    cout<<H*W-(h*W+w*H)+h*w<<'\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag) {
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
}

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

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

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};


int main(void) {
    long double a, b, c;
    cin >> a >> b >> c;
    ansYes(c >a + b + ((long double)2) * sqrtl((a * b)) );
}




Measured memory_bytes: 256
def solve():
    gx, gy = map(int,input().split())
    N = int(input())
    X = set()#x軸平行な道にマタタビがあるときのゴールに近い方の座標
    Y = set()#y軸平行な道にマタタビがあるときのゴールに近い方の座標
    for i in range(N):
        x1, y1, x2, y2 = map(int,input().split())
        if x1 == x2:
            Y |= {(x2, max(y1, y2))}
        else:
            X |= {(max(x1, x2), y2)}
    ans = [[0 for i in range(gx + 1)] for j in range(gy + 1)]
    ans[0][0] = 1
    for y in range(gy + 1):
        for x in range(gx + 1):
            if y == 0:
                if (x, y) in X or x == 0:
                    pass
                else:
                    ans[y][x] = ans[y][x-1]
            else:
                if x == 0:
                    if (x, y) in Y:
                        pass
                    else:
                        ans[y][x] = ans[y-1][x]
                else:
                    if (x, y) in X and (x, y) in Y:
                        ans[y][x] = 0
                    elif (x, y) in X:
                        ans[y][x] = ans[y-1][x]
                    elif (x, y) in Y:
                        ans[y][x] = ans[y][x-1]
                    else:
                        ans[y][x] = ans[y-1][x] + ans[y][x-1]
    return ans[gy][gx]
p = int(input())
for _ in range(p):
    a = solve()
    if a == 0:
        print('Miserable Hokusai!')
    else:
        print(a)



Measured memory_bytes: 5624
#include<iostream>
#include<cstdio>
using namespace std;
#define int long long
signed main(){
	int ball[3] = {1,0,0};
	char a,b;
	while( scanf("%c,%c", &a, &b) != EOF ){
		a -= 'A';
		b -= 'A';
		int t = ball[a];
		ball[a] = ball[b];
		ball[b] = t;
	}
	for(char i=0;i<3;i++){
		if(ball[i] == 1) cout << (char)('A' + i) << endl;
	}
	return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
typedef pair<ll,ll> ipair;
#define F first
#define S second
 
/*
//functions from gfg
 
long long int power(long long int x,long long int y,long long  int p)
{
    long long int res = 1;     // Initialize result
 
    x = x % p;  // Update x if it is more than or 
                // equal to p
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            {//d=(long double)x/p;
            res = (res*x) % p;
            }
 
        // y must be even now
        y = y>>1; // y = y/2
        x=(x*x)%p;
        
    }
    return res%p;
}
 
long long int gcd(long long int a,long long int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
 
long long int binomialCoeff(long long int n, ll k) 
{ 
    ll res = 1; 
  
    // Since C(n, k) = C(n, n-k) 
    if (k > n - k) 
        k = n - k; 
  
    // Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1] 
    for (ll i = 0; i < k; ++i) 
    { 
        res *= (n - i); 
        res /= (i + 1); 
    } 
  
    return res; 
} 
 

void sieve(int n, vector<ll> &primes) 
{ 
    vector<int> prime(n,1);
    ll p;
    for ( p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == 1) 
        { 
            
            for (int i=p*p; i<=n; i += p) 
                prime[i] = 0; 
        } 
    } 
  
    for(p=2;p<=n;p++)
    {
        if(prime[p])
        primes.pb(p);
    }
   
} 


void dfs(vector<ll> adj[] ,ll src,vector<ll> &vis)
{
    vis[src]=1;
    for(ll i=0;i<adj[src].size();i++)
    {
        if(vis[adj[src][i]]==0)
        dfs(adj,adj[src][i],vis)
    }
}
 
*/

int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    
    
	ll n,i,j,p,k,m,ans=0,a,b,c;
    cin>>a>>b>>c;
    
    k =a+b+c;
    p =max(max(a,b),c);
    if((3*p)%2==k%2)
    {
        cout<<(3*p-k)/2<<endl;
    }
    else
    {
        cout<<(3*(p+1) - k)/2<<endl;
    }
    
    
    
    
    // for(i=0;i<n;i++)
    // {
    //     cout<<a[i]<<" ";
    // }
    // cout<<endl;
    
	return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <stdio.h>
#include <string.h>
#define Max 100005
#define LL long long
using namespace std;
int data[200];
int main()
{
    int  n;
    scanf("%d",&n);
 /*   for(int i=4;i<=100;i+=4)
			data[i]=1;
	for(int i=7;i<=100;i+=7)
			data[i]=1;*/
	for(int i=0;i<=25;i++)
		for(int j=0;j<=14;j++)
		{
			if(i*4+j*7<=100)
				data[i*4+j*7]=1;
		}
	if(data[n])
		printf("Yes\n");
	else
		printf("No\n");
    return 0;
}


Measured memory_bytes: 256
import collections
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
Q=int(input())
d=collections.Counter(A)
for i in range(Q):
  B,C=map(int,input().split())
  s += d[B]*C - d[B]*B
  print(s)
  if C in d:
    d[C]+=d[B]
  else:
    d[C]=d[B]
  d[B]=0

Measured memory_bytes: 24092
import heapq
N,M=map(int,input().split())
A=list(map(lambda x:-int(x),input().split()))
heapq.heapify(A)

for _ in range(M):
    a=-heapq.heappop(A)
    a//=2
    heapq.heappush(A,-a)

print(-sum(A))

Measured memory_bytes: 86368
x, k, d = map(int, input().split())
x_abs = abs(x)
if x_abs >= k * d:
  print(x_abs - k * d)
else:
  n = x_abs // d
  if (k - n) & 1:
    print((n + 1) * d - x_abs)
  else:
    print(x_abs - n * d)

Measured memory_bytes: 9156
/**-------------------------
|--------From A.R.A--------|
-------------------------**/

#include <bits/stdc++.h>

#define ll            long long int
#define pb            push_back
#define ull           unsigned long long int
#define endl          "\n"
#define sz(c)         (c).size()
#define sall(c)       sort((c).begin(),(c).end())
#define rsall(c)      sort((c).rbegin(),(c).rend())
#define rev(c)        reverse((c).begin(),(c).end())
#define FOR(i,n)      for(ll i=0;i<n;i++)
#define max3(a,b,c)   max(max(a,b),c)
#define min3(a,b,c)   min(min(a,b),c)
#define input(a,i,n)  for(ll i=1;i<=n;i++){     cin>>a[i];}
#define output(a,i,n) for(ll i=0;i<n;i++){cout<<a[i]<<" ";}

using namespace std;
int64_t R=1;
int main(){
    int64_t n,cur=1,k=0;
    string s;
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='W'){
            for(int j=n-cur;j>i;j--){
                if(s[j]=='R'){k++;swap(s[j],s[i]);break;}
                if(s[j]=='W'){cur++;}
            }
        }
    }
    cout<<k<<endl;
}


Measured memory_bytes: 3752
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    x = II()
    divs = enumerate_divs(x)
    # print(divs)

    for r,q in divs:
        # for i in range(r+1):
        i = 0
        while True:
            a = i
            b = a-r
            # print(a,b)
            d = a**5-b**5
            if d > x and b >= 0:
                i = 0
                break
            if d==x:
                print(a, b)
                return None
            i+=1


if __name__ == '__main__':
    main()

Measured memory_bytes: 9656
N = int(input())
ans = 0

def primer(x):
    res = []
    y = 2
    while y*y <= x:
        while x % y == 0:
            res.append(y)
            x //= y
        y += 1
    if x > 1:
        res.append(x)
    return res

res_all = []
for i in range(N+1):
    res_all.extend(primer(i))
from collections import Counter
D = Counter(res_all)
ans = 1
for value in D.values():
    ans *= value+1
    ans %= 10**9+7
print(ans)


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

typedef long long ll;
typedef pair<ll,ll> pii;

long long MOD = 1000000000 + 7;

bool compare(pii x, pii y){
  return x.first < y.first;
}

int main(){
  cout << setprecision(10);
  int N;
  cin >> N;

  map<ll,int> m;

  ll ans = 0;

  for(ll i = 1; i <= N; i++){
    ll tmp;
    cin >> tmp;

    if(m.count(i-tmp) == 0){

    } else { 
      ans += m[i-tmp];
    }

    if(m.count(i+tmp) == 0){
      m[i+tmp] = 1;
    } else { 
      m[i+tmp] += 1;
    }

  }
  cout << ans << endl;

}


Measured memory_bytes: 15996
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

const int MAX_P = 10020;
bool prime[MAX_P];

void init()
{
    for (int i = 0; i < MAX_P; i++)
        prime[i] = true;
    prime[0] = prime[1] = false;

    for (int i = 2; i * i < MAX_P; i++)
        if (prime[i]) 
            for (int j = 2 * i; j < MAX_P; j += i)
                prime[j] = false;
}


int main()
{
    init();

    int n;
    while (cin >> n, n) {
        while (n >= 2) {
            if (prime[n] && prime[n - 2]) {
                printf("%d %d\n", n - 2, n);
                break;
            }
            n--;
        }
    }

    return 0;
}

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

int main()
{
    char S[100];
    scanf("%s",&S);
    if(strcmp(S,"Sunny")==0){
        printf("Cloudy");
    }
    if(strcmp(S,"Cloudy")==0){
        printf("Rainy");
    }
    if(strcmp(S,"Rainy")==0){
        printf("Sunny");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)

const int INF = 100000000;

using namespace std;


int main() {
	int a[101] = {0};
	int x;
	rep(i, 0, 3) {
		cin >> x;
		a[x]++;
	}

	int count = 0;
	rep(i, 0, 101) {
		if (a[i] > 0)count++;
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int r = sc.nextInt();
			if (r == 0) {
				sc.close();
				break;
			}

			int n = sc.nextInt();

			int[] xl = new int[n];
			int[] xr = new int[n];
			int[] h = new int[n];
			for (int i = 0; i < n; i++) {
				xl[i] = sc.nextInt();
				xr[i] = sc.nextInt();
				h[i] = sc.nextInt();
			}

			int[] cover = new int[2 * r];
			for (int i = 0; i < n; i++) {
				int ll = Math.max(0, xl[i] + r);
				int rr = Math.min(r * 2, Math.max(0, xr[i] + r));

				for (int j = ll; j < rr; j++) {
					cover[j] = Math.max(cover[j], h[i]);
				}
			}

			double ans = 100000.0;
			for (int i = 0; i < cover.length; i++) {
				// int xx = i - r > 0 ? i - r + 1 : r - i - 1;
				int xx = Math.abs(r - i - 1);
				double t1 = cover[i] - r
						* Math.sin(Math.acos((double) Math.abs(r - i) / r));
				double t2 = cover[i] - r * Math.sin(Math.acos((double) xx / r));
				ans = Math.min(ans, Math.min(t1 + r, t2 + r));
			}

			System.out.println(String.format("%.4f", ans));
		}
	}
}

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

using namespace std;

int main()
{
    int M, T, P, R;
    
    while (scanf("%d %d %d %d", &M, &T, &P, &R) && M){
        vector<pair<pair<int, int>, int> > record(T);
        int wa[64][16] = {0};
        
        for (int i = 0; i < T; i++) record[i].second = -(i + 1);
        
        for (int i = 0; i < R; i++){
            int m, t, p, j;
            scanf("%d %d %d %d", &m, &t, &p, &j);
            if (j) wa[t - 1][p] += 20;
            else {
                record[t - 1].first.first--;
                record[t - 1].first.second += m + wa[t - 1][p];
            }
        }
        
        sort(record.begin(), record.end());
        
        for (int i = 0; i < T; i++){
            printf("%d", -record[i].second);
            if (i + 1 < T && record[i].first == record[i + 1].first) printf("=");
            else if (i + 1 < T) printf(",");
            else printf("\n");
        }
    }
    
    return (0);
}

Measured memory_bytes: 1200
#include "stdio.h"
#include <stdlib.h>
 
int main (){
  int N;
  int a, b, c;
  scanf("%d",&N);
  int A[N+2];
  int B[N+1];
  long counter=0;
  for (int i=1; i<=N+1; i++){
    scanf("%d",&A[i]);
  }
  for (int i=1; i<=N; i++){
    scanf("%d",&B[i]);
  }

  for (int i=1; i<=N; i++){
    if (A[i]>=B[i]){
      //      printf("case1\n");
      A[i]=A[i]-B[i];
      counter+=B[i];
      B[i] = 0;
    } else{
      //      printf("case2\n");
      B[i] = B[i]-A[i];
      counter+=A[i];
      A[i]=0;
      if (A[i+1]>=B[i]){
	A[i+1] = A[i+1]-B[i];
	counter+=B[i];
	B[i]=0;
      } else {
	B[i] = B[i]-A[i+1];
	counter+=A[i+1];
	A[i+1]=0;
      }
    }

    /*    for (int i=1; i<=N+1; i++){
      printf("A[%d]=%d\n",i,A[i]);
    }
    for (int i=1; i<=N; i++){
      printf("B[%d]=%d\n",i,B[i]);
    }
    printf("counter=%d\n",counter);
    */
  }
  
  /*  for (int i=1; i<=N+1; i++){
    printf("A[%d]=%d\n",i,A[i]);
  }
  for (int i=1; i<=N; i++){
    printf("B[%d]=%d\n",i,B[i]);
    }*/
  printf("%ld\n",counter);

  return 0;
}


Measured memory_bytes: 896
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))


def solve():
    h, w = rl()
    starth, startw = rl()
    endh, endw = rl()
    maze = []
    for i in range(h):
        maze.append(list(input()))

    def nbrs(x, y):
        dx = [-1, 1, 0, 0]
        dy = [0, 0, -1, 1]
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if 0 <= nx and nx < h and 0 <= ny and ny < w:
                yield (nx, ny)

    def magic(x, y):
        for nx in range(x - 2, x + 3):
            for ny in range(y - 2, y + 3):
                if nx == x and ny == y: continue
                if 0 <= nx and nx < h and 0 <= ny and ny < w:
                    yield (nx, ny)


    bridges = dd(set)
    def dfs(x, y, num):
        if maze[x][y] != '.':
            return
        else:
            maze[x][y] = num
            for nx, ny in magic(x, y):
                if maze[nx][ny] not in ['.', '#', num]:
                    bridges[num].add(maze[nx][ny])
                    bridges[maze[nx][ny]].add(num)
            for nx, ny in nbrs(x, y):
                dfs(nx, ny, num)

    num = 0
    for x in range(h):
        for y in range(w):
            if maze[x][y] == ".":
                dfs(x, y, num)
                num += 1
   
    curr = [maze[starth-1][startw-1]]
    goal = maze[endh-1][endw-1]
    if curr[0] == goal:
        print (0)
        return

    seen = set(curr)
    depth = 0
    while curr:
        ring = []
        depth += 1
        for node in curr:
            for nxt in bridges[node]:
                if nxt not in seen:
                    if nxt == goal:
                        print (depth)
                        return
                    seen.add(nxt)
                    ring.append(nxt)
        curr = ring

    print (-1)



mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 228456
#include <bits/stdc++.h>
using namespace std;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    int N; cin >> N;
    int ans = 0;
    for (int i = 105; i <= N; i = i + 2) {
        int cnt = 0;
        for (int j = 1; j <= i; j = j + 2) {
            if (i % j == 0) cnt++;
        }
        if (cnt == 8) ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, typename T, T M>
struct ModFact {
    T fact[N+1];
    T ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        fact[0] = 1;
        for (int i=0; i<N; ++i)
            fact[i+1] = (fact[i]*(i+1))%M;
        ifact[N] = power(fact[N], M-2);
        for (int i=N-1; i >= 0; --i)
            ifact[i] = (ifact[i+1]*(i+1))%M;
    }
    constexpr T power(T a, T b) {
        T r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
    constexpr T comb(T n, T r) {
        return (((fact[n]*ifact[r])%M)*ifact[n-r])%M;
    }
};
 
ModFact<100000, ll, MOD> fact;

ll N, ans = 1;
ll cnt = 1;
char S[200000];

int main() {
    scanf("%lld\n", &N);
    fread_unlocked(S, 1, (N<<1), stdin);
    if(S[0] == 'B' && S[(N<<1)-1] == 'B') {
        size_t i;
        bool f = false;
        for(i = 1; i < (N<<1); i++) {
            if(S[i] == S[i-1]) f ^= true;
            if(f) {
                ans *= (cnt << 1) - i;
                if(ans > 1LL<<32) ans %= MOD;
            }
            else cnt++;
            if(cnt > N || i + 1 > N + cnt) break;
        }
        if(i != (N<<1) || cnt != N) ans = 0;
        else ans = (ans * fact.fact[N]) % MOD;
    } else ans = 0;
    printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main(){
    cin>>a>>b>>c>>d;
    if(a+b>c+d)cout<<"Left";
    if(a+b==c+d)cout<<"Balanced";
    if(a+b<c+d)cout<<"Right";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define A 100000

int p(int,int);

int S[A],n;

int main(){
  int i,m;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  m = p(0,n-1);

  for(i=0;i<n;i++){
    if(i)printf(" ");
    
    if(i == m)printf("[");
    
    printf("%d",S[i]);

    if(i == m)printf("]");
  }
  printf("\n");
  return 0;
}

int p(int x,int y){
  int a,b,c,i;

  a = S[y];
  b = x-1;

  for(i=x;i<y;i++){
    if(S[i]<=a){
      b++;
      c = S[b];
      S[b] = S[i];
      S[i] = c;
    }
  }

    c = S[b+1];
    S[b+1] = S[y];
    S[y] = c;

    return b+1;
}



Measured memory_bytes: 2108
#include <iostream>
#include <string>
using namespace std;
int main(){
    int a,b;
    string op;
    while(true){
        cin >> a >> op >> b;
        if(op=="?"){
            break;
        }else if(op=="+"){
            cout << a+b << endl;
        }else if(op=="-"){
            cout << a-b << endl;
        }else if(op=="*"){
            cout << a*b << endl;
        }else if(op=="/"){
            cout << a/b << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3152
#include<stdio.h>

int main(){
  int a,b,c,d,e,f;
  float x,y;
  while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)!=-1){
    x = (float)(c*e-b*f)/(a*e-d*b);
    y = (float)(c*d-a*f)/(b*d-a*e);
    if(-0.0005<x && x<=0)
      x=0;
    if(-0.0005<y && y<=0)
      y=0;
    printf("%.3f %.3f\n",x,y);
  }
  return 0;
}
  

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

using namespace std;

int main()
{
  int N, A, B, C, X;
  while(cin >> N >> A >> B >> C >> X, N || A || B || C || X){
    int Y[100];
    for(int i = 0; i < N; i++) cin >> Y[i];
    int frame = 0;
    for(int i = 0; i < N; i++){
      while(Y[i] != X){
	frame++;
	if(frame > 10000) break;
	X = (A * X + B) % C;
      };
      frame++;
      X = (A * X + B) % C;
      if(frame > 10001) break;
    }
    if(frame > 10001) cout << -1 << endl;
    else cout << frame-1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int a,b,c;cin >> a >> b >> c;
	if(a < c && c < b)cout << "Yes" << endl;
	else if(b < c && c < a)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main(){
  int A, B;
  cin >> A >> B;
  
  int answer = 0;
  for (int i=A; i<=B; i++){
    int a, b, c, d, e;
    
    a = i % 10;                           //1の位
    b = (i % 100 - i % 10) / 10;          //10の位
    c = (i % 1000 - i % 100) / 100;       //100の位
    d = (i % 10000 - i % 1000) / 1000;    //1,000の位
    e = (i % 100000 - i % 10000) / 10000; //10,000の位
     
    if (a == e && b == d)
      answer++;
  }
  
  cout << answer << endl;
}


Measured memory_bytes: 3608
// AOJ 2494 Sliding GCD
// 2018.3.18 bal4u

#include <stdio.h>

#define MAX   100000
#define DMAX     130	// max 126

int t[MAX+1][DMAX+1], w[MAX+1];
int c[MAX+1];

void divisor_tble(int N)
{
	int i, k, n;
	n = (N>>1)+1;
	for (i = 2; i <= n; i++) {
		for (k = i<<1; k <= N; k += i) t[k][w[k]++] = i;
	}
}

int main()
{
	int  N, W, nw, i, k, lo, hi, one, two;

	scanf("%d%d", &N, &W), nw = N-W+1;
	if (W == 1) {
		putchar('1');
		for (k = 2; k <= nw; k++) putchar(' '), putchar('1');
		putchar('\n');
		return 0;
	}

	divisor_tble(N);

	printf("%d", W);
	one = W, two = 0;
	for (k = 1; k <= W; k++) {
		for (i = 0; i < w[k]; i++) {
			if (++c[t[k][i]] == 2) { two++;	if (t[k][i] <= W) one--; }
		}
	}

	lo = 1, hi = W;
	for (k = 2; k <= nw; k++) {
		for (i = 0; i < w[lo]; i++) {
			if (--c[t[lo][i]] == 1) { two--; if (t[lo][i] > lo && t[lo][i] <= hi) one++; }
		}
		if (c[lo] < 2) one--;
		lo++, hi++;
		for (i = 0; i < w[hi]; i++) {
			if (++c[t[hi][i]] == 2) { two++; if (t[hi][i] >= lo && t[hi][i] <= hi) one--; }
		}
		if (c[hi] < 2) one++;
		printf(" %d", one+two+1);
	}
	putchar('\n');
	return 0;
}


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

int main() {
  long K;
  cin >> K;
  
  long ans=0;
  long temp=0;
  for(long i=1; i<K+1; i++){
  for(long j=1; j<K+1; j++){
  for(long z=1; z<K+1; z++){
    temp=gcd(i,j);
    temp=gcd(temp,z);
    ans += temp;
  }}}
  
  cout << ans << endl;
  return 0;
}


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

int main(){
	int a, b, n;
	cin >> a >> b;
	if (a > b){
		if (a - 1 >= b) n = a + a - 1;
		else n = a + b;
	}
	else {
		if (b - 1 >= a) n = b + b - 1;
		else n = a + b;
	}
		cout << n << endl;
	
}

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

#define MOD 1000000007

using namespace std;

int qmul(int x, int k) {
	if (k == 0) return 1;
	int t = qmul(x, k / 2);
	t = 1LL * t * t % MOD;
	if (k & 1) t = 1LL * t * x % MOD;
	return t;
}

int get(int n, int x) {
	int u = 1, d = 1;
	for (int i = 0; i < x; i++) {
		u = 1LL * u * (n - i) % MOD;
		d = 1LL * d * (i + 1) % MOD;
	}
	d = qmul(d, MOD - 2);
	return 1LL * u * d % MOD;
}

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int ans = (qmul(2, n) + MOD - 1) % MOD;
	int d1 = get(n, a);
	int d2 = get(n, b);
	ans = (ans - d1 + MOD) % MOD;
	ans = (ans - d2 + MOD) % MOD;
	cout << ans << endl;
	return 0;
}

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

#define endl '\n'

int const N = 16;
vector<pair<int, int>> a[N];
vector<int> seq(N);
int n;

int solve(int i, int t){
    seq[i] = t;
    if (i == n){
        vector<int> aux(n+1, -1), nseq = seq;
        queue<int> f;
        for (int j=1; j<=n; j++){
            if (!seq[j]) continue;
            for (pair<int, int> x : a[j]){
                if (x.second == 1 && nseq[x.first] == 0){
                    f.push(x.first);
                    nseq[x.first] = 1;
                }
            }
        }
        while(!f.empty()){
            int top = f.front(); f.pop();
            for (pair<int, int> x : a[top]){
                if (x.second == 1 && nseq[x.first] == 0){
                    f.push(x.first);
                    nseq[x.first] = 1;
                }
            }
        }
        int ans = 0;
        for (int j=1; j<=n; j++){
            if (!nseq[j]) continue;
            ans++;
            for (pair<int, int> x : a[j]){
                if (nseq[x.first] != x.second) return 0;
            }
        }
        return ans;
    } else{
        return max(solve(i+1, 1), solve(i+1, 0));
    }
}

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

    cin >> n;
    for (int i=0; i<n; i++){
        int c; cin >> c;
        while(c--){
            int x,y; cin >> x >> y;
            a[i+1].push_back({x,y});
        }
    }
    cout << solve(0,0) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

ll comb[51][51];

int main(){
    for(int i=0;i<=50;i++){
        for(int j=0;j<=i;j++){
            if(j==0||j==i){
                comb[i][j]=1;
            }else{
                comb[i][j]=comb[i-1][j-1]+comb[i-1][j];
            }
        }
    }
    int n,a,b;
    cin>>n>>a>>b;
    ll v[n];
    for(int i=0;i<n;i++){
        cin>>v[i];
        v[i]=-v[i];
    }
    sort(v,v+n);
    ll ans=0;
    for(int i=0;i<a;i++){
        ans-=v[i];
    }
    ll res=0;
    int ub=upper_bound(v,v+n,v[a-1])-v;
    int lb=lower_bound(v,v+n,v[a-1])-v;
    if(v[0]!=v[a-1]){
        res=comb[ub-lb][a-lb];
    }
    else{
        for(int i=a;i<=min(b,ub);i++){
            res+=comb[ub-lb][i];
        }
    }
    cout<<fixed<<setprecision(25)<<(double)ans/a<<endl;
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n;
long long ans;
int main(){
	cin>>n;
	for (long long i=1;i<=n;i++){
		if (i%3==0){
			continue;
		}
		if (i%5==0){
			continue;
		}
		ans+=i;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3596
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class UnionFind:
    """ Union-Find木 """

    def __init__(self, n):
        self.n = n
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        # 1-indexedのままでOK、その場合は[0]は未使用
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n+1)
        # あるノードを根とする集合に属するノード数
        self.size = [1] * (n+1)
        # あるノードを根とする集合が木かどうか
        self.tree = [True] * (n+1)

    def find(self, x):
        """ 根の検索(グループ番号と言えなくもない) """
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """ 併合 """
        # 根を探す
        x = self.find(x)
        y = self.find(y)

        # 木かどうかの判定用
        if x == y:
            self.tree[x] = False
            return
        if not self.tree[x] or not self.tree[y]:
            self.tree[x] = self.tree[y] = False

        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def is_same(self, x, y):
        """ 同じ集合に属するか判定 """
        return self.find(x) == self.find(y)

    def get_size(self, x=None):
        if x is not None:
            """ あるノードの属する集合のノード数 """
            return self.size[self.find(x)]
        else:
            """ 集合の数 """
            res = set()
            for i in range(self.n+1):
                res.add(self.find(i))
            # グループ0の分を引いて返却
            return len(res) - 1
    
    def is_tree(self, x):
        """ 木かどうかの判定 """
        return self.tree[self.find(x)]

N, M = MAP()
A = LIST()
uf = UnionFind(N)
for i in range(M):
    a, b = MAP()
    uf.union(a, b)

ans = 0
for i, a in enumerate(A):
    # UnionFindが繋がっているなら、スワップを繰り返してその場所に移動できる
    if uf.is_same(i+1, a):
        ans += 1
print(ans)


Measured memory_bytes: 15968
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	mp := map[int]int{}
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		mp[a]++
	}
	sum := 0
	for k, v := range mp {
		if k <= v {
			sum += v - k
		} else {
			sum += v
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 8960
// Lets go to the next level 
// AIM Expert at CF *__* asap 
// Hit A,B,C and if possible D faster and reach Expert
// Remember you were also a novice when you started, 
// hence never be rude to anyone who wants to learn something
// Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts 
// Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure.  
#include "bits/stdc++.h"
//#include <algorithm>
#define ll long long 
#define mod 1000000007
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define lb lower_bound
#define ub upper_bound
#define endll "\n";
#define all(x) (x).begin(), (x).end()
#define forr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define for1(i,a,b) for(int i=a;i<b;i++)
#define for2(i,a,b) for(int i=a;i>=b;i--)
#define for3(i,a,b) for(long long int i=a;i<b;i++)
#define for4(i,a,b) for(long long int i=a;i>=b;i--)
#define pp pair<int,int>
#define ld long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpp vector<pp>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvpp vector<vpp>
#define I insert
#define mem(a,x) memset(a,x,sizeof(a))
#define p_queue(a) priority_queue<a,vector<a>,greater<a>>
using namespace std;
//const int dx[8]={1,0,-1,0,1,1,-1,-1},dy[8]={0,1,0,-1,-1,1,-1,1};
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; 
const int N=2e5+5;
/*vector<bool> p(N+1, true);
void sieve()
{
    p[0] = p[1] = false;
    int i,j;
    for (i = 2; i*i <= N; i++) 
    {
        if (p[i]) 
        {
            for (j = i * i; j <=N; j += i)
            {
                p[j] =false;
            }
        }
    }
}*/
/*int power(int a, int b){
    int res = 1;
    while(b > 0){
        if(b % 2){
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
        b /= 2;
    }
    return res;
}*/
/*int gcd(int a,int b){
    if(a<b) swap(a,b);
    a%=b;
    if(a==0) return b;
    return gcd(b,a);
}*/
/*int lcm(int a,int b){
   return (a*1LL*b)/gcd(a,b);
}*/
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);

        int a;cin>>a;
        cout<<a+a*a+a*a*a<<endll;

    
    return 0;
}

/*

*/




Measured memory_bytes: 3644