akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <iostream>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
typedef vector<long long> vll, vLL;

bool check(const string& s,const string& t){
	int n = s.size();
	int m = t.size();
	for(int i=0;i<=n-m;i++){
		bool ok = true;
		REP(j,m){
			if(s[i+j]!='?' && s[i+j]!=t[j])ok=false;
		}
		if(ok)return true;
	}
	return false;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n,a,x[51],y[51],maxX;
	ll dp[51][5001];
	scanf("%d %d",&n,&a);
	maxX = a;
	REP(i,n){
		scanf("%d",&x[i+1]);
		maxX = max(x[i+1],maxX);
	}
	memset(dp,0,sizeof(dp));

	REP(j,n){
		y[j+1] = x[j+1] - a;
	}
	dp[0][n*maxX]=1;
	for(int j = 1;j<=n;j++){
		REP(t,2*n*maxX + 1){
			dp[j][t] = dp[j-1][t];
			if(t>=y[j] && t-y[j]<=2*n*maxX){
				dp[j][t] += dp[j-1][t-y[j]];
//if(dp[j][t]>0)cout << "if dp[" << j-1 << "][" << t << "]+dp[" << j-1 << "][" << t-y[j] << "]=dp[" << j << "][" << t << "]=" << dp[j][t] << endl;
			}else{
//if(dp[j][t]>0)cout << "else dp[" << j-1 << "][" << t << "]=dp[" << j << "][" << t << "]=" << dp[j][t] << endl;
			}
		}
	}
	cout << dp[n][n*maxX]-1 << endl;

	return 0;
}
/*int A[100100];
long long dp[100][3000];
 
int main3(){
	int n,x,a;
	cin >> n >> x;
 
	for(int i=0;i<n;i++){
		cin >> A[i];
		A[i]-=x;
	}
	
	dp[0][n*x]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=50*50;j++){
			dp[i+1][j]=dp[i][j];
			
			if(j-A[i]>=0)
				dp[i+1][j]+=dp[i][j-A[i]];
	cout << "dp[" << i+1 << "][" << j << "]=" << dp[i+1][j] << endl;
		}
	}
	
	cout << dp[n][n*x]-1 << endl;
	return 0;
}*/

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

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

	n %= 10;

	if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9){
		cout << "hon" << endl;
	}

	else if(n == 0 || n == 1 || n == 6 || n == 8){
		cout << "pon" << endl;
	}

	else{
		cout << "bon" << endl;
	}

}



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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;
typedef pair<int, int> ii;
typedef long long ll;

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

    int x; cin >> x;

    cout << 360/__gcd(x, 360) << '\n';
    
}

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

int get(int ax,int ay,int az,int bx,int by,int bz,int len){
  int res=0,x,y,z;
  vector<P>X,Y,Z;
  X.push_back(P(ax,ax+len));
  X.push_back(P(bx,bx+len));
  Y.push_back(P(ay,ay+len));
  Y.push_back(P(by,by+len));
  Z.push_back(P(az,az+len));
  Z.push_back(P(bz,bz+len));
  sort(X.begin(),X.end());
  sort(Y.begin(),Y.end());
  sort(Z.begin(),Z.end());
  if(X[0].second<X[1].first)return 0;
  if(Y[0].second<Y[1].first)return 0;
  if(Z[0].second<Z[1].first)return 0;
  x=X[0].second-X[1].first;
  y=Y[0].second-Y[1].first;
  z=Z[0].second-Z[1].first;
  res+=x*y*2;
  res+=z*y*2;
  res+=x*z*2;
  return res;
}

int n,k,s,a[2001][2001],ans;
int x[2001],y[2001],z[2001];
vector<int>v[2001];
int root;
bool used[2001];

void dfs(int V,int d,int sum){
  if(d==k){
    if(k>2)sum+=a[root][V];
    ans=max(ans,sum);
    return;
  }
  used[V]=1;
  r(i,v[V].size()){
    int nxt=v[V][i];
    if(used[nxt])continue;
    dfs(nxt,d+1,sum+a[V][nxt]);
  }
  used[V]=0;
}

signed main(){
  while(cin>>n>>k>>s,n){
    memset(a,0,sizeof(a));
    r(i,n)cin>>x[i]>>y[i]>>z[i];
    if(k==1){
      cout<<s*s*6<<endl;
      continue;
    }
    r(i,2001)v[i].clear();
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        int X=get(x[i],y[i],z[i],x[j],y[j],z[j],s);
        if(!X)continue;
        a[i][j]=a[j][i]=X;
        v[i].push_back(j);
        v[j].push_back(i);
      }
    }
    ans=0;
    r(i,n){
      root=i;
      memset(used,0,sizeof(used));
      dfs(i,1,0);
    }
    if(ans)cout<<s*s*k*6-ans<<endl;
    else cout<<-1<<endl;
  }
}


Measured memory_bytes: 34448
def C(N, S):
    n_diff_chars = S.count(".")
    cand_list = [n_diff_chars]
    for c in S:
        if c == ".":
            n_diff_chars -= 1
        else:
            n_diff_chars += 1
        cand_list.append(n_diff_chars)
    print(min(cand_list))


if __name__ == "__main__":
    N = int(input())
    S = input()
    C(N, S)

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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)

