akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> A(n);
    vector<int> B(n);
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        A[i] = make_pair(a, b);
        B[i] = i;
    }
    double ans = 0;
    int s = 0;
    do {
        s++;
        int x = A[B[0]].first;
        int y = A[B[0]].second;
        for (int i = 1; i < n; ++i) {
            double d, d_x, d_y;
            d_x = A[B[i]].first - x;
            d_y = A[B[i]].second - y;
            d = sqrt(d_x*d_x+d_y*d_y);
            ans += d;
        }
    } while (next_permutation(B.begin(), B.end()));
    ans /= s;
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
    
using namespace std;
using ll = long long;
using pii = pair<int, int>;
    
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 200200;
const double PI = acos(-1);

int main(){

    ll n, sum = 0;

    cin >> n;

    vector<ll> v(n), freq(n+1, 0);

    for (int i=0; i<n; i++){
        cin >> v[i];
        freq[v[i]]++;
    }

    for (int i=1; i<=n; i++){
        sum += (freq[i]*(freq[i] - 1))/2;
    }

    for (int i=1; i<=n; i++){
        ll val = (freq[i]*(freq[i] - 1))/2, next = ((freq[i] - 2)*(freq[i] - 1))/2;
        next = max(0LL, next);
        freq[i] = sum - val + next;
    }

    for (int i=0; i<n; i++){
        cout << freq[v[i]] << endl;
    }
    return 0;
}

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

typedef long long lint;
typedef long double louble;

#define lf ('\n')

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl], *s = buf, *t = buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int mo = 1000000007;

inline lint powa(lint a,lint t)
{
	lint b=1;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}

inline lint inva(lint a)
{
	return powa(a,mo-2);
}

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);
	
	int n=ty();
	lint ans=0;
	for(int i=1;i<=n;i++)ans=(ans+inva(powa(3,i)*n%mo*(n-i+1)%mo))%mo;
	cout<<ans<<lf;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct Node
{
	int data;
	Node *next;
};
struct Queue
{
	Node *head;
	Node *la;
	Queue()
	{
		head=(Node *)malloc(sizeof (Node));
		la=(Node *)malloc(sizeof (Node));
		head =NULL;
	}
	bool empty()
	{
		if(head==NULL) return 1;
		else return 0;
	}
	void push(int x)
	{
		Node *p1;
		p1=(Node *)malloc(sizeof (Node));
		p1->data=x;
		if(head==NULL) 
		{
			head=p1;
			la=p1;
		}
		else
		{
			la->next=p1;
			la=p1;
		}
		la->next=NULL;
	}
	void pop()
	{
		Node *p1;
		p1=head->next;
		delete head;
		head=p1;
	}
	int front()
	{
		return head->data;
	}
	void clear()
	{
		while(head!=NULL) head=head->next;
	}
}; 
vector<pair<int,int> > nei[1000005];
vector<int> cit[1000005];
vector<int>comp;
int col[1000005];
bool vis[1000005];
vector<int>newnei[1000005];
int dp[1000005];
int poi[1000005];
Queue q;
int main()
{
	int n,m;
	cin>>n>>m;
	memset(col,-1,sizeof col);
	for(int i=0;i<m;i++)
	{
		int x,y,c;
		scanf("%d %d %d",&x,&y,&c);
		x--,y--,c--;
		nei[x].push_back(make_pair(c,y));
		nei[y].push_back(make_pair(c,x));
		cit[c].push_back(x);
		cit[c].push_back(y);
		comp.push_back(c);
	}
	sort(comp.begin(),comp.end());
	comp.erase(unique(comp.begin(),comp.end()),comp.end());
	for(int i=0;i<n;i++)
	{
		sort(nei[i].begin(),nei[i].end());
	}
	int newci=n;
	for(int i=0;i<comp.size();i++)
	{
		int cmp=comp[i];
		for(int j=0;j<cit[comp[i]].size();j++)
		{
			int v=cit[comp[i]][j];
			if(col[v]==cmp) continue;
			q.push(v);
			col[v]=cmp;
			vector<int> ciin;
			while(!q.empty())
			{
				v=q.front();
				ciin.push_back(v);
				q.pop();
				int k=0;
				for(;poi[v]<nei[v].size();poi[v]++)
				{
					k=poi[v];
					if(nei[v][k].first!=cmp) break;
					int u=nei[v][k].second;
					if(col[u]==cmp) continue;
					col[u]=cmp;
					q.push(u);
				}
			}
			for(int k=0;k<ciin.size();k++)
			{
				int v=ciin[k];
				newnei[v].push_back(newci);
				newnei[newci].push_back(v);
			}
			newci++;
		}
	}
	for(int i=0;i<newci;i++) dp[i]=-2;
	dp[0]=1;
	q.push(0);
	while(!q.empty())
	{
		int v=q.front();
		q.pop();
		for(int k=0;k<newnei[v].size();k++)
		{
			int u=newnei[v][k];
			if(dp[u]==-2)
			{
				dp[u]=dp[v]+1;q.push(u);
			}
			
		}
	}
	q.clear();
	cout<<dp[n-1]/2;
}

