akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;
const int mod=1000000007;

int fac[200010],inv[200010];

int power(int x,int y)
{
    int t=1;
    while (y)
    {
        if (y&1) t=ll(t)*x%mod;
        y>>=1;x=ll(x)*x%mod;
    }
    return t;
}

int c(int n,int m)
{
    if (m<0||n<m) return 0;
    return ll(fac[n])*inv[m]%mod*inv[n-m]%mod;
}

int main()
{
    #ifdef waltz
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int h,w,a,b;scanf("%d%d%d%d",&h,&w,&a,&b);
    fac[0]=1;for (int i=1;i<=200000;i++) fac[i]=ll(fac[i-1])*i%mod;
    inv[200000]=power(fac[200000],mod-2);for (int i=200000;i;i--) inv[i-1]=ll(inv[i])*i%mod;
    int ans=0;
    for (int i=1;i<=h-a;i++) ans=(ll(c(i-1+b,i-1)-c(i-2+b,i-2))*c(h-i+w-b-1,h-i)+ans)%mod;
    printf("%d\n",(ans+mod)%mod);
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n , b;
cin>>n>>b;
cout<<(n+b-1)/b<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    char N1, N2, N3, N4;
    cin >> N1 >> N2 >> N3 >> N4;
    map<char, int> cnt;
    cnt[N1]++;
    cnt[N2]++;
    cnt[N3]++;
    cnt[N4]++;
    if(cnt['1'] == 1 and cnt['9'] == 1 and cnt['7'] == 1 and cnt['4'] == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int K, S;
int main() {
    cin >> K >> S;
    int sum = 0;
    for(int z=0; z<=K; z++) {
        if(S-z <= K && S-z>=0) {
            sum += S - z + 1;
        } else if(S-z > K && K*2-S+z>=0) {
            sum += K*2 - S + z + 1;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    string s;
    cin >> s;
    vector<int> a(26);
    rep(i, s.size()) {
        a.at(s.at(i) - 'a')++;
    }
    rep(i, 26) {
        if (a.at(i) % 2 == 1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

int main(){
    int N,K;cin>>N>>K;
    vector<long long>H(N);
    for(int i=0;i<N;i++)cin>>H[i];
    sort(H.begin(),H.end());
    long long res=0;
    for(int i=0;i<N-K;i++)res+=H[i];
    cout<<res<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("mmx,avx,fma")
//#pragma GCC optimize ("unroll-loops")

using namespace __gnu_pbds;
using namespace std;

//template <class T>
//istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//template <char d = ' ', class T>
//ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }
//template <char d = ' ', class T>
//ostream& operator << (ostream& out, set<T>& v){ for(auto& e : v){ out << e << d; } return out; }

#define pb push_back
#define mk make_pair
#define X first
#define Y second
#define cont continue
#define ret return
#define For(i, a, b) for (int i = a; i < b;i++)
#define forn(i, a) for (int i = 0;i < a;i++)
#define ford(i, a, b) for (int i = b - 1;i >= a;i--)
#define fordn(i, a) for (int i = a - 1;i >= 0;i--)
#define forr(x, arr) for(auto &x: arr)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define REE(s_) {cout << s_ << '\n';exit(0);}
#define endl '\n'
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())

#define int long long
typedef double dd;
typedef long double ldd;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef set<int> si;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
template <typename T> std::string toString(T val){std::ostringstream oss; oss << val; return oss.str();}

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

const int mod = 1e9 + 7;

//int powq(int a, int n) {
//    int res = 1;
//    while (n){
//        if (n & 1) {
//            res *= a;
//            res %= mod;
//            --n;
//        }
//        else {
//            a *= a;
//            a %= mod;
//            n >>= 1;
//        }
//
//    }
//    res %= mod;
//    return res;
//}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #ifdef KULA
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
    #else
//        freopen("input.in", "r", stdin);
//        freopen("output.out", "w", stdout);
    #endif
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(c, b / a);
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n,k = map(int,input().split())
a=list(map(int,input().split()))
q = Counter(a).most_common()
count = 0
i = 0
if len(q) < k:
    print(0)
    exit()
while i < k:
    count += q[i][1]
    i += 1
print(n-count)

Measured memory_bytes: 39352
#include<stdio.h>
#include<string.h>
int main()
{
	char str[1000];
	gets(str);
	if(strcmp(str,"Sunny")==0)
	{
		printf("Cloudy\n");
	}
	else if(strcmp(str,"Cloudy")==0)
	{
		printf("Rainy\n");
	}
	else if(strcmp(str,"Rainy")==0)
	{
		printf("Sunny\n");
	}
  return 0;
}

Measured memory_bytes: 128
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int V;
int E;
struct edge { int from, to, cost; };

typedef pair<int, int> PP;

vector<edge> e;

int Par[100000];
int Rank[100000];

void init(int n) {
	for (int i = 0; i < n; i++) {
		Par[i] = i;
		Rank[i] = 0;
	}
}

int find(int x) {
	if (Par[x] == x) {
		return x;
	}
	else {
		return Par[x] = find(Par[x]);
	}
}

void unite(int  x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (Rank[x] < Rank[y]) {
		Par[x] = y;
	}
	else {
		Par[y] = x;
		if (Rank[x] == Rank[y])Rank[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

// ソート時に比較するための関数 
bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}

int kruskal() {
	init(V);
	sort(e.begin(), e.end(), comp);
	int ans = 0;
	for (int i = 0; i<E; i++) {
		if (!same(e[i].from, e[i].to)) {
			unite(e[i].from, e[i].to);
			ans += e[i].cost;
		}
	}
	return ans;
}

int main() {
	int n;
	int x, y;

	cin >> n;
	V = n;
	vector<pair<int,pair<int, int>>>xy, yx;
	REP(i, n) {
		cin >> x >> y;
		xy.emplace_back(mp(x,mp( y, i)));
		yx.emplace_back(mp(y, mp(x, i)));
	}
	sort(ALL(xy));
	sort(ALL(yx));
	REP(i, xy.size() - 1) {
		E++;
		e.emplace_back(edge{ xy[i].second.second,xy[i + 1].second.second,min(abs(xy[i].first - xy[i + 1].first),abs(xy[i].second.first - xy[i + 1].second.first)) });
	}
	REP(i, yx.size() - 1) {
		E++;
		e.emplace_back(edge{ yx[i].second.second,yx[i + 1].second.second,min(abs(yx[i].first - yx[i + 1].first),abs(yx[i].second.first - yx[i + 1].second.first)) });
	}
	cout << kruskal() << endl;
}

Measured memory_bytes: 6956
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef long long ll;
typedef pair<int,int> pii;
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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
  os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
  os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<int N,class Tuple> void out(ostream&,const Tuple&) {}
template<int N,class Tuple,class,class ...Ts> void out(ostream &os,const Tuple &t) {
	if(N)os<<","; os<<get<N>(t); out<N+1,Tuple,Ts...>(os,t);
}
template<class ...Ts> ostream& operator<<(ostream &os, const tuple<Ts...> &t) {
  os<<"("; out<0,tuple<Ts...>,Ts...>(os,t); os<<")"; return os;
}
template<class T>void output(T *a, int n) {REP(i,n){if(i)cout<<",";cout<<a[i];}cout<<endl;}
template<class T>void output(T *a, int n,int m) { REP(i,n) output(a[i],m);}

ll func(int a, int b, int d, int f) {
  return (f<=d ?
          f*a :
          d*a+(f-d)*b);
}

int x[1000];
int y[1000];
int a[1000];
int b[1000];
int d[1000];

ll distf[100][100];
ll distd[100][100];
ll distf_d[100][100];


int main() {
  int n,m,s,t,f;
  while(cin>>n>>m>>s>>t>>f) {
    REP(i,n)REP(j,n)
      distf_d[i][j]=distf[i][j]=distd[i][j]=(i==j?0:1LL<<50);
    int dd = INF;    
    REP(i,m) {
      cin >> x[i] >> y[i] >> a[i] >> b[i] >> d[i];
      if (a[i]<b[i]) dd = d[i];
    }
    if (dd != INF) {
      if (dd > f) dd = f;
    }
    // cout << tpl(f,dd,f-dd) << endl;
    REP(i,m) {
      chmin(distf[x[i]][y[i]],func(a[i],b[i],d[i],f));
      chmin(distd[x[i]][y[i]],func(a[i],b[i],d[i],dd));
      if (a[i]>b[i])
        chmin(distf_d[x[i]][y[i]],func(a[i],b[i],d[i],f-dd));      
    }
    REP(k,n)REP(i,n)REP(j,n) {
      chmin(distf[i][j], distf[i][k]+distf[k][j]);
      chmin(distd[i][j], distd[i][k]+distd[k][j]);
      chmin(distf_d[i][j], distf_d[i][k]+distf_d[k][j]);      
    }
    // cout << distd[0][2] << endl;
    // cout << distf_d[0][2] << endl;
    ll ans = 1LL<<50;
    if (dd == INF) {
      ans = distf[s][t];
    } else {    
      REP(i,n)REP(j,n) {
        chmin(ans, distf[s][i]+distd[i][j]+distf_d[i][j]+distf[j][t]);
      }
    }
    if (ans == 1LL<<50) {
      puts("Impossible");
    } else {
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  ll W,H,x,y;
  double ansa;
  int ansb=0;
  cin>>W>>H>>x>>y;
  if((double)W/2.0==x&&(double)H/2.0==y) ansb=1;
  ansa=(double)W*H/2.0;
  printf("%.12f %d\n",ansa,ansb);
}


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

using namespace std;
using ll = long long;
constexpr int mo = 1000000007;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<62;
int n;
ll k;
vector<ll> a;
bool check(int v){
    vector<ll> b;
    vector<ll> s;
    for(auto & t : a)b.push_back(t%v);
    sort(b.begin(),b.end());
    s.push_back(0);
    for(auto &t : b)s.push_back(s.back()+t);
    for(int i=0;i<n;++i){
        ll A = s[i];
        ll B = 1ll*(n-i)*v - (s[n] - s[i]);
        if(max(A,B) <= k) return true;
    }
    return false;
}
int main(){
    cin>>n>>k;
    a.resize(n);
    for(auto &b: a) cin>>b;
    ll sum = accumulate(a.begin(),a.end(),0);
    ll ret = 0;
    for(int x=1;x*x<=sum;++x)if(sum%x==0){
        if(check(x)) ret = max(ret,1ll*x);
        if(check(sum/x)) ret = max(ret,1ll*sum/x);
    }
    cout << ret << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a,b,c;
    int cnt=0;
    int i;
    
    scanf("%d %d %d",&a,&b,&c);
    
    for(i=a;i<=b;i++)
    {
        if(c%i == 0)    cnt++;
    }
    
    printf("%d\n",cnt);
    
    return 0;
}



Measured memory_bytes: 2052
def examE():
    N, K = LI()
    A = LI()
    sumA = [0]*(N+1)
    for i in range(1,N+1):
        sumA[i] = sumA[i-1]+A[i-1]
    d = defaultdict(int)
    ans = 0
    #連想配列 先頭からの番号　余分な量
    que = deque()
    for i,a in enumerate(sumA):
        #K番目以降は一番左のやつ消していく
        if que and que[0][0] <= (i-K):
            d[que.popleft()[1]] -= 1
        cur = (a-i)%K
        ans +=d[cur]
        d[cur] +=1
        que.append((i,cur))
#        print(ans,que,d,a-i)
    print(ans)
    return

def examF():
    return

import sys,copy,bisect,itertools,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examE()


Measured memory_bytes: 105928
#include<iostream>
#include<cmath>
using namespace std;
int target;

int main(int argc, char *argv[]){
  while(cin >> target, target){
    int card;
    cin >> card;
    int ans = -1, digit = log10(card), bit = 0;

    for (int i = 0; i < 1<<digit; i++) {
      int tmp = card, calc = 0;
      for (int j = digit - 1; j >= 0; j--) {
        if(i&(1<<j)){
          calc += tmp/(int)pow(10, j+1);
          tmp %= (int)pow(10, j+1);
        }
      }
      calc += tmp;
      if(ans < calc && calc <= target){
        // std::cout << "calc:" << calc << std::endl;
        ans = calc;
        bit = i;
      }else if(ans == calc){
        bit = -1;
      }
    }
    if(ans == -1){
      std::cout << "error" << std::endl;
    }else if (bit == -1){
      std::cout << "rejected" << std::endl;
    }else{
      //std::cout << "bit:" << bit << std::endl;
      std::cout << ans << " ";
      for (int i = digit - 1; i >= 0; i--) {
        std::cout << (int)(card/pow(10, i+1));
        card %= (int)pow(10, i+1);
        if(bit&(1<<i))std::cout << " ";
      }
      std::cout << card << std::endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int i,j,k,n,m;
void read(int &x){
	char c;x=0;do c=getchar();while(c>57||c<48);
	do x=x*10+c-48,c=getchar();while(c<=57&&c>=48);
}
void read(ll &x){
	char c;x=0;do c=getchar();while(c>57||c<48);
	do x=x*10+c-48,c=getchar();while(c<=57&&c>=48);
}
string s,s1;
int main() {
    cin>>s;
	s1+=s[0];
	k=1;
	for(i=1;i<s.size();i++){
		string s2;
		s2+=s[i];
		if(s1==s2&&i!=s.size()-1){
			s2+=s[++i];
			++k;
			s1=s2;
		}else
		if(s1!=s2){
			++k;
			s1=s2;
		}
	}cout<<k<<endl;
    //cerr << 1.0*clock()/CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))
ans = 0
check = 0
for i in range(1, n):
  if a[i-1] == a[i] and check == 0:
    ans += 1
    check = 1
  elif a[i-1] == a[i] and check == 1:
    check = 0
  else:
    check = 0
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdint>

int main() {
  int A, B, C;
  intmax_t K;
  scanf("%d %d %d %jd", &A, &B, &C, &K);

  printf("%d\n", (K%2 > 0)? B-A:A-B);
}


Measured memory_bytes: 128
$n, $m, $q = gets.chomp.split(' ').collect! { |tmp| tmp.to_i }
$data = Array.new
$q.times do
    $data.push(gets.chomp.split(' ').collect! { |tmp| tmp.to_i })
end
$ans = 0

def dfs(value)
    if value.length > $n then
        tmp_ans = 0
        $data.each { |a, b, c, d|
            if value[b] - value[a] == c then
                tmp_ans += d
            end
        }
        if tmp_ans > $ans then
            $ans = tmp_ans
        end
        return
    end

    for i in value.last..$m
        dfs(Array.new(value).push(i))
    end
end

dfs([1])
puts $ans

Measured memory_bytes: 15156
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll,ll> P;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    int N; cin >>N;
    vector<int>P, Q(N);
    rep(i,N){
        int p; cin >> p;
        p--;
        P.push_back(p);
    }
    rep(i,N){
        Q[P[i]]=i;
    }
    Q.push_back(-1);
    int cnt=1;
    int ans=0;
    for(int i=0; i<N; i++){
        if(Q[i]>Q[i+1]){
            ans=max(ans, cnt);
            cnt=1;
        }else{
            cnt++;
        }
    }
    cout << N-ans << endl;
    return 0;
}


Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)




int main(){

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt	
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif	

    FAST
//	PRECISE

ll n;
cin>>n;
ll a1=0,a2=0;
string s;
cin>>s;
FOR(i,0,n){
	if(s[i]=='W')a2++;
	else a1++;
}
ll k3=0;
FOR(i,0,a1){
	if(s[i]=='W')k3++;
}
cout<<min(a1,min(a2,k3));


return 0;
 }



Measured memory_bytes: 3756
x, n = map(int, input().split())
p = set(list(map(int, input().split())))

cand1 = x
while cand1 in p:
    cand1 -= 1

cand2 = x
while cand2 in p:
    cand2 += 1

if abs(cand1 - x) <= abs(cand2 - x):
    ans = cand1
else:
    ans = cand2

print(ans)


Measured memory_bytes: 9180
INF = float('inf')
MAX_N = 110
MAX_W = 10**5 + 100

N, W = map(int, input().split())
w, v = [0]*N, [0]*N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[0]*MAX_W for _ in range(MAX_N)]

for i in range(1,N+1):
    for j in range(W+1):
        if j-w[i-1]>=0:
            dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]]+v[i-1])

        dp[i][j] = max(dp[i][j], dp[i-1][j])

print(dp[N][W])

Measured memory_bytes: 120984
<?php
//以下の高速化でなんとか通りました。N=300、O(N^3)はPHPには辛いですね
//メモ化再帰->DPに書き換え
//3次元配列へのアクセスを2次元に落とす
$N = intval(trim(fgets(STDIN)));
$A = explode(' ', trim(fgets(STDIN)));
$c1=$c2=$c3=0;
foreach($A as $a){
    if($a == '1')$c1++;
    if($a == '2')$c2++;
    if($a == '3')$c3++;
}
$dp = array_fill(0, $N+1, array_fill(0,$N+1, array_fill(0,$N+1,0)));
for($k = 0; $k <= $c3; ++$k){
    $dpk = &$dp[$k];
    for($j = 0, $J = $c2 + $c3 - $k; $j <= $J; ++$j){
        for($i = 0, $I = $c1+$c2+$c3-$k-$j; $i <= $I ; ++$i){
            if($i==0&&$j==0&&$k==0)continue;
            $tmp = $N;
            if($i>0)$tmp+=$i*$dpk[$j][$i-1];
            if($j>0)$tmp+=$j*$dpk[$j-1][$i+1];
            if($k>0)$tmp+=$k*$dp[$k-1][$j+1][$i];
            $dpk[$j][$i] = $tmp/($i+$j+$k);
        }
    }
}
echo $dp[$c3][$c2][$c1];


Measured memory_bytes: 926200
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>
#include <stack>

using namespace std;

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

const ll mod = 1e9 + 7;
const ll mmod = 998244353;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<string> g;
vector<vector<bool>> used;
vector<ll> d;

int main() {
    
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    ll n;
    cin >> n;
    vector<ll> c(n);
    map<ll, ll> m;
    
    for (int i = 0; i < n; ++i)
    {
        ll tmp;
        cin >> tmp;
        c[i] += tmp;
        if (i == 0)
        {
            continue;
        }
        c[i] += c[i - 1];
    }
    for (int i = 0; i < n; ++i)
    {
        m[c[i]]++;
    }
    ll ret = m[0];
    for (auto itr = m.begin(); itr != m.end(); ++itr)
    {
        ret += (itr->second * (itr->second - 1)) / 2ll;
    }
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 14336
n = int(input())
S = [v for v in input()]

# determine L or R
lst = [0 for i in range(2 * n)]
for i in range(2 * n):
    if S[i] == 'W' and (2 * n - i - 1) % 2 == 0:
        lst[i] = 'L'
    elif S[i] == 'W' and (2 * n - i - 1) % 2 == 1:
        lst[i] = 'R'
    elif S[i] == 'B' and (2 * n - i - 1) % 2 == 0:
        lst[i] = 'R'
    elif S[i] == 'B' and (2 * n - i - 1) % 2 == 1:
        lst[i] = 'L'


deq = 0
val = 1
#tracing lst
for i in range(2 * n):
    if lst[i] == 'L':
        deq += 1
    elif lst[i] == 'R':
        val *= deq
        val %= 10 ** 9 + 7
        deq -= 1

if deq != 0:
    print(0)
else:
    for i in range(1, n + 1):
        val = val * i % (10 ** 9 +7)
    print(val)


Measured memory_bytes: 66428
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;

int p[1001];
int h[1000*1000+1001];

int main(){
	int n,m,ans;
	while(cin>>n>>m){
		if(n==0&&m==0) break;
		p[0]=0;
		ans=0;
		for(int i=1; i<=n; ++i){
			cin >> p[i];
		}
		for(int i=0; i<=n; ++i){	
			for(int j=0; j<=n; ++j){
				h[i*n+j]=p[i]+p[j];
			}
		}
		sort(h,h+n*n+1);
		/*
		for(int i=0; i<=n*n; ++i){
			cout << h[i] << "\n";
		}
		*/
		for(int i=0; i<=n; ++i){	
			for(int j=0; j<=n; ++j){	
				int tmp=p[i]+p[j];
				int l=0,r=n*n;
				int cnt=0;
				while(1){
					int mid=(r+l)/2;
					if(cnt>=20){
						if(h[mid]+tmp<=m) ans=max(ans,h[mid]+tmp);
						break;
					}
					if(h[mid]+tmp>m){
						r=mid;
					} else if(h[mid]+tmp<m){
						l=mid;
					} else if(h[mid]+tmp==m){
						ans=m;
						break;
					}
					++cnt;
				}
			}
		}
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 5092
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
int c(const void *v1,const void *v2){
    return ((int *)v1)[0]-((int *)v2)[0];
}
int main(void){
    int N,M,map[20000][3],inf[20001],i,sum;
    for(;memset(inf,0,sizeof(inf)),sum=1,inf[1]=1,scanf("%d %d",&N,&M),N+M;){
        for(i=0;i<M;i++)
            scanf("%d %d %d",&map[i][0],&map[i][1],&map[i][2]);
        qsort(map,M,sizeof(int)*3,c);
        for(i=0;i<M;i++)
            if(inf[map[i][1]] && !inf[map[i][2]]){
                inf[map[i][2]]=1;
                sum++;
            }
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

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

Measured memory_bytes: 256
use std::io::{BufRead, Write};
use std::io;
use std::mem;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let _: usize = buf.trim_right().parse().unwrap();
    buf.clear();
    input.read_line(&mut buf).unwrap();
    let mut p: Vec<usize> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
    let mut result: usize = 0;
    for i in 0..p.len() - 1 {
        if p[i] == i + 1 {
            result += 1;
            let mut_range = &mut p[i..i + 2];
            let (first, mut_range) = mut_range.split_first_mut().unwrap();
            let (second, _) = mut_range.split_first_mut().unwrap();
            mem::swap(first, second);
        }
    }
    if p.last().unwrap() == &p.len() {
        result += 1;
    }
    writeln!(output, "{}", result).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "5
1 4 3 5 2\n",
            "2\n",
        );
    }
    #[test]
    fn case2() {
        test(
            "2
1 2\n",
            "1\n",
        );
    }
    #[test]
    fn case3() {
        test(
            "2
2 1\n",
            "0\n",
        );
    }
    #[test]
    fn case4() {
        test(
            "9
1 2 4 9 5 8 7 3 6\n",
            "3\n",
        );
    }
}


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

int main(){
    int n,l; cin >> n >> l;
    vector<string> S(n);
    rep(i,n){
        cin >> S[i];
    }
    sort(S.begin(),S.end());

    rep(i,n){
        cout << S[i];
    }

    cout << endl;


}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    
    def Warshall_Floyd(d):
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    d[i][j] = min(d[i][j], d[i][k]+d[k][j])
        return d
      
    n, m, l = map(int, input().split())
    f_inf = float('inf')
    dist = [[f_inf]*n for _ in range(n)]
    
    for _ in range(m):
        a, b, c = map(int, input().split())
        dist[a-1][b-1] = c
        dist[b-1][a-1] = c

    Warshall_Floyd(dist)

    dist2 = [[f_inf]*n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if dist[i][j] <= l:
                dist2[i][j] = 1
    
    Warshall_Floyd(dist2)

    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        if dist2[s-1][t-1] == f_inf:
            print(-1)
        else:
          ans = dist2[s-1][t-1]
          print(ans-1)

if __name__ == "__main__":
    main()

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

check = {}
i = 0
number = []
next = a[0]
start = 0

for i in range(1,n+1):
    if next in check:
        start = number.index(next)
        rep = number[number.index(next):]
        break
    else:
        check[next] = 1
        number.append(next)
        next = a[next-1]

if k <= start:
    print(number[k-1])
else:
    c = len(rep)
    print(rep[(k-start-1)%c])

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

#define ull unsigned long long int
#define ll long long int

const ll M=1e9+7;

ll mod(ll n){
	return (n%M + M)%M;	
}
ll add(ll a, ll b){
	return mod(mod(a)+mod(b));
}
ll mul(ll a, ll b){
	return mod(mod(a)*mod(b));
}
ll modMinus(ll a, ll b){
	return mod(mod(a)-mod(b));
}
ll modpow(ll x, ll n) 
{ 
	if (n == 0) 
		return 1%M;
	if (n == 1)
		return x%M; 
	ll u = modpow(x,n/2); 
	u = mul(u,u); 
	if (n%2) 
		u = mul(u,x); 
	return u; 
}
ll gcd(ll a,ll b){
	if(b==0)
		return a;
	return gcd(b,a%b);
}
bool isPrime(ll n){
	int end = sqrt(n);
	for(int i=2;i<=end;i++)
		if(n%i==0)
			return false;
	return true;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   
    
    int t=1;

    while(t--){
    	int n;
    	cin>>n;

    	int ans;
    	if(n==1)
    		ans=0;
    	else if(n==2)
    		ans=2;
    	else{
    		ans = modMinus(modpow(10,n),mul(2,modpow(9,n)));
    		ans=add(ans,modpow(8,n));
    	}
    	cout<<ans;
    }

    
    return 0;
}


Measured memory_bytes: 3660
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
typedef struct{
  double x;
  double y;
} pos;
 
void kock( int n, pos p1, pos p2) {
 
  pos s, t, u;
 
  if(n == 0) {
    return;
  }
 
  s.x = ( 2 * p1.x + p2.x )/3;
  s.y = ( 2 * p1.y + p2.y )/3;
  t.x = ( p1.x + 2 * p2.x )/3;
  t.y = ( p1.y + 2 * p2.y )/3;
  u.x = (t.x - s.x)*cos(M_PI/3) - (t.y - s.y)*sin(M_PI/3) + s.x;
  u.y = (t.x - s.x)*sin(M_PI/3) + (t.y - s.y)*cos(M_PI/3) + s.y;
 
  kock( n-1, p1, s);
  printf("%f %f\n", s.x, s.y);
  kock( n-1, s, u);
  printf("%f %f\n", u.x, u.y);
  kock( n-1, u, t);
  printf("%f %f\n", t.x, t.y);
  kock( n-1, t, p2);
}
 
int main() {
 
  int n;
  pos start={ 0, 0};
  pos end={ 100, 0};
 
  scanf("%d", &n);
 
  printf("%f %f\n", start.x, start.y);
 
  kock( n, start, end);
 
  printf("%f %f\n", end.x, end.y);
 
  return 0;
 
}

Measured memory_bytes: 2752
import collections

n, k = map(int, input().split())
a = list(map(int, input().split()))

c = collections.Counter(a)
vs = []
for v in c.values():
  vs.append(v)
vs.sort(reverse=True)

i = 0
if len(vs) <= k:
  print(i)
  exit()
else:
  while len(vs) > k:
    i += vs[-1]
    vs.pop()
  else:
    print(i)
    exit()
    
    

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

string s;
vector<string> vs; 
bool f[26];

void dfs(string t, int now){
    if(now == s.size()){
        string r = t;
        memset(f, false, sizeof(f));
        rep(i, 0, r.size()){
            if(f[r[i] - 'a'] == false && r[i] != 'a'){
                r[i] = r[i] - 1;
            }
            f[t[i] - 'a'] |= true;
        }
        if(r == s) vs.push_back(t);
        return;
    }
    int d[26] = {};
    rep(i, 0, now) d[t[i] - 'a']++;
    if(t[now] != 'z'){
        string tmp = t;
        tmp[now] = tmp[now] + 1;
        dfs(tmp, now + 1);
    }
    if(t[now] == 'a' || d[t[now] - 'a'] != 0) dfs(t, now + 1);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (1) {
        cin >> s;
        if(s == "#") break;
        vs.clear();
        dfs(s, 0);
        int ans = vs.size();
        sort(vs.begin(), vs.end());
        cout << ans << endl;
        if(ans <= 10){
            rep(i, 0, ans){
                cout << vs[i] << endl;
            }
        }else{
            rep(i, 0, 5){
                cout << vs[i] << endl;
            }
            rep(i, ans - 5, ans){
                cout << vs[i] << endl;
            }
        }
    }
}


Measured memory_bytes: 4144
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
#define what(x) cerr << #x << " is " << x << endl;
const int INF = 1 << 28;

ll fastpowmod(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll mod) { return fastpowmod(a, mod - 2, mod); }

ll comb(ll a, ll b, ll mod) {
    ll ret = 1;
    for (ll i = a; i > (a - b); --i) {
        ret = ret * i % mod;
    }
    for (ll i = 1; i <= b; ++i) {
        ret = ret * modinv(i, mod) % mod;
    }
    return ret;
}

void factors(ll a, set<ll> &facs) {
    for (ll i = 1; i <= sqrt(a); ++i) {
        if (a % i == 0) {
            facs.insert(i);
            facs.insert(a / i);
        }
    }
}

void primeFactors(ll a, map<ll, ll> &facs) {
    ll sqrtA = sqrt(a);
    for (ll i = 2; i <= sqrtA; ++i) {
        while (a % i == 0) {
            facs[i]++;
            a /= i;
        }
    }
    if (a > sqrtA)
        facs[a]++;
}

int main() {
    ll N, M;
    cin >> N >> M;
    ll mod = 1'000'000'007;
    map<ll, ll> facs;
    primeFactors(M, facs);
    ll ret = 1;
    for (auto it = facs.begin(); it != facs.end(); it = next(it)) {
        ret = ret * comb(it->second + N - 1LL, it->second, mod) % mod;
    }
    cout << ret << endl;
    return 0;
}

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


int main() {
    int N, K;
    cin >> N >> K;
    ll p[N];
    ll a[N + 1]{};
    for (int i = 0; i < N; i++) {
        cin >> p[i];
        a[i + 1] = a[i] + p[i];
    }
    double ans = 0;
    ll sum = 0;
    ll t = 0;
    for (int i = K; i <= N; i++) {
        t = a[i] - a[i - K] + K;
        sum = max(sum, t);
    }
    ans = (double)sum / 2.0;
    printf("%.6f\n", ans);
    
    return 0;
}


Measured memory_bytes: 3328
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Set;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String[] w = in.nextStringArray(n);

            Set<String> set = new TreeSet<>();
            set.add(w[0]);
            for (int i = 1; i < n; i++) {
                if (w[i - 1].charAt(w[i - 1].length() - 1) != w[i].charAt(0)
                        || set.contains(w[i])) {
                    out.println("No");
                    return;
                }
                set.add(w[i]);
            }

            out.println("Yes");
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public String[] nextStringArray(int n) {
            String[] res = new String[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextString();
            }
            return res;
        }

    }
}



Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
    string s; cin >> s;
    if (s.back() == 's') cout << s << "es" << endl;
    else cout << s << "s" << endl;
    return 0;
}


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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < max(a, b); ++i) {
    	cout << min(a, b);
    }
  cout << '\n';
}

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


int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

int main() {
	int k = ri(), x = ri();
	for (int i = x - k + 1; i <= x + k - 1; i++) std::cout << i << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a[10010],b[10010],f[10010];
ll v[10010];
ll ans[10010];
ll c[10010];
int main(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n-1){
		ll p,q;
		scanf("%lld%lld",&p,&q);
		a[i]=p-1;
		b[i]=q-1;
		v[a[i]]++;
		v[b[i]]++;
	}
	rep(i,0,n)scanf("%lld",c+i);
	sortup(c,n);
	
	ll sum=0;
	rep(_,0,n){
		//最も次数が小さい頂点に値を割り当てる
		ll m=INF,mi=-1;
		rep(i,0,n){
			if(v[i]<m){
				m=v[i];
				mi=i;
			}
		}
		v[mi]=INF;
		ans[mi]=c[_];
		rep(x,0,n-1)if(!f[x]){
			if(a[x]==mi){
				f[x]=1;
				sum+=c[_];
				v[b[x]]--;
			}else if(b[x]==mi){
				f[x]=1;
				sum+=c[_];
				v[a[x]]--;
			}
		}
	}
	printf("%lld\n",sum);
	rep(i,0,n)printf("%lld ",ans[i]);
}

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

int main(){
  int N, M, K;
  cin >> N >> M >> K;
  vector<long long int> A(N+1, 0), B(M+1, 0);
  
  for(int i=1; i < N + 1; i++){
    cin >> A.at(i);
    A.at(i) += A.at(i - 1);
  }
  
  for(int i=1; i < M + 1; i++){
    cin >> B.at(i);
    B.at(i) += B.at(i - 1);
  }
  
  int j = M;
  int ans = 0;
  for(int i=0; i < N + 1; i++){
    if(A.at(i) > (long long int)K)break;
    while(B.at(j) > K - A.at(i))j--;
    ans = (ans > i + j)? ans : i+j;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6424
from collections import Counter
N = int(input())
S = list(input())
c = Counter(S[1:])
ans = 0+c["E"]
now = S[0]
e = c["E"]
w = 0
for i in range(1,N):
    if now == "W":
        w += 1
    now = S[i]
    if now == "E":
        e -= 1
    if w+e < ans:
        ans = w+e
print(ans)

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

using namespace std;

#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long int
#define float long double
#define foor(i, a, b) for ( int (i) = (a); (i)<(b); (i)++ )
#define foor2(i, a, b) for( int (i) = (a); (i)>(b); (i)-- )
#define foorl(i, a, b) for ( ll (i) = (a); (i)<(b); (i)++ )
#define foorl2(i, a, b) for( ll (i) = (a); (i)>(b); (i)-- )
#define mp make_pair
#define f1 first
#define f2 second
#define pb push_back
#define pii pair<int,int>
#define vpii vector <pii>
#define vi vector<int>
#define sz(a) (int) a.size( )
#define fillArr(n, a) foor(i, 0, n) cin >> a[i];
#define print(a) cout << #a << endl;
#define umax(a,b) a = max ( a, b )
#define umin(a,b) a = min ( a, b )
#define all(k) k.begin ( ), k.end( )
#define rall(k) k.rbegin ( ), k.rend( )
#define clean(k) memset( k, 0, sizeof(k) )
#define endl '\n'


int main(){
	IoFast;
	int n, x, sum = 0;
    cin >> n >> x;
    int a[n];
    foor (i,0,n)
        cin >> a[i];

    sort(a, a + n);
    foor (i, 0, n){
        sum += a[i];
        
        if(x < sum){
            cout << i << endl;
            break;
        }
		else if(x == sum){
            cout << i + 1 << endl;
            break;
        }
        if(i == n - 1){
            cout << i << endl;
        }
    }
}



Measured memory_bytes: 256
from math import gcd, sqrt


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def main():
    N = input()
    A = list(map(int, input().split()))

    s_tmp = A[0]
    p_flag = True
    p_dic = [0] * (10**6+1)
    for a in A:
        s_tmp = gcd(s_tmp, a)
        if p_flag:
            tmp = list(set(prime_factorize(a)))
            for t in tmp:
                if p_dic[t] == 0:
                    p_dic[t] = 1
                else:
                    p_flag = False
                    continue

    if p_flag:
        print('pairwise coprime')
    elif s_tmp == 1:
        print('setwise coprime')
    else:
        print('not coprime')


if __name__ == "__main__":
    main()


Measured memory_bytes: 205284
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N;
	scanf("%d", &N);
	int A[16][16];
	rep(i, N) rep(j, N) scanf("%d", A[i] + j);

	int n = 1 << N;
	vector<ll> dp(n);
	rep1(i, N - 1) {
		int M = 1 << i;
		rep(j, M) {
			ll kari = dp[j];
			rep(k, i) if (j >> k & 1) kari += A[i][k];
			dp[M + j] = kari;
		}
	}

	rep1(i, n - 1) {
		int k = 1 << 31 - __builtin_clz(i);
		for (int j = i - 1 & i; j >= k; j = j - 1 & i) {
			dp[i] = max(dp[i], dp[j] + dp[i ^ j]);
		}
	}

	printf("%lld", dp[n - 1]);

	Would you please return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  
  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }

  
 
}
             
 

Measured memory_bytes: 3604