int main(){
  string s, t;
  cin >> s >> t;
  int r = 0;
  REP(i, 3) if(s[i] == t[i]) ++r;
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 256
W, H, N = map(int, input().split())
xya = [[int(i) for i in input().split()] for i in range(N)]
Lower_left = [0, 0]
Top_right = [W, H]
ans = 0
for x, y, a in xya:
    if a == 1:
        if x > Lower_left[0]:
            Lower_left[0] = x
    elif a == 2:
        if x < Top_right[0]:
            Top_right[0] = x
    elif a == 3:
        if y > Lower_left[1]:
            Lower_left[1] = y
    elif a == 4:
        if y < Top_right[1]:
            Top_right[1] = y

    if Top_right[0] > Lower_left [0] and Top_right[1] > Lower_left[1]:
        ans = (Top_right[0] - Lower_left[0]) * (Top_right[1] - Lower_left[1])
    else:
        ans = 0

print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
  int a[3][3];
  rep(i,3){
    cin>>a[i][0]>>a[i][1]>>a[i][2];
  }
  int n;
  cin>>n;
  int b[n];
  rep(i,n)cin>>b[i];
  int ans=0;

  rep(i,n){
    rep(j,3){
      rep(k,3){
        if(a[j][k]==b[i])a[j][k]=-1;
      }
    }
  }
  //tate
  rep(i,3){
    if (a[0][i]+a[1][i]+a[2][i]==-3)ans=1;
  }
  //yoko
  rep(i,3){
    if (a[i][0]+a[i][1]+a[i][2]==-3)ans=1;
  }
  //nananme
  if (a[0][0]+a[1][1]+a[2][2]==-3)ans=1;
  if (a[0][2]+a[1][1]+a[2][0]==-3)ans=1;

  if(ans==1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    string s;
    cin>>s;
    int k=s.size();
    int maxn=k;
    for(int i=0;i<k-1;i++)
    {
        if(s[i]!=s[i+1])maxn=min(maxn,max(i+1,k-i-1));
    }
    cout<<maxn<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	if (n.back() == '3')
		cout << "bon" << endl;
	else if (n.back() == '0' || n.back() == '1' || n.back() == '6' || n.back() == '8')
		cout << "pon" << endl;
	else
		cout << "hon" << endl;
}

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

	solve();
}


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

int main() {
	int n;
	cin >> n;
	
	string S;
	cin >> S;
	
	int i = 0, j = n;
	while (i < n && S[i] == '<') ++i;
	while (j > 0 && S[j-1] == '>') --j;
	
	cout << n - min(i, n - j) << endl;
}