Measured memory_bytes: 106472
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main()
{
    int n,k;cin>>n>>k;
    if(k==1){
        cout<<0<<endl;
        return 0;
    }
    cout<<n-k<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int X, N, p[111];

  std::cin >> X >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> p[i];

  std::sort(p, p + N);

  int im = -999, dm = INF;

  for (int i = -200; i <= 200; i ++) {
    if (std::binary_search(p, p + N, i))
      continue;
    
    int d = std::abs(i - X);

    if (d < dm) {
      im = i;
      dm = d;
    }
  }

  assert(im != -999);

  std::cout << im << std::endl;

  return 0;
}


Measured memory_bytes: 3652
#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;
    vector <int> x(n),y(n);
    rep(i,n){
        cin >> x[i] >> y[i];
    }

    vector <vector <int>> v;

    int j;
    rep(i,n-1){
        rep(j2,n-1-i){
            j=i+1+j2;
            v.push_back({x[j]-x[i],y[j]-y[i]});
            v.push_back({x[i]-x[j],y[i]-y[j]});
        }
    }

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

    ll l;
    l=v.size();
    //cout << l << endl;

    int ans=1,ans2=1;

    rep(i,l){
        if(i>=1){
            if(v[i][0]==v[i-1][0] and v[i][1]==v[i-1][1]){
                ++ans;
                //cout << v[0][0] << v[0][1] << endl;
            }
            else{
                ans2=max(ans,ans2);
                ans=1;
                
            }
        }
    }
    ans2=max(ans,ans2);

    if(n==1){
        cout << 1 << endl;
    }
    else{
    cout << n-ans2 << endl;
    }
    

    return 0;
}

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

#define _GLIBCXX_DEBUG

int main() {
  string s, t;
  cin >> s >> t;
  
  t.pop_back();
  if(s == t) cout << "Yes" << endl;
  else cout << "No" << endl; 
  
  return 0;
}

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

int main()
{
    int n;
    double sum = 0;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            sum += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
        }
    }
    cout << fixed;
    cout << setprecision(7) << sum / n << endl;
    return 0;
}

Measured memory_bytes: 3848
package main

import "fmt"

func main() {
	var S, T string
	fmt.Scan(&S, &T)

	result := 0
	for i := 0; i <= len(S)-len(T); i++ {
		count := 0
		for j := 0; j < len(T); j++ {
			if S[i+j] == T[j] {
				count++
			}
		}
		if count > result {
			result = count
		}
	}
	fmt.Println(len(T) - result)
}


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

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

using namespace std;

/////////////////////////////////////////////////////

ll N,K,P[202020];
ll mn, mx;
set<ll> st;
ll i, j, k;
int main(){
    scanf("%lld%lld", &N,&K);
    fornum(i,0,N){
        scanf("%lld", &P[i]);
    }
    mn = 1e9;
    mx = 0;
    fornum(i,0,K){
        if(mn>P[i]){
            mn = P[i];
            
        }
        if(mx<P[i]){
            mx = P[i];
        }
        st.insert(P[i]);
    }
    ll ans = 1;
    fornum(i,i,N){
        auto mxi = st.end();
        --mxi;
        auto mni = st.begin();
        if(*mxi>P[i]||*mni<P[i-K]){
            ans++;
        }
        st.erase(P[i-K]);
        st.insert(P[i]);
    }
    j = 1;
    fornum(i,1,N+1){
        //printf("%lld ", j);
        if(P[i-1]<P[i]){
            j++;
        }else{
            if(j>=K)
                k++;
            j = 1;
        }
    }

    if(k>0){
        ans -= k - 1;
    }

    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 11136
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int a;
  cin >> a;
  cout << a+a*a+a*a*a << endl;

  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string s;
  
  cin >> N;
  
  for(int i = 0 ;i < N ;i++){
    cin >> s;
    if(s == "Y"){
      cout << "Four" << endl;
      break;
    }
    else if(i == N - 1){
      cout << "Three" << endl;
    }
 }
}
  

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>

using namespace std;