Measured memory_bytes: 3348
S=input()
N=len(S)
if N%2==0:
    T0=S[:N//2]+S[:N//2][::-1]
    T1=S[::-1][:N//2]+S[::-1][:N//2][::-1]
else:
    T0=S[:N//2]+S[N//2]+S[:N//2][::-1]
    T1=S[::-1][:N//2]+S[N//2]+S[::-1][:N//2][::-1]
count0=0
count1=0
for n in range(N):
    if S[n]!=T0[n]:
        count0+=1
    if S[n]!=T1[n]:
        count1+=1
print(min(count0,count1))


Measured memory_bytes: 3064
n, k = map(int, input().split())
v = list(map(int, input().split()))

ab_max = min(n, k)
got_max = 0
for ab_i in range(ab_max+1):
    for a_i in range(ab_i+1):
        b_i = ab_i - a_i
        taken = v[:a_i] + v[-1:-(b_i+1):-1]
        taken.sort(reverse=True)
        cd_max = min(k-ab_i, ab_i)
        for cd_i in range(cd_max+1):
            if cd_i == 0:
                continue
            if taken[-1] >= 0:
                break
            else:
                taken.pop()
        got_sum = sum(taken)
        if got_sum > got_max:
            got_max = got_sum

print(got_max)


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

using namespace std;

#define ll long long

#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scd(x) scanf("%lf",&x)

#define pfi(x) printf("%d",x)
#define pfl(x) printf("%lld",x)
#define pfd(x) printf("%lf",x)
#define pfc(x) printf("Case %d: ",x++)
#define ps printf(" ")
#define pn printf("\n")

#define pb(x) push_back(x)
#define ppb(x) pop_back(x)
#define pf(x) push_front(x)
#define ppf(x) pop_front(x)
#define in(x,y) insert({x,y})
#define sv(a) sort(a.begin(),a.end())

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll a, b;
    cin >> a >> b;

    if(a % 3 && b % 3 && (a + b) % 3)
    	printf("Impossible\n");
    else
    	printf("Possible\n");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
int n,a[200010];
int ck[200010];
bool vis[200010];
long long k;
vector<int> ls[200010];
int main() {
	scanf("%d%lld",&n,&k);
	k=n*k;
	int i;
	for(i=0;i<n;i++) {
		scanf("%d",a+i);
		ls[a[i]].push_back(i);
	}
	int cur=0,j;
	vector<pair<int,int> > v;
	while(1) {
		j=lower_bound(all(ls[a[cur]]), cur+1)-ls[a[cur]].begin();
		if(j==sz(ls[a[cur]])) j=ls[a[cur]][0];
		else j=ls[a[cur]][j];
		ll len=j<=cur?(n-cur+j):(j-cur); len++;
		ck[cur]=len;
		//printf("cur:%d, len:%lld, j:%d\n", cur, len);
		cur=(j+1)%n;
		if(ck[cur]) {
			break;
		}
	}
	for(i=0;i!=cur;i=(i+ck[i])%n) {
		if(k<=ck[i]) {
			if(k==0||k==ck[i]) return 0;
			vector<int> ans;
			while(k--) {
				if(vis[a[i]]) {
					while(ans.back()!=a[i]) { 
						vis[ans.back()]=false;
						ans.pop_back();
					}
					ans.pop_back();
					vis[a[i]]=false;
				} else {
					ans.push_back(a[i]);
					vis[a[i]]=true;
				}
				i=(i+1)%n;
			}
			for(auto& it : ans) printf("%d ", ans);
			return 0;
		}
		k-=ck[i];
	}
	ll sum = 0;
	while(1) {
		sum+=ck[i];
		i=(i+ck[i])%n;
		if(i==cur) break;
	}
	k%=sum;
	if(k==0) return 0;
	while(1) {
		for(;;i=(i+ck[i])%n) {
			if(k<=ck[i]) {
				if(k==0||k==ck[i]) return 0;
				vector<int> ans;
				while(k--) {
					if(vis[a[i]]) {
						while(ans.back()!=a[i]) {
							vis[ans.back()]=false;
							ans.pop_back();
						}
						assert(ans.back()==a[i]);
						ans.pop_back();
						vis[a[i]]=false;
					} else {
						ans.push_back(a[i]);
						vis[a[i]]=true;
					}
					i=(i+1)%n;
				}
				for(auto& it : ans) printf("%d ", it);
				return 0;
			}
			k-=ck[i];
		}
	}
	return 0;
}

Measured memory_bytes: 15096
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 200009
using namespace std;
inline ll find_ans(ll n, ll c, ll d)
{
	ll g=__gcd(c,d);
	ll lc=((c*d)/g);
	ll ans=(n/c)+(n/d)-(n/lc);
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans=find_ans(b,c,d);
	ans-=find_ans(a-1,c,d);
	cout<<(b-a+1-ans)<<endl;
	return 0;
}

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

int V, E;
std::vector< int > graph[112345];

const int INF = (1 << 30);

int dfnum[112345];
int parent[112345];

const uint32_t FLAG_ROOT = 0x00000001;

std::vector<int> res;

template<uint32_t flags = 0>
int dfs(int prev, int id, int depth) {
  dfnum[id] = depth;
  parent[id] = prev;
  int lowest = dfnum[id];
  int n = graph[id].size();
  bool isArticulationPoint = false;
  int children_count = 0;
  for(int i = 0; i < n; ++i) {
    int next = graph[id][i];
    if( next == prev ) continue;
    if( dfnum[next] != INF ) {
      lowest = std::min(lowest, dfnum[next]);
      continue;
    }
    int lowest_child = dfs<>(id, next, depth + 1);
    lowest = std::min(lowest, lowest_child);
    if( dfnum[id] <= lowest_child ) {
      isArticulationPoint = true;
    }
    children_count += 1;
  }
  if( flags & FLAG_ROOT ) {
    isArticulationPoint = false;
  }
  if( (flags & FLAG_ROOT ) and children_count >= 2 ) {
    isArticulationPoint = true;
  }
  if( isArticulationPoint ) {
    res.push_back(id);
  }
  //printf("lowest[%d] = %d\n", id, lowest);
  return lowest;  
}


int main() {
  for(int& I : dfnum) I = INF;
  scanf("%d %d", &V, &E);
  for(int i = 0; i < E; ++i) {
    int s, t;
    scanf("%d %d", &s, &t);
    graph[s].push_back(t);
    graph[t].push_back(s);
  }

  dfs<FLAG_ROOT>(-1, 0, 1);

  for(int i = 0; i < V; ++i) {
    //printf("dfnum[%d] : %d\n", i, dfnum[i]);
  }

  std::sort(res.begin(), res.end());
  for(int I : res) {
    printf("%d\n", I);
  }
  
  return 0;
}

Measured memory_bytes: 7836
fds = [int(input()) for i in range(5)]

def ten(min):
    return min + 10-min%10

fds.sort(key=lambda x: x%10)

sum = 0
a = False
for i in range(5):
    if fds[i]%10 == 0:
        sum += fds[i]
    elif a:
        sum += ten(fds[i])
    else:
        sum += fds[i]
        a = True

print(sum)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define all(x) x.begin(), x.end()
using pii = pair<int, int>;
using ll = long long;
using ld = long double;

int N, M;
vector<int> G[100010];

bool vis[100010];
bool col[100010];

void dfs(int n, bool res, int &a, int &b) {
    vis[n] = true;
    if (res == 0)
        a++;
    else
        b++;
    col[n] = res;
    for (auto nxt : G[n]) {
        if (vis[nxt]) {
            if (col[nxt] == res) {
                cout << -1 << endl;
                exit(0);
            }
            continue;
        }
        dfs(nxt, !res, a, b);
    }
}
bitset<100010> dp[2];
bool solve() {
    cin >> N >> M;
    REP(i, M) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    vector<int> A, B, C;
    REP(i, N) {
        if (!vis[i]) {
            int a = 0, b = 0;
            dfs(i, 0, a, b);
            A.push_back(a);
            B.push_back(b);
            C.push_back(abs(a - b));
        }
    }
    int K = A.size();
    dp[0][0] = true;
    REP(i, K) {
        //cerr << A[i] << " " << B[i] << endl;
        int now = i % 2;
        int nxt = (now + 1) % 2;
        dp[nxt] = (dp[now] << A[i]) | (dp[now] << B[i]);
    }
    int mx = 0;
    int sum = N;
    // cout << dp[K % 2] << endl;
    REP(i, N + 1) {
        if (dp[K % 2][i]) {
            mx = max(mx, (N - i) * i);
        }
    }
    cout << mx - M << endl;
    return true;
}

signed main() {
    // while (solve())
    solve();
}


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

int Digit(int x)
{
    int i = 10;
    int digit = 0;

    while(x != 0)
    {
        x = x / i;
        digit++;
    }

    return digit;
}

int main()
{
    int a,b;

    while(cin >> a >> b)
    {
            cout << Digit(a+b) << endl;
    }

    return 0;
}



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

using ll = long long;
using Field = vector<vector<ll>>;
using Graph = vector<vector<ll>>;
using VI = vector<int>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VC = vector<char>;
using PI = pair<int, int>;

#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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; }

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; i++) {
        if (N % i == 0) return false;
    }
    return true;
}

vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            res.push_back(i);
            if (N / i != i) res.push_back(N / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

vector<pair<long long, long long>> prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; a++) {
        if (N % a != 0) continue;
        long long ex = 0;

        while (N % a == 0) {
            ex++;
            N /= a;
        }

        res.push_back({a, ex});
    }

    if (N != 1) res.push_back({N, 1});
    return res;
}


ll N;

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

    cin >> N;
    vector<pair<ll, ll>> pf = prime_factorize(N);

    ll ans = 0;

    for (auto p : pf) {
        ll e = p.second;
        ll tmp = 0, cur = 1;
        while (e >= cur) {
            e -= cur;
            cur++;
            tmp++;
        }
        ans += tmp;
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3640
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int n;
int m;

int main(){
    cin >> n >> m;
    int ans = 1900 * m + (n - m) * 100;
    for(int i = 1;i <= m;i++){
        ans = ans * 2;
    }
    cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 256
n = int(input())
suits = ["S", "H", "C", "D"]
cards = []
for i in suits:
    for j in range(1, 14):
        cards.append([i, str(j)])
for i in range(n):
    s, r = input().split()
    cards.remove([s, r])
for i in cards:
    print(i[0] + " " + i[1])


Measured memory_bytes: 5604
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> g[202020];
int d[202020], dd[202020];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  //c
  cin >> n;
  for (int i = 0; i + 1 < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < n; i++) d[i] = -1;
  d[0] = 0;
  {
    queue<int> que;
    que.push(0);
    while (que.size()) {
      int cur = que.front();
      que.pop();
      for (int nxt : g[cur]) {
        if (d[nxt] != -1) continue;
        d[nxt] = d[cur] + 1;
        que.push(nxt);
      }
    }
  }
  int c = -1, cc = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] > cc) {
      c = i;
      cc = d[i];
    }
  }
  //cerr << c << " " << cc << endl;
  for (int i = 0; i < n; i++) dd[i] = -1;
  dd[c] = 0;
  {
    queue<int> que;
    que.push(c);
    while (que.size()) {
      int cur = que.front();
      que.pop();
      for (int nxt : g[cur]) {
        if (dd[nxt] != -1) continue;
        dd[nxt] = dd[cur] + 1;
        que.push(nxt);
      }
    }
  }
  int siz = 0;
  for (int i = 0; i < n; i++) {
    siz = max(siz, dd[i]);
  }
  siz++;
  vector<int> dp(siz + 1);
  cerr << siz << endl;
  if (siz == 1) {
    cout << "First" << endl;
    return 0;
  }
  if (siz == 2) {
    cout << "Second" << endl;
    return 0;
  }
  if (siz == 3) {
    cout << "First" << endl;
    return 0;
  }
  dp[0] = 0;
  dp[1] = 1;
  dp[2] = 0;
  dp[3] = 1;
  for (int i = 3; i <= siz; i++) {
    if (dp[i - 1] == 0 || dp[i - 2] == 0) {
      dp[i] = 1;
    } else {
      dp[i] = 0;
    }
  }
  cout << (dp[siz] == 0 ? "Second" : "First") << endl;
  return 0;
}