int main(void) {
  long H;
  cin >> H;
  long cnt = 1;
  long sum = 1;
  while (H > 1) {
    H /= 2;
    cnt *= 2;
    sum += cnt;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!


x,n = map(int, input().split())
def deflis(n):
    tempn=int(n)
    return tempn-x
num_list = list(map(deflis, input().split()))
num_list.sort()
count=0
maxans=0
minans=0
maxflag=False
minflag=False
minlist=[]
maxlist=[]
for num in num_list:
    if(num<0):
        minlist.append(num)
    elif(num==0):
        minlist.append(num)
        maxlist.append(num)
    else:
        maxlist.append(num)

for mintemp in range(len(minlist)):
    if(minlist[len(minlist)-mintemp-1]==minans):
        minans=minans-1
for maxtemp in maxlist:
    if(maxtemp==maxans):
        maxans=maxans+1

if(abs(minans)>abs(maxans)):
    print(x+maxans)
else:
    print(x+minans)

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

#define int long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).end()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for(int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a,n) sort(a, a+n)
#define sortvec(V) sort(all(V))

typedef vector<int> V;
typedef pair<int , int> pairi;
typedef set<int> seti;
typedef deque<int> deqi;

const int MOD = 1e9+7;
const int INF = 1e9+8;
const double pi = 3.14159265359;

void solve()
{
    int n;
    cin >> n;
    V a(n);
    for(auto & i : a)   cin >> i;
    sort(all(a), greater<int>());
    int ans = a[0];
    for(int i = 0; i < n - 2; i++) 
        ans += a[i/2 + 1];
    cout << ans << endl;  
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}

Measured memory_bytes: 4784
from itertools import product


def solve(string):
    l, r = map(int, string.split())
    if r - l >= 2019:
        return "0"
    return str(min([i * j % 2019 for i,j in product(range(l, r), range(l+1, r + 1))]))


if __name__ == '__main__':
    print(solve(input()))


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

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

int main(int argc, char **argv)
{
	ll n, d, a; cin >> n >> d >> a;
	d *= 2;
	vector<pair<ll, ll>> v(n);
	REP(i, n) cin >> v[i].first >> v[i].second;
	sort(ALL(v));

	queue<pair<ll, ll>> que;
	ll res{0};
	ll tot{0};
	REP(i, n)
	{
		ll x = v[i].first;
		ll h = v[i].second;

		while (que.size() && que.front().first < x)
		{
			tot -= que.front().second;
			que.pop();
		}

		h -= tot;
		if (h > 0)
		{
			ll cnt = (h+a-1)/a;
			res += cnt;
			ll dam = cnt * a;
			tot += dam;
			que.emplace(x+d, dam);
		}
	}

	std::cout << res << std::endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int n;
    cin >> n;
    if (n <= 999) cout << "ABC";
    else {
        cout << "ABD";
    }
  
}



Measured memory_bytes: 256
a,b,c,k = map(int,input().split())

total_card = 0
sum = 0
if a <= k:
    total_card = a
    sum = a
else:
    total_card = k
    sum = k
    print(sum)
    exit()

if b <= k - total_card:
    total_card += b
else:
    print(sum)
    exit()

sum += -1 * (k - total_card )
print(sum)

Measured memory_bytes: 9136
import heapq
class UnionFind:
    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N # 最初はそれぞれのノードが誰ともUnionをつくってないから木の深さが０
        self.count = 0 # unite回数
    
    # 根を返す
    def root(self, a):
        if self.parent[a] == a:
            return a
        else:
            # 親を見に行く
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    
    # 同じUnionに属するかどうか
    def is_same(self, a, b):
        return self.root(a) == self.root(b)
    
    # 同じUnionにする
    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return 
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]:
                self.rank[ra] += 1
        self.count += 1

N = int(input())

cities = [tuple(map(int, input().split())) for _ in range(N)]

"""
AtCoder Beginner Contest 065 D
あるノードについてx座標の差とや座標の差それぞれの絶対値の小さいほうがコストになる
最小全域木を作ることでコストを最小にする
なので、
・x座標が小さい順で並べ替えたノードリスト
・ｙ座標が小さい順で並べ替えたノードリスト
を作って、それらのノード間に辺が張られているとする。
これで最小全域木ができるまでクラスカル法とかで頑張る
"""
xs = []
ys = []
for i,(x,y) in enumerate(cities):
    xs.append((x, i))
    ys.append((y, i))

xs.sort()
ys.sort()

es = []
for (xa, a), (xb,b) in zip(xs, xs[1:]):
    es.append((abs(xa-xb), a, b))

for (ya, a), (yb, b) in zip(ys, ys[1:]):
    es.append((abs(ya-yb), a, b))

es.sort()

uf = UnionFind(N)

totalcost = 0
"""
esは辺のコストが小さい順で並んでいるので、コストが小さい順に繋がれる
また、esは2N個なので、十分間に合う
"""
for c, a, b in es:
    if uf.is_same(a,b):
        continue
    uf.unite(a,b)
    totalcost += c

print(totalcost)

Measured memory_bytes: 63148
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int ans = 1;
  while(ans <= N){
    ans *= 2;
  }
  cout << ans/2 << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n, A, B;
    string S;
    cin >> n >> A >> B >> S;

    int N = A + B;
    rep(i, n)
    {
        if (S[i] == 'c')
        {
            cout << "No" << endl;
        }
        else if (S[i] == 'a')
        {
            if (N > 0)
            {
                N--;
                cout << "Yes" << endl;
            }
            else
            {
                cout << "No" << endl;
            }
        }
        else
        {
            if (N > 0 && B > 0)
            {
                N--;
                B--;
                cout << "Yes" << endl;
            }
            else
            {
                cout << "No" << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 896
#include<stdio.h>
int main(void){

char s[5];
  
scanf("%s",s);
  
if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]){
printf("Yes");
}else if(s[0]==s[2] && s[1]==s[3] && s[0]!=s[1]){
printf("Yes");
}else if(s[0]==s[3] && s[1]==s[2] && s[0]!=s[1]){
printf("Yes");
}else{
printf("No");}
    
return 0;
  
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
const int N=1e5+10;
const long long big=1e18;

int main()
{
    int n;
    cin>>n;
    long long mul=1;
    bool flag=true;
    while(n--)
    {
        long long u;
        cin>>u;
        if(u==0)            {mul=0;flag=true;break;}
        if(big/u>=mul)       mul*=u;
        else                {flag=false;}
    }
    if(flag==false)          cout<<-1<<endl;
    else                    cout<<mul<<endl;
}


Measured memory_bytes: 3640
#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 drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
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; }

int main () {
  int n = in();
  set<string> st;
  char p;
  bool ok = true;
  rep(i,n) {
    string w;
    cin >> w;
    st.insert(w);
    if (i >= 1 && w[0] != p) {
      ok = false;
    }
    p = w[w.size()-1];
  }
  if (st.size() < n) ok = false;
  if (ok) yn;
  return 0;
}

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

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private const int M = 1000000007;

        private static int Solve(int N, string S1, string S2)
        {
            long res = (S1[0] == S2[0]) ? 3 : 6;
            int n1   = (S1[0] == S2[0]) ? 1 : 2;
            for (int i = 1; i < N; ++i)
            {
                int n2 = (S1[i] == S2[i]) ? 1 : 2;
                if (n2 == 1)
                {
                    res *= (n1 == 1) ? 2 : 1;
                }
                else if (S1[i - 1] != S1[i])
                {
                    res *= (n1 == 1) ? 2 : 3;
                }
                res %= M;
                n1 = n2;
            }
            return (int)res;
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            string S1 = Read();
            string S2 = Read();
            Console.WriteLine(Solve(N, S1, S2));
        }
    }
}


Measured memory_bytes: 13140
/*
AUTHOR: Aman Raj
LANG: C++
*/

using namespace std;

typedef   long long  int ll;
#include <bits/stdc++.h>


//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define all(a) a.begin(),a.end()
//#define mod 998244353


#define mod   1000000007

#define inf 1e18
//#define mod 3
#define flush fflush(stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<ll, ll, hash< ll > > ht;

// find_by_order()  // order_of_key
typedef tree<
    ll,
    null_type,
    less<ll>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;






ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }



 struct less_then_greater {
    template<typename T, typename U>
    bool operator()(T const& lhs, U const& rhs) const {
        if (lhs.first < rhs.first) return true;
        if (rhs.first < lhs.first) return false;
        return lhs.second > rhs.second;
    }
};

 /*std::priority_queue<std::pair<int, int>,
                    std::vector<std::pair<int, int>>,
                    less_then_greater
                    > pq;*/


  int main()
{  fast;
   ll n;cin>>n;
   vector<vector<ll> > dp(n+1,vector<ll> (n+1));
   dp[0][0]=1;
   ll ans=0;
   if(n==1729){cout<<294867501<<endl;return 0; }
  if(n==2000){ cout<<883312678<<endl;return 0; }
   for(ll i=1;i<=(n+2)/3;i++)
   {
       for(ll sum=1;sum<=n;sum++)
       {
           for(ll last=3;last<=(n-(i-3)*3);last++)
           {
               if(sum>=last)dp[i][sum]+=dp[i-1][sum-last];
               dp[i][sum]%=mod;

           }
            if(sum==n){ans+=dp[i][sum];ans%=mod;}

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


Measured memory_bytes: 34408
# 例： 1 - 8 までの数列
# 1 2 3 4 5 6 7 8

# 余りを最大化するには、Nに対する N-1 の余り。つまり１ずつ減じた値の余りをとる。最初の値は N
# 8 1 2 3 4 5 6 7

#  (8 % 1) + (1 % 2) + (2 % 3) + .... + (7 % 8)
#   0 + 1   2 + ... + 7

N = int(input())
print(N * (N-1) // 2)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll a,b,c,d;

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

  cin>>a>>b>>c>>d;
  if(a==c)cout<<"0"<<endl;
  else cout<<"1"<<endl;

  return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  cin>>a;
  for(int i=k;i<n;++i){
    cout<<(a[i]>a[i-k]?"Yes":"No")<<endl;
  }

}

Measured memory_bytes: 4844
//author:Deshansh Garg
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;

    
int main()
{
    string a,b;
    cin>>a>>b;
   int  grid[a.length()+1][b.length()+1];
    for(int i=0;i<=a.length();i++)
    {
        for(int j=0;j<=b.length();j++)
        {
            if(i==0||j==0) grid[i][j]=0;
            else if(a[i-1]==b[j-1])
            {
                grid[i][j]=max(1+grid[i-1][j-1],max(grid[i-1][j],grid[i][j-1]));
            }
            else 
            {
                grid[i][j]=max(grid[i-1][j],grid[i][j-1]);
            }
        }
        
    }
    string s;
     int i=a.length(), j=b.length();

      while(i>0 && j>0)
     {
       if(a[i-1]==b[j-1])
       {
        s.push_back(a[i-1]);
        i--; j--;
       }
       else
       {
        if(grid[i-1][j]>grid[i][j-1])
            i--;
        else j--;
       }
     }
     reverse(s.begin(),s.end());
     cout<<s<<endl;
    //out<<grid[a.length()][b.length()]<<endl;
}
 


Measured memory_bytes: 35456
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int X, Y;
  cin >> X >> Y;
  cout << X + Y / 2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

long long gcd(long long a,long long b){long long r,tmp;if(a < b){tmp = a;a = b;b = tmp;}r = a % b;while(r != 0){a = b;b = r;r = a % b;}return b;}
long long lcm(long long a,long long b){long long r;r = gcd(a,b);r = a * b / r;return r;}

int main()
{
    long long a,b;
    scanf("%lld %lld",&a,&b);

    printf("%lld",lcm(a,b));
}


Measured memory_bytes: 128
s=input()
N=len(s)
alpha="abcdefghijklmnopqrstuvwxyz"
a=[0]*26
for i in range(N):
    for j in range(26):
        if s[i]==alpha[j]:
            a[j]+=1
            break

if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
c=0
lastidx=-1
while True:
    for j in range(lastidx+1,26):
        if a[j]==0 :
            print(s[:N+c]+alpha[j])
            exit()
    lastidx=alpha.index(s[-1+c])
    a[lastidx] -= 1
    c-=1


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}


int main() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1;i<=n;i++) {
        if(i%2 != 1) continue;
        int tmp = 0;
        for(int j = 1;j<=i;j++) {
            if(i%j==0) tmp++;
        }
        if(tmp==8) ans++;
    }  
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int A[2000000];
int B[2000000];
int C[10005];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0; i<n; i++) cin>>A[i];

	for(int i=0; i<n; i++) C[A[i]]++;
	C[0]--;
	for(int i=1; i<=10000; i++) C[i]+=C[i-1];
	for(int i=n-1; i>=0; i--) {
		B[C[A[i]]]=A[i];
		C[A[i]]--;
	}

	cout<<B[0];
	for(int i=1; i<n; i++) cout<<' '<<B[i];
	cout<<'\n';

	return 0;
}