Measured memory_bytes: 14452
N,K=map(x->parse(Int,x),split(readline()))
D=Dict{Int,Int}()
for a=map(x->parse(Int,x),split(readline()))
	D[a]=get(D,a,0)+1
end
A=[v for (k,v)=D]
sort!(A)
ans=0
for i=1:length(A)-K
	ans+=A[i]
end
println(ans)


Measured memory_bytes: 155692
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile

INF = float("inf")


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


from itertools import chain, combinations


def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1))


from collections import defaultdict


def main():
    n = readi()
    shougen = defaultdict(list)
    for i in range(n):
        a = readi()
        for _ in range(a):
            x, y = readi(2)
            x -= 1
            shougen[i].append((x, y))

    ans = 0
    for ps in powerset(range(n)):
        valid = True
        for p in ps:
            for x, y in shougen[p]:
                if y == 1 and x not in ps:
                    valid = False
                if y == 0 and x in ps:
                    valid = False
        if valid:
            ans = max(ans, len(ps))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 43996
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    string A, B; cin >> A >> B;
    if (A.size() > B.size()) { cout << "GREATER" << endl; return 0; }
    if (A.size() < B.size()) { cout << "LESS" << endl; return 0; }
    if (A == B) { cout << "EQUAL" << endl; return 0; }
  
    rep(i, 0, A.size()) {
      if (A[i] > B[i]) { cout << "GREATER" << endl; return 0; }
      if (A[i] < B[i]) { cout << "LESS" << endl; return 0; }
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
   
// g++ -std=c++11 prac.cpp
        
int main(){
    ll b,c,n,x,y,m=-1,k,w,sum=1,ans=0,Max=-1e9,count=0,Min=1e9+1;
    string s,t,u;
    bool ok=true;
    cin >> s;
    b = 0;
    rep(i,s.size()){
        if(s[i]=='W'){
            ans += i-b;
            b++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct blk {
  long long w, s, v;
};


bool mysort(const blk& a, const blk& b) {
  if (a.w < b.w && a.s <= b.s) return true;
  if (a.w == b.w && a.s <= b.s) return true;
  if (a.w < b.w && a.s == b.s) return true;

  auto x = min(a.s, b.s-a.w);
  auto y = min(b.s, a.s-b.w);

  if (x > y) return true;
  // if (x == y && a.s < b.s) return true;
  // if (x == y && a.w < b.w) return true;
  return false;
}

vector<vector < long long > > F( 1000+10, vector<long long>(10000+10, 0));

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

  vector<blk> lst(N);
  long long naxs= 1;
  for (long long i=0; i < N; i++) {
    long long mys;
    cin >> lst[i].w >> mys >> lst[i].v;
    lst[i].s = mys;
    naxs = max(naxs, mys);
  }

  stable_sort(lst.begin(), lst.end(), mysort);
  reverse(lst.begin(), lst.end());
  // for(auto i=0; i<N;i++) printf("%d %d %d\n", lst[i].w, lst[i].s, lst[i].v);
  // F[i, s],  blk 0..i, with solid s

  F[0][ lst[0].s ] = lst[0].v;

  for(long long i=1; i< N; i++) {
    long long is = lst[i].s;
    for(long long s=0; s<=naxs; s++) { F[i][s] = F[i-1][s]; }

    for(long long s=0; s<=is; s++) {
      long long a = 0;

      if (s + lst[i].w <= naxs) { a = F[i-1][s + lst[i].w ]; }

      F[i][s] = max( F[i][s],  a + lst[i].v);
    }

    // s == is
    for(auto s=is; s<=naxs; s++) {
      long long a=0;
      if (s + lst[i].w <= naxs) { a = F[i-1][s + lst[i].w ]; } 
      F[i][is] = max( F[i][is], a  + lst[i].v);
    }
  }

  long long ans = -1;
  for(long long i=0; i< N; i++) {
    for(long long s=0; s<=naxs; s++) ans = max(ans, F[i][s]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 79360
#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;
  cin >> N;
  string C;
  cin >> C;

  int ans = 0;
  int l = 0, r = N - 1;
  while (true) {
    while (l < N) {
      if (C[l] == 'W') break;
      l++;
    }
    while (0 <= r) {
      if (C[r] == 'R') break;
      r--;
    }
    if (r < l) break;
    ans++;
    l++;
    r--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3736
n = int(input())
a = list(map(int,input().split()))

seki = 1
if 0 in a:
  print(0)
else:

  for i in range(n):
    seki*=a[i]
    if seki > 10**18:
      break
  if seki > 10**18:
    print('-1')
  else:
    print(seki)

Measured memory_bytes: 21576
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, M, X;
  cin >> N >> M >> X;
  vector<vector<ll>> book(N, vector<ll>(M + 1));//money , a0...

  for (ll i = 0; i < N; ++i) {
    ll c;
    cin >> c;
    book.at(i).at(0) = c;
    for (ll j = 0; j < M; ++j) {
      ll a;
      cin >> a;
      book.at(i).at(j + 1) = a;
    }
  }
  ll ans = INF;
  for (ll i = 0; i < (1 << N); ++i) {
    vector<ll> point(M, 0);
    ll money = 0;
    for (ll j = 0; j < N; ++j) {
      if (i & (1 << j)) {
        money += book.at(j).at(0);
        for (ll k = 0; k < M; ++k) {
          point.at(k) += book.at(j).at(k + 1);
        }
      }
    }
    bool ok = true;
    for (ll i = 0; i < M; ++i) {
      if (point.at(i) < X) {
        ok = false;
      }
    }
    if (ok) {
      ans = min(ans, money);
    }
  }
  if (ans == INF) {
    cout << -1 << "\n";
  }
  else {
    cout << ans << "\n";
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
template<class T> inline istream& operator >> (istream & c, vector<T> & A) {rep(i, A.size()) c >> A[i];return c;}
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	long long k;
	cin >> s >> k;
	if (s.size() == 1) {
		cout << k / 2 << endl;
		return 0;
	}
	int n = s.size();
	bool ok = false;
	for (int i = 1; i < n; ++i) {
		if (s[i] != s[0]) ok = true;
	}
	if (!ok) {
		cout << k * (long long)s.size() / 2 << endl;
		return 0;
	}
	if (s[0] == s[n - 1]) {
		long long res1 = 1, res2 = 1, res3 = 0;
		for (int i = 0; i < n - 1; ++i) {
			if (s[i] == s[i + 1]) res1++;
			else break;
		}
		for (int i = n - 1; i >= 0; --i) {
			if (s[i] == s[i - 1]) res2++;
			else break;
		}
		for (int i = 0; i < n - 1; ++i) {
			if (s[i] == s[i + 1]) {
				res3++;
				s[i + 1] = '#';
			}
		}
		long long ans = res3 * k - (k - 1) * (res1 / 2 + res2 / 2 - (res1 + res2) / 2);
		cout << ans << endl;
	}
	else {
		long long ans = 0;
		for (int i = 0; i < n; ++i) {
			if (s[i] == s[i + 1]) {
				ans++;
				s[i + 1] = '#';
			}
		}
		ans *= k;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, K; cin >> N >> K;
    vector<int> P(N);
    vector<double> E(N);
    REP(i, 0, N) {
        cin >> P[i];
        E[i] = (double)P[i] * (P[i] + 1) / 2 / P[i];
    }

    double ans = 0;
    REP(i, 0, K) {
        ans += E[i];
    }

    double sum = ans;
    REP(i, 0, N - K) {
        sum = sum - E[i] + E[i + K];
        ans = max(ans, sum);
    }
    cout << fixed << setprecision(15);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;
 
int h,w,n,sr,sc;
string s,t;
vector<int> A,B;
bool flag;
signed main(){
    cin>>h>>w>>n;
    cin>>sr>>sc;
    cin>>s>>t;
  

    FOR(i,0,s.size()){
        switch(s[i]){
            case 'R':A.push_back(1);
                break;
            case 'L':A.push_back(2);
                break;
            case 'D':B.push_back(1);
                break;
            case 'U':B.push_back(2);
                break;
        }
        switch(t[i]){
            case 'R':A.push_back(3);
                break;
            case 'L':A.push_back(4);
                break;
            case 'D':B.push_back(3);
                break;
            case 'U':B.push_back(4);
                break;
        }
    }
    reverse(A.begin(),A.end());
    reverse(B.begin(),B.end());

    flag=true;

    //yoko
    int L=1,R=w;

    FOR(i,0,A.size()){
        switch(A[i]){
            case 1:R--;
                break;
            case 2:L++;
                break;
            case 3:L=max(1,L-1);
                break;
            case 4:R=min(w,R+1);
                break;
        }
        if(R-L<0){
            flag=false;
            break;
        }
    }
    if(sc<L||R<sc){flag=false;}

    int U=1,D=h;
    FOR(i,0,B.size()){
        switch(B[i]){
            case 1:D--;
                break;
            case 2:U++;
                break;
            case 3:U=max(1,U-1);
                break;
            case 4:D=min(h,D+1);
                break;
        }
        if(D-U<0){
            flag=false;
            break;
        }
    }
    if(sr<U||D<sr){flag=false;}

    if(flag)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;





 
}

Measured memory_bytes: 2428
import std.stdio,std.string,std.conv,std.algorithm;

int main()
{
	string s;
	double Max,Min;
	bool flag = true;
	while((s = readln.chomp).length != 0)
	{
		double a = s.to!double;
		if(flag)
		{
			Max = a;
			Min = a;
			flag = false;
		}
		else
		{
			Max = max(Max,a);
			Min = min(Min,a);
		}
	}
	writeln(Max-Min);
	return 0;
}

Measured memory_bytes: 1128
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

pair<int, int> next_time() {
	int sh, sm, eh, em;
	scanf("%d:%d-%d:%d", &sh, &sm, &eh, &em);
	return make_pair(sh * 60 + sm, eh * 60 + em);
}

vector<pair<int, int>> input_schedule() {
	int n;
	scanf("%d", &n);
	vector<pair<int, int>> res(n);
	for(auto &e : res) e = next_time();
	return res;
}

bool contain(const pair<int, int> &a, const pair<int, int> &b) {
	return a.first <= b.first && b.second <= a.second;
}

int main() {
	const auto classes = input_schedule();

	int n;
	scanf("%d", &n);
	vector<vector<pair<int, int>>> students(n);
	for(auto &e : students) e = input_schedule();

	int m;
	scanf("%d", &m);
	vector<vector<pair<int, int>>> teachers(m);
	for(auto &e : teachers) e = input_schedule();

	int res = 0;
	for(const auto &c : classes) {
		int cnt = 0;
		for(const auto &s : students) {
			for(const auto &e : s) {
				if(contain(e, c)) {
					++cnt;
				}
			}
		}

		for(const auto &t : teachers) {
			for(const auto &e : t) {
				if(cnt && contain(e, c)) {
					++res;
					--cnt;
				}
			}
		}
	}

	printf("%d\n", res);

	return EXIT_SUCCESS;
}

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

Measured memory_bytes: 3640
while True:
    n,x = map(int,input().split())
    if n == x == 0:
        exit()
    cnt = 0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k == x:
                    cnt += 1
    print(cnt)


Measured memory_bytes: 5596
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
ll po(ll a, ll b){
    ll res = 1;
    while(b){
        if(b & 1) res = res * a;
        a = a * a;
        b >>= 1LL;
    }
    return res;
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, p;
    cin >> n >> p;
    vector<int> a(n);
    int o = 0, e = 0;
    for(auto &x : a){
        cin >> x;
        if(x & 1) o++;
        else e++;
    }
    if(p == 0){
        if(o > 0)
            cout << po(2, n - 1);
        else{
            cout << po(2, n);
        }
    }else{
        if(o > 0)
            cout << po(2, n - 1);
        else{
            cout << 0;
        }
    }
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/


Measured memory_bytes: 256
use std::io;

fn main() {
    let nk = read_vec::<usize>();
    let n = nk[0];
    let k = nk[1];
    let mut w = Vec::new();

    for _ in 0..n {
        w.push(read::<i32>());
    }
    println!("{}", search(&w, k as i32));
}

// 2分探索 O(logn)
// ソート済みのデータを入力
pub fn search(a: &[i32], key: i32) -> i32 {
    // 最大積載量Pの最小値は最大荷物の重さ
    let mut min = *a.clone().into_iter().max().unwrap();
    let mut max = a.clone().iter().sum::<i32>();
    let mut ans = max;

    while min < max {
        let mid: i32 = (min + max) / 2;
        let p = need_track(&a, &mid);
        if p > key {
            min = mid + 1;
        } else {
            max = mid;
            ans = if min > max { min } else { max };
        }
    }
    ans
}

// 何台のトラックが必要か数える
fn need_track(a: &[i32], p: &i32) -> i32 {
    let mut count = 1;
    let mut shipment= 0;
    for &num in a {
        shipment += num;
        if shipment > *p {
            count += 1;
            shipment = num;
        }
    }
    count
}

/// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}

/// 標準入力から一行を読み取り、指定の型に変換する関数
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}



Measured memory_bytes: 5052
#include  <cstdio>
#include <algorithm>
using namespace std;
long long x,y;
int main()
{
	scanf("%lld%lld",&x,&y);
	for(int i=1;;i++)
	{
		x*=2;
		if(x>y)
		{
			printf("%d",i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 128
a[20],z=1e4,n,m;*p;main(i){for(;scanf("%d%d",&m,&n)*n;puts(a))for(*a=1;~n--;)for(i=18;i;*p=~n?p[1]+=*p*m/z,*p*m%z:*p&&!printf("%d%.3s",*p,51-i*3+"MtsFksNytAsgGgsGokSaiSeiKanKo\0JouJo\0GaiKeiChoOkuMan"))p=a+--i;}

Measured memory_bytes: 616
#include<stdio.h>
#include<math.h>
int main(void){
  int nDay,mNum;
  int a[10000];
  int i;


  scanf("%d %d",&nDay,&mNum);
  for(i=0;i<mNum;i++){
    scanf("%d ",&a[i]); 
  }
  
  
  for(i=0;i<mNum;i++){
    nDay = nDay - a[i];
  }
  
  
  if(nDay>=0){
    printf("%d",nDay);
  }
  else{
    printf("-1");
  }
  
  return 0;
}


Measured memory_bytes: 1748
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        vector<double> P(n);
        FOR(i,0,n)
            cin >> P[i];
        map<int,double> dp[2];
        int cur = 0, nxt = 1;
        dp[cur][0] = 1;
        FOR(i,0,n) {
            dp[nxt].clear();
            FOR_ALL(x,dp[cur]) {
                const int k = x->first;
                const double v = x->second;
                dp[nxt][k+1] += v*P[i];
                dp[nxt][k] += v*(1-P[i]);
            }
            swap(cur,nxt);
        }
        double ans = 0;
        FOR_ALL(x,dp[cur]) {
            const int k = x->first;
            if (k > n-k)
                ans += x->second;
        }
        printf("%.10f\n",ans);
    }
    return 0;
}


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

using namespace std;


int main(int argc, char *argv[])
{
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    
    int Z = 0;
    int min_cost = A * X + B * Y;
    
    while (X > 0 || Y > 0) {
        min_cost = min(min_cost, A * X + B * Y + Z * C);
        X = max(X - 1, 0);
        Y = max(Y - 1, 0);
        Z += 2;
    }
    
    min_cost = min(min_cost, A * X + B * Y + Z * C);
    
    cout << min_cost << endl;
    
    return 0;
}


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

using namespace std;

#define int long long
#define pb push_back

const int inf = 1e18 + 123, N = 1e3 + 5;
int n, rx[N], ry[N], rc[N], bx[N], by[N], bc[N];

struct MaxFlow {
    int nVer, src, snk;
    struct Edge {
        int u, v, cap, f, cost;
        Edge (int u = 0, int v = 0, int cap = 0, int f = 0, int cost = 0) : u(u), v(v), cap(cap), f(f), cost(cost) {}
    };
    vector<Edge> edge;
    vector< vector<int> > gr;
    vector<int> d, par, idEdge;
    MaxFlow (int nVer = 0, int src = 0, int snk = 0) : nVer(nVer), src(src), snk(snk) {
        gr.assign(nVer + 5, vector<int>() );
        edge.clear();
    }
    void addEdge (int u, int v, int cap, int cost) {
        gr[u].pb(edge.size() ); edge.pb(Edge(u, v, cap, 0, cost) );
        gr[v].pb(edge.size() ); edge.pb(Edge(v, u, 0, 0, -cost) );
    }
    bool spfa() {
        d.assign(nVer + 5, inf); d[src] = 0;
        par.assign(nVer + 5, -1); idEdge.assign(nVer + 5, -1);
        vector<bool> inQ(nVer + 5, 0);
        queue<int> q; q.push(src); inQ[src] = 1;
        while (!q.empty() ) {
            int u = q.front(); q.pop(); inQ[u] = 0;
            for (int id : gr[u]) {
                if (edge[id].f < edge[id].cap && d[ edge[id].v ] > d[u] + edge[id].cost) {
                    d[ edge[id].v ] = d[u] + edge[id].cost;
                    if (!inQ[ edge[id].v ]) q.push(edge[id].v), inQ[ edge[id].v ] = 1;
                    par[ edge[id].v ] = u;
                    idEdge[ edge[id].v ] = id;
                }
            }
        }
        return d[snk] != inf;
    }
    void update () {
        int flow = inf;
        for (int u = snk; u != src; u = par[u]) {
            flow = min(flow, edge[ idEdge[u] ].cap - edge[ idEdge[u] ].f);
        }
        for (int u = snk; u != src; u = par[u]) {
            edge[ idEdge[u] ].f += flow;
            edge[ idEdge[u] ^ 1 ].f -= flow;
        }
    }
    int solve () {
        while (spfa() ) update();
        int ret = 0;
        for (auto _ : edge) if (_.f > 0) ret += _.f * _.cost;
        return ret;
    }
};

int32_t main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> rx[i] >> ry[i] >> rc[i];
    for (int i = 1; i <= n; ++i) cin >> bx[i] >> by[i] >> bc[i];

    MaxFlow mf(2 * n + 6, 0, 2 * n + 1);
    for (int i = 1; i <= n; ++i) {
        mf.addEdge(mf.src, i, rc[i], 0);
        mf.addEdge(i + n, mf.snk, bc[i], 0);
        mf.addEdge(i, 2 * n + 2, rc[i], - rx[i] - ry[i]);
        mf.addEdge(2 * n + 2, i + n, bc[i], bx[i] + by[i]);
        mf.addEdge(i, 2 * n + 3, rc[i], - rx[i] + ry[i]);
        mf.addEdge(2 * n + 3, i + n, bc[i], bx[i] - by[i]);
        mf.addEdge(i, 2 * n + 4, rc[i], rx[i] - ry[i]);
        mf.addEdge(2 * n + 4, i + n, bc[i], - bx[i] + by[i]);
        mf.addEdge(i, 2 * n + 5, rc[i], rx[i] + ry[i]);
        mf.addEdge(2 * n + 5, i + n, bc[i], - bx[i] - by[i]);
    }

    cout << - mf.solve();

    return 0;
}


Measured memory_bytes: 1812
s=input()
n=len(s)
d=[0]
d10=[0,1,10]
for i in range(n):
    d10.append(d10[-1]*10%2019)
for i in range(1,n+1):
    d.append((d[-1]+int(s[-i])*d10[i])%2019)
import collections
c=collections.Counter(d)
ans=0
for i in c.values():
    ans+=i*(i-1)//2
print(ans)

Measured memory_bytes: 81620
#include<stdio.h>

unsigned int DifferentCount(char* a_s, char* a_t);

int main(void) {
	//文字列の定義
	static char s[200001],t[200001];
	
	//文字列の入力
	scanf("%s", s);
	scanf("%s", t);
	//文字列の異なる文字の数を出力
	printf("\n%d\n", DifferentCount(s, t));

	return 0;
}

/******
*　2つの文字列の異なる文字の数を数える関数
*　char* a_s、char* a_t　入力された2つの文字列
*/
unsigned int DifferentCount(char* a_s, char* a_t) {
	unsigned int i;
	unsigned count = 0;			//異なる文字の数を数える変数

	for (i = 0;i <= 200001;i++) {
		//文字が異なる場合カウントアップ
		if ((a_s[i] != a_t[i]) && (a_s[i] != 0x00) && (a_t[i] != 0x00)) {
			count++;
		}
		//文字列に終点コードを見つけた場合終了
		else if ((a_s[i] == 0x00) && (a_t[i] == 0x00)) {
			break;
		}
		else {}
	}
	return(count);
}

Measured memory_bytes: 2452
#coding:utf-8
N,M=map(int,raw_input().split())
A=map(int,raw_input().split())
dp=[-1 for i in range(10**4 + 1)]
Cost={(i+1):v for i,v in enumerate([2,5,5,4,5,6,3,7,6])}

for a in A:
    dp[Cost[a]] = max(dp[Cost[a]], a)

for n in range(2, N+1):
    for a in A:
        if n-Cost[a]>=0 and dp[n-Cost[a]] != -1:
            dp[n] = max(dp[n], dp[n-Cost[a]] * 10 + a)
print(dp[n])

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

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

vector<bool> visited(105);
vector<vector<int>> edge(105);
bool dfs(int cur, int par) {
    // if a cycle doesn't exist, return true
    visited[cur] = true;
    bool ic = false;
    if (edge[cur].size() == 0) {
        return true;
    } else {
        for (int i = 0; i < edge[cur].size(); i++) {
            if (edge[cur][i] == par) {
                continue;
            }
            if (visited[edge[cur][i]]) {
                ic = true;
                break;
            } else {
                visited[edge[cur][i]] = true;
            }
            if (!dfs(edge[cur][i], cur)) {
                ic = true;
            }
        }
        if (ic) {
            return false;
        } else {
            return true;
        }
    }
}
int ctoi(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    return 0;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % 2019;
    } else {
        return modpow(m, n - 1) * m % 2019;
    }
}
int main() {
    string s;
    cin >> s;
    map<long long int, int> cnt;
    long long int acc = 0, ans = 0;
    reverse(s.begin(), s.end());
    cnt[0]++;
    REP(i, s.size()) {
        acc += (ctoi(s[i]) * modpow(10, i)) % 2019;
        acc %= 2019;
        ans += cnt[acc];
        cnt[acc]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672