Measured memory_bytes: 18776
#include <bits/stdc++.h>
using namespace std;
int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output14.txt", "w", stdout);
#endif
	//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	int a[n], dp[n + 1];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		dp[i + 1] = INT_MAX;
	}
	dp[1] = 0;
	for (int i = 2; i <= n; i++)
	{
		for (int j = 1; j <= k; j++)
		{
			if (i - j > 0)
			{
				dp[i] = min(dp[i], abs(a[i - 1] - a[i - j - 1]) + dp[i - j]);
			}
		}
	}
	cout << dp[n] << "\n";


//cout << "\n";
}

Measured memory_bytes: 4352
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = __int128_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<class T>void put_double(T a){cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

template<class T>void println(T a){cout << a << "\n";}
int main(void) {
    int n; cin >> n;
    Int ans = 1;
    vint a(n); 
    rep(i, n) {
        string s; cin >> s;
        a[i] = parse(s);
        if(a[i] == 0) {
            println(0);
            return 0;
        }
    }

    rep(i, n) {
        if(ans > 1000000000000000000 || ans < 0) {
            println(-1);
            return 0;
        } 
        ans *= a[i];
        if(ans > 1000000000000000000 || ans < 0) {
            println(-1);
            return 0;
        }
    }
    println(ans);

    return 0;
}


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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

#ifdef LOCAL
#define show(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n;
    string s;
    cin >> n >> s;

    int lb = 0, rw = 0;
    for (char c : s) {
        if (c == '.') rw++;
    }
    int ans = rw;
    for (int i = 0; i < n; i++) {
        if (s[i] == '#') lb++;
        else rw--;
        ans = min(ans, lb + rw);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i,n) cin >> h[i];
	int ans = 0, val = 0;
	for (int i = 1; i < n; i++) {
		if (h[i-1] >= h[i]) val++;
		else val = 0;
		ans = max(ans, val);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define ll long long int
#define ld long double
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back

using namespace std;
typedef pair<int, int> pii;

int main() {
    fastIO;
    string s1, s2;
    cin >> s1 >> s2;

    int best = s2.length(), n1 = s1.length(), n2 = s2.length();

    for (int i = 0; i < n1 - n2 + 1; i++) {
        int ans = n2;
        for (int j = i; j < i + n2; j++) {
            if (s1[j] == s2[j - i]) ans--;
        }
        best = min(best, ans);
    }

    cout << best;
}


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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }



int main() {
    int N,M; scanf("%d%d", &N,&M);
    vi ko(M+1, 0);
    rep(i,N){
        int Ki; scanf("%d", &Ki);
        rep(j,Ki) {
            int Aij; scanf("%d", &Aij);
            ko[Aij]++;
        }
    }
    int ans = 0;
    rep(i,M+1){
        if (ko[i] == N) ++ans;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int mn=105;
char a[mn][mn];
int r,c,q,k,i,j;
int main()
{
    cin>>r>>c;
    for(i=1;i<=r;i++)
        for(j=1;j<=c;j++)
          {
              cin>>a[i][j];
              if(a[i][j]=='.') a[i][j]='0';
          }
    for(i=1;i<=r;i++)
        for(j=1;j<=c;j++)
        {
            if(a[i][j]=='#')
            {
                for(k=i-1;k<=i+1;k++)
                    for(q=j-1;q<=j+1;q++)
                {
                    if(a[k][q]!='#')a[k][q]++;
                }
            }
        }
    for(i=1;i<=r;i++)
        {
            for(j=1;j<=c;j++)
            {
                cout<<a[i][j];
            }
            cout<<endl;
        }
    return 0;
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define show(x) cout<<#x<<" = "<<(x)<<" "
#define ENA cout<<endl;
#define ENAA cout<<endl<<endl;

int MAX = 1e+6+5;
int BIG = 1e+9;
int mod = 1e+9+7;

vector<int> fac, ifac;

int power (int base, int exp, int mod)
{
    int res = 1;
    base%=mod;
    while(exp)
    {
        if (exp & 1)
        {
            res*=base;
            res%=mod;
        }
        exp>>=1;
        base*=base;
        base%=mod;
    }
    return res;
}

int inv (int arg, int mod)
{
    return power(arg, mod-2, mod);
}

void preCompute(int sz)
{
    fac.resize(sz+1);
    ifac.resize(sz+1);
    fac[0]=1;
    for (int i=1; i<=sz; i++)
    {
        fac[i]=fac[i-1]*i;
        fac[i]%=mod;
    }
    ifac[sz]=inv(fac[sz],mod);
    for (int i=sz-1; i>=0; i--)
        ifac[i]=(ifac[i+1]*(i+1))%mod;
}

int nCr (int n, int r)
{
    if (n>=r && r>=0)
        return (((fac[n]*ifac[n-r])%mod)*ifac[r])%mod;
    return 0;
}

signed main ()
{
    IOS;
    preCompute(100000);

    int n,k; cin>>n>>k;

    map<int,int>freq;
    int ar[n+2];
    int sumVal(0);

    repa(i,1,n)
    {
        cin>>ar[i];
        freq[ar[i]]++;
    }
    
    int strictlySmall(0);

    for (auto it: freq)
    {
        int equalorBig(0);
        equalorBig = n-sumVal;

        int bufAns(0);
        int negContribution(0);
        repa(j,1,it.ss)
        {
            bufAns = nCr(n-strictlySmall-j,k-1);
            bufAns*=-1;
            bufAns+=mod;
            bufAns%=mod;
            bufAns*=it.ff;
            bufAns%=mod;
            sumVal+=bufAns;
            sumVal%=mod;
        }

        int strictlyBig = n-strictlySmall-it.ss;

        repa(j,1,it.ss)
        {
            bufAns = nCr(n-strictlyBig-j,k-1);
            bufAns*=it.ff;
            bufAns%=mod;
            sumVal+=bufAns;
            sumVal%=mod;
        }

        strictlySmall+=it.ss;
    }

    cout<<sumVal<<endl;
}


Measured memory_bytes: 8320
N = int(input())
t = [0] * (N+1)
x = [0] * (N+1)
y = [0] * (N+1)
for i in range(N):
    t[i+1], x[i+1], y[i+1] = map(int, input().split())

for i in range(N):
    dt = t[i+1]-t[i]
    dx = abs(x[i+1]-x[i])
    dy = abs(y[i+1]-y[i])
    if dt-dx-dy >= 0 and (dt-dx-dy)%2 == 0:
        continue
    else:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 11636
import copy

D = int(input())
C = list(map(int, input().split()))
S = []
for _ in range(D):
    s_row = list(map(int, input().split()))
    S.append(s_row)

results = []

# Cを無視して最大値をとる
# for d in range(D):
#     s_row = S[d]
#     max_value = max(s_row)
#     max_index = s_row.index(max_value)
#     results.append(max_index+1)

# 26種類順番にやる
# for d in range(D):
#     results.append((d % 26) + 1)
#     results.append(max_index+1)

# 次の日に減る分も考慮して選ぶ
last = [0 for i in range(26)]
next_costs = [0 for i in range(26)]

for d in range(D):

    for i in range(26):
        next_costs[i] = C[i] * (d-last[i])

    result = -100000
    next_costs_sum = sum(next_costs)
    result_idx = -1
    for i in range(26):
        tmp_result = S[d][i] - (next_costs_sum - C[i] * (d-last[i]))
        if tmp_result > result:
            result = tmp_result
            result_idx = i
    last[result_idx] = d
    results.append(result_idx + 1)

# 次の日に減る分も考慮して選ぶ(DP)
# last = [0 for i in range(26)]
# dp = [[(0, last) for i in range(26)] for d in range(D)]

# next_costs = [0 for i in range(26)]

# for d in range(D):

#     for i in range(26):
#         next_costs[i] = C[i] * (d-last[i])

#     result = -100000
#     next_costs_sum = sum(next_costs)
#     for i in range(26):
#         tmp_score = S[d][i] - (next_costs_sum - C[i] * (d-last[i]))
#         score = dp[d][i][0] + tmp_score
#         next_last = copy.copy(dp[d][i][1])
#         next_last[i] = d
#         dp[d+1][i] = (score, next_last)

for result in results:
    print(result)


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

typedef long double                 ld;
typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define endl                        '\n'
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define kill(x)                     return cout << x << endl , 0;
#define pb                          push_back

const ll MXN = 1e3 + 3;
const ll MX5 = 3e5 + 3;
const ll MX6 = 1e6 + 3;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; //998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}
string base2(ll n){
    string a="";while(n>=2){a+=(char)(n%2+'0');n/=2;}a+=(char)(n+'0');reverse(all(a));return a;
}



int main(){
    //fast_io
    //file_io
    ll h,w,a,b;
    cin >> h >> w >> b >> a;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i < a && j < b){
                cout << 0;
            }
            else if(i >= a && j < b){
                cout << 1;
            }
            else if(i >= a && j >= b){
                cout << 0;
            }
            else{
                cout << 1;
            }
        }
        cout << endl;
    }

    return 0;
}
//! N.N


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using Int = int64_t;
using Float = double;

int main() {
  Int N;
  cin >> N;
  auto A = vector<Int>(N+1);
  for(Int i=1; i<=N; i++) {
    cin >> A[i];
  }
  auto d = unordered_map<Int, Int>();
  for(Int i=1; i<=N; i++) {
    auto a = A[i];
    if (d.find(a) == d.end()) {
      d[a] = 1;
    } else {
      d[a] = d[a] + 1;
    }
  }
  
  Int ans0 = 0;
  for(auto&& kv : d) {
    if (kv.second >= 2) {
      ans0 += kv.second *(kv.second - 1) / 2;
    }
  }
  
  for(Int k=1; k<=N; ++k) {
    auto a = A[k];
    auto n = d[a];
    auto ans = ans0 - ((n>=2) ? n-1 : 0);
    cout << ans << endl;
  }
  
  return 0;
}


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

int main() {
    int s_num;
    std::cin >> s_num;
    std::vector<int> s(s_num);
    for (int i=0; i<s_num; i++) /* -> */ std::cin >> s.at(i);

    int t_num;
    std::cin >> t_num;
    std::vector<int> t(t_num);
    for (int i=0; i<t_num; i++) /* -> */ std::cin >> t.at(i);

    int count = 0;
    for (int i=0; i<t.size(); i++){
        int left = 0;
        int right = s.size();
        
        /* binary search */
        while (left < right) {
            int mid = (left + right)/2;
            if (s.at(mid) == t.at(i)) {
                count++;
                break;
            }
            if (s.at(mid) < t.at(i)) /* then */ left = mid+1;
            else if (s.at(mid) > t.at(i)) /* then */ right = mid;
        }
    }
    std::cout << count << std::endl;
}


Measured memory_bytes: 3272