akhauriyash/Code-Regression huggingface dataset:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        if n == 0:
            break
        a = [S() for _ in range(n)] + ['']
        b = [0] * (n+1)
        for i in range(1,n):
            s = a[i]
            b[i] = len(s.split('.')) - 1
        r = [[c for c in t] for t in a[:n]]
        for i in range(n):
            t = b[i]
            if t == 0:
                continue
            r[i][t-1] = '+'
            ni = i
            for j in range(i+1,n):
                if b[j] < t:
                    break
                if b[j] == t:
                    ni = j
                    break
            for j in range(i+1,ni):
                r[j][t-1] = '|'
            for j in range(t-1):
                if r[i][j] == '.':
                    r[i][j] = ' '
        for c in r:
            rr.append(''.join(c))

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 27908
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>

#include <algorithm>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <string>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define INF (1 << 30)
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back

#if DEBUG
#define _DEBUG(x) cout << #x << ": " << x << endl
#define _DDEBUG(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl
#else
#define _DEBUG(x) ;
#define _DDEBUG(x, y) ;
#endif

#define ll long long
#define ull unsigned long long
#define MOD 1000000007

/** FOR VECTOR DEBUG */
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  if (!v.empty()) {
    out << '[';
    copy(v.begin(), v.end(), ostream_iterator<T>(out, ", "));
    out << "\b\b]";
  }
  return out;
}

/* template end */

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

  ll k, a, b;
  cin >> k >> a >> b;
  if (a >= b) {
    cout << (k + 1) << endl;
    return 0;
  }
  ll d = k / (a + 2);
  vector<ll> v(4);
  v[0] = 1 + b * d + k % (a + 2);
  v[1] = 1 + b * (d - 1) + (a + 2) + k % (a + 2);
  if (k > a) {
    v[2] = 1 + (a - 1) + ((k - a + 1) / 2) * (b - a);
    v[3] = 1 + (a - 1) + ((k - a + 1) / 2 - 1) * (b - a) + 2;
    if ((k - a + 1) % 2 == 1) {
      v[2] += 1;
      v[3] += 1;
    }
  }
  _DEBUG(v);
  ll ans = *max_element(v.begin(), v.end());
#if DEBUG
  cout << "** RESULT **" << endl; // debug
#endif
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  string S, T;
  cin >> S >> T;
  for(int i=0; i<S.size(); ++i) {
    if(S[i] != T[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3616
using System;
using System.Linq;
using System.Collections.Generic;

namespace agc030_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var text = Console.ReadLine();
            var list = text.Split(' ').Select(x => int.Parse(x)).ToList();

            var a = list[0];
            var b = list[1];

            var aodd = a % 2;
            var bodd = b % 2;

            if (aodd != bodd){
                Console.WriteLine("IMPOSSIBLE");
                return;
            }

            if (a > b){
                var c = (a - b) / 2;
                Console.WriteLine(a - c);
            }
            else{
                var c = (b - a) / 2;
                Console.WriteLine(b - c);
            }
            
        }
    }
}


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

int main(int argc, const char *argv[]){
    int n,m;
    cin >> n >> m;
    vector<int> L(m),M(m);
    for(int i=0;i<m;i++){
        cin >> L[i] >> M[i];
    }
    int maxv = *max_element(L.begin(),L.end());
    int minv = *min_element(M.begin(),M.end());
    cout << max(minv-maxv+1,0) << endl;
    return 0;
}

Measured memory_bytes: 1152
amount, num = map(int, input().split())

hated_digit = list(map(str, input().split()))

while True:
    check = 0
    for hd in hated_digit:
        if hd not in str(amount):
            check += 1

        else:
            amount += 1
    if check == num:
        print(amount)
        break


Measured memory_bytes: 2940
#include <stdio.h>

int main(void)
{
	int i, j;
	int a, b, c, d, e;
	int n[5];
	int buf;
	
	scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
	
	n[0] = a;
	n[1] = b;
	n[2] = c;
	n[3] = d;
	n[4] = e;
	
	for (i = 0; i < 4; i++){
		for (j = 0; j < 4 - i; j++){
			if (n[j] < n[j + 1]){
				buf = n[j + 1];
				n[j + 1] = n[j];
				n[j] = buf;
			}
		}
	}
	
	a = n[0];
	b = n[1];
	c = n[2];
	d = n[3];
	e = n[4];
	
	printf("%d %d %d %d %d\n", a, b, c, d, e);
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;
int main(){
    int n;
    cin >> n;
    int mat[n][n];
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            mat[i][j] = 0;
        }
    }
    for(int i = 0; i < n; ++i){
        int id;
        cin >> id;
        int k;
        cin >> k;
        int v;
        for(int j = 0; j < k; ++j){
            cin >> v;
            mat[id-1][v-1] = 1;
        }
    }
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(j == 0){
                cout << mat[i][j];
            } else {
                cout << ' ' << mat[i][j];
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
    int N, a = 0, b = 0;
    cin >> N;
    vector<int> P(N), Q(N), v(N);
    for (auto& i : P) cin >> i;
    for (auto& i : Q) cin >> i;
    iota(v.begin(), v.end(), 1);
    for (int i = 1; next_permutation(v.begin(), v.end()); i++) {
        if (P == v) a = i;
        if (Q == v) b = i;
    }
    cout << abs(a - b) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,m,res=0;
    cin >> n >> m;
    vi x(m),b(m-1);
    rep(i,m) cin >> x.at(i);
    sort(x.begin(), x.end());
    rep(i,m-1) b.at(i) = x.at(i+1) - x.at(i);
    sort(b.begin(), b.end());
    if(m-n>0) rep(i,m-n) res += b.at(i);
    cout << res << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
void YesNo(bool);
void YESNO(bool);


int main(){
    vector<char>s(4);
    int x = 0;
    for (int i = 0; i < 4; i++) {
        cin >> s.at(i);
        
        if (s.at(i) == '+') {
            x++;
        }else{
            x--;
        }
    }
    cout << x << endl;
    
    return 0;
}


void YesNo(bool x){
    if (x) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

void YESNO(bool x){
    if (x) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
}


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

int GCD(int x, int y) {
    return x ? GCD(y % x, x) : y;
}
int main()
{
  int N;
  cin >> N;
  string M;
  if(N < 1000){
    M = "ABC";
  }
  else{
    M = "ABD";
  }
  cout << M << endl;
}


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

const int maxn = 100000 + 10;
int a[maxn];
int dp[maxn];

int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; scanf("%d", &a[i]), i ++ );

	for(int i = 2; i <= n; i++) dp[i] = INT_MAX;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; i + j <= n and j <= k; j++) {
			dp[i + j] = min(dp[i + j], dp[i] + abs(a[i] - a[i + j]));
		}
	}

	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
x1,x2,x3,x4,x5=map(int, input().split())
if(x1==0):
  print(1)
  exit()
if(x2==0):
  print(2)
  exit()
if(x3==0):
  print(3)
  exit()
if(x4==0):
  print(4)
  exit()
if(x5==0):
  print(5)

Measured memory_bytes: 9184
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = (int)3e7;
int ex[2][87];
LL dp[MAXN];

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 3; j++) {
            scanf("%d", &ex[i][j]);
        }
    }
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j < 3; j++) {
            int sub = ex[0][j];
            int add = ex[1][j];
            dp[i + sub] = max(dp[i + sub], dp[i] + add);
        }
    }
    LL nN = 0;
    for (int i = 0; i <= N; i++) {
        int tmp = N - i;
        nN = max(nN, tmp + dp[i]);
    }
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= nN; i++) {
        for (int j = 0; j < 3; j++) {
            int sub = ex[1][j];
            int add = ex[0][j];
            dp[i + sub] = max(dp[i + sub], dp[i] + add);
        }
    }
    LL ans = 0;
    for (int i = 0; i <= nN; i++) {
        int tmp = nN - i;
        ans = max(ans, tmp + dp[i]);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 234752
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    in_arr(int, a, n);
    sort(a.begin(), a.end());
    int ans = 0;
    rep(i, n){
        x -= a[i];
        if(x >= 0){
            ans++;
        }else{
            break;
        }
    }
    if(x > 0)
        ans--;
    cout << ans << endl;
    return 0;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h, w;;
	cin >>h >>w;
	vector<VI> a(h, VI(w));
	rep(i, h) rep(j, w) cin >>a[i][j];
	int cry =0, py=-1, px=-1;
	vector<VI> ans;
	rep(i, h) rep(j, w){
		int nj = i%2? w-1-j: j;
		if(!cry && a[i][nj] %2==0) continue;
		if(!cry && a[i][nj] %2){
			cry =1; py=i; px=nj;
		}else if(cry){
			ans.push_back({py+1,px+1,i+1,nj+1});
			if(a[i][nj] %2) cry = 0;
			else{cry =1; py=i; px=nj;}
		}
	}
	printf("%d\n", sz(ans));
	for(auto x:ans){
		printf("%d %d %d %d\n",x[0],x[1],x[2],x[3]);
	}
	return 0;
}


Measured memory_bytes: 10032
//AOJ0623
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define INF 1e+18;
using namespace std;

struct edge{ int to; int cost; };
typedef pair<long long int,int> P;

int V;
vector<edge> graph[100001];
long long int d[100001];

void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > que;
	for(int i = 0;i < V;i++) d[i] = INF;
	d[s] = 0;
	que.push(make_pair(0,s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0;i < graph[v].size();i++){
			edge e = graph[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(make_pair(d[e.to],e.to));
			}
		}
	}
}

int main(){
	int m,k,s,cp,cq;
	bool danger[100001];
	queue<int> que;
	cin >> V >> m >> k >> s >> cp >> cq;
	for(int i = 0;i < V + 1;i++) danger[i] = false;
	for(int i = 0;i < k;i++) {
		int t;
		cin >> t;
		t--;
		danger[t] = true;
		graph[V].push_back({t,0});
	}
	danger[V] = true;
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b;
		a--;
		b--;
		if(!danger[b]) graph[a].push_back({b,0});
		if(!danger[a]) graph[b].push_back({a,0});
	}
	que.push(V);
	for(int j = 0;j <= s;j++){
		int siz = que.size();
		for(int k = 0;k < siz;k++){
			int v = que.front();que.pop();
			//cout << graph[v].size() << endl;
			for(int i = 0;i < graph[v].size();i++){
				//cout << v << " " << graph[v][i].to << endl;
				if(j == 0 || !danger[graph[v][i].to]){
					danger[graph[v][i].to] = true;
					que.push(graph[v][i].to);
				}
			}
		}
	}
	//for(int i = 0;i < V;i++) if(danger[i]) cout << i << endl;
	for(int i = 0;i < V;i++){
		for(int j = 0;j < graph[i].size();j++){
			int to = graph[i][j].to;
			if(to == V - 1) graph[i][j] = {to,0};
			else if(danger[to]) graph[i][j] = {to,cq};
			else graph[i][j] = {to,cp};
			//cout << i << " " << to << " " << graph[i][j].cost << endl;
		}
	}
	dijkstra(0);
	cout << d[V - 1] << endl;
	return 0;
}

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

typedef long long llong;

const int MAXN = 15;

llong cnt[MAXN];

int main()
{
  cnt[0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    cnt[i] = 1;
    for (int j = 1; j < i; ++j) {
      cnt[i] += cnt[j];
    }
  }
  char s[MAXN];
  scanf("%s", s);
  int n = strlen(s);
  llong ans = 0;
  for (int i = 0; i < n; ++i) {
    llong now = 0;
    for (int j = i; j < n; ++j) {
      now = now * 10 + s[j] - '0';
      ans += now * cnt[i] * cnt[n - j - 1];
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<iostream>
const int maxn = 1001000;
int a[maxn],b[maxn];
int s[maxn],p[maxn];
inline int cmpa(int a,int b) {
	return s[a]>s[b];
}
inline int cmpb(int a,int b) {
	return p[a]>p[b];
}
int main() {
	std::ios::sync_with_stdio(false);
	int n;
	std::cin >> n;
	for(int i=1; i<=n; ++i)
		std:: cin >> ((i&1)?a[i+1>>1]:b[i>>1]);
	for(int i=1; i<<1<=n; ++i)
		++s[a[i]],++p[b[i]];
	std::sort(a+1,a+n/2+1,cmpa);
	std::sort(b+1,b+n/2+1,cmpb);
	std::unique(a+1,a+n/2+1);
	std::unique(b+1,b+n/2+1);
	int ans=n;
	a[3]=1e5+20;
	b[3]=1e5+10;
	for(int i=1; i<=3; ++i)
		for(int j=1; j<=3; ++j) {
			if(a[i] != b[j])
				ans=std::min(ans,n-s[a[i]]-p[b[j]]);
			ans=std::min(ans,n-s[a[i]]);
			ans=std::min(ans,n-p[b[j]]);
		}
	std::cout << ans;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

ll N, M, X;
ll C[15];
ll A[15][15];
ll ans = INF;

void solved(vl vec, ll n, ll money) {
    if(n == N) {
        for(ll i = 0; i < vec.size(); i++) {
            if(vec[i] < X) {
                return;
            }
        }
        ans = min(money, ans);
        return;
    }
    solved(vec, n + 1, money);
    for(ll i = 0; i < M; i++) {
        vec[i] += A[n][i];
    }
    solved(vec, n + 1, money + C[n]);
}

int main() {
    cin >> N >> M >> X;

    for(ll i = 0; i < N; i++) {
        cin >> C[i];
        for(ll j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }
    vl alg(M, 0);
    solved(alg, 0, 0);
    if(ans != INF) {
        cout << ans << endl;
    } else {
        cout << "-1" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int N;

long long comb(int num) {
	if (num <= 1)return 0;
	long long ans = 0;
	for (int i = 1; i < num; i++) {
		ans += num - i;
	}
	return ans;
}

int main() {
	cin >> N;
	vector<vector<char> > s(N, vector<char> (10));
	vector<string> str(N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> s[i][j];
		}
		sort(s[i].begin(), s[i].end());
		for (int j = 0; j < 10; j++) {
			str[i] += s[i][j];
		}
	}
	sort(str.begin(), str.end());

	long long ans = 0;
	long long now = 1;
	for (int i = 1; i < N; i++) {
		if (str[i] == str[i - 1]) {
			now++;
		}
		else {
			ans += comb(now);
			now = 1;
		}
	}
	ans += comb(now);
	cout << ans << endl;
}

Measured memory_bytes: 12800
s = input()
n = len(s)


even0 = 0
even1 = 0
odd0 = 0
odd1 = 0

for i in range(n):
    if i%2 == 0:
        if s[i] == "0":
            even0 += 1
        else:
            even1 += 1
    else:
        if s[i] == "0":
            odd0 += 1
        else:
            odd1 += 1
print(min(n-even0-odd1,n-odd0-even1))

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

int main() {
	string S;
	int w;
	cin >> S >> w;
	vector<char> res;
	for (int i=0; i<S.size(); ++i) {
		if ((i % w) == 0) res.push_back(S[i]); 
	}
	res.push_back('\0');
	string s_res(res.data());
	cout << s_res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  int count=0;
  rep(i,s.size()-2){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import std;

long calcEven(int[] a) {
    assert(a.length % 2 == 0);

    long sum1 = 0;
    long sum2 = 0;
    for (int i = 0; i < a.length; i += 2) {
        sum1 += a[i];
        sum2 += a[i+1];
    }
    return max(sum1, sum2);
}

long calc(int[] a) {
//    if (a.length % 2 == 0) return calcEven(a);

    alias Key = Tuple!(int, int);

    long ans = long.min;
    long rec(int p, int rest, ref long[Key] memo) {
        if (p >= a.length) {
            return 0;
        }

        if (Key(p, rest) in memo) {
            long m = memo[Key(p, rest)];
            return m;
        }

        long x = rec(p + 2, rest, memo) + a[p];
        if (rest > 0) {
            x = max(x, rec(p + 1, rest - 1, memo));
        }
        return memo[Key(p, rest)] = x;
    }

    long[Key] memo;
    return rec(0, a.length % 2 == 0 ? 1 : 2, memo);

}

void main() {
    readint;
    auto a = readints;
    writeln(calc(a));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


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

#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
//#define mo 998244353
string str;
//map<int, int>::iterator itr; 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    int c=INT_MAX;
    for(int i=0;i<=s.size()-t.size();i++){
        int co=0;
        for(int j=0;j<t.size();j++){
            if(s[i+j]!=t[j]){
                co++;
            }
        }
        c=min(c,co);
    }
    cout<<c;
    return 0;
}


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

int x,a[1100],c[1100],d[1100],b[1100],maks=0,numb=0,H;
int main(){
    cin>>x;
    for(int i=1;i<=x;i++){
        cin>>a[i];
    }
    for(int m=1;m<=1000;m++){
        d[m]=m;
    }
    for(int k=1;k<=x;k++){
        c[k]=0;
    }
    for(int l=1;l<=x;l++){
        for(int z=1;z<=1000;z++){
        if(a[l]==d[z]){
            c[z]++;
        }
        }
    }
    for(int p=1;p<=1000;p++){
        if(c[p]>=1){
            b[p]=c[p]-1;
        }
        else if (c[p]==0){
            b[p]=0;
        }
    }
    for(int n=1;n<=1000;n++){
        numb+=b[n];
    }
   cout<<x-numb;
    }

Measured memory_bytes: 3636
#!/usr/bin/env python3
import sys


def solve(K: int, N: int, A: "List[int]"):
    mx = 0
    for i in range(len(A) - 1):
        if A[i + 1] - A[i] > mx:
            mx = A[i + 1] - A[i]
    if A[0] + K - A[-1] > mx:
        mx = A[0] + K - A[-1]
    print(K - mx)



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(K, N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 26228
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, sum[1000000], ans, dp[110000];
Pll a[200000], b[2000000];
string str, ss, dd;
bool f[2000][2000],ff;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
vector<Pll>v;
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n;
	dp[0] = 2;
	dp[1] = 1;
	rep(i, 100) {
		dp[i + 2] = dp[i] + dp[1 + i];
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 4608
#include<stdio.h>
int main(void)
{int a,b;
  scanf("%d %d",&a,&b);

  if(a<b)
    printf("a < b\n");
  if(a>b)
    printf("a > b\n");
  if(a==b)
    printf("a == b\n");

  return(0);

}

Measured memory_bytes: 580
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;

int N,M;
int a[305][305];
int b[305][305];

signed main(){
    cin>>N>>M;
    set<int> st;
    rep(i,N){
        rep(j,M){
            cin>>a[i][j];
            a[i][j]--;
            st.insert(j);
        }
    }
    int ans=301;
    while(!st.empty()){
        map<int,int> mp;
        for(int i=0;i<N;i++){
            for(int j=0;j<M;j++){
                if(st.count(a[i][j])){
                    mp[a[i][j]]++;
                    break;
                }
            }
        }
        int cnt=0;
        for(auto pp:mp){
            chmax(cnt,pp.sc);
        }
        chmin(ans,cnt);
        set<int> ss;
        for(auto pp:mp){
            if(cnt==pp.sc){
                ss.insert(pp.ft);
            }
        }
        for(int s:ss) st.erase(s);
    }
    cout<<ans<<endl;
}

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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 600010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,k;

char s[maxn];

int A[maxn];

void Work(){
	int now=0,l=1,r=n;
	REP(i,1,n*2){
		if((A[l]^now))A[l]^=1;
		else{
			l++;A[++r]=now;
			now^=1;
		}
		if(!--k){
			REP(j,l,r)printf("%c",'A'+(!(A[j]^now)));puts("");
			return;
		}
	}
	REP(i,l,r)A[i]^=now;
	if((n&1)&&(k&1))A[l]^=1;
	REP(i,l,r)printf("%c",'A'+(!A[i]));puts("");
}

void Init(){
	read(n,k);
	scanf("%s",s+1);
	REP(i,1,n)A[i]=!(s[i]-'A');
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
using P = pair<ll,ll>;

int main(){
        ll n;
        scanf("%ld", &n);
        vector<vector<ll>> link(n, vector<ll>(0));
        vector<P> edges(n-1);
        for(ll i=0; i<n-1; i++){
                scanf("%ld %ld", &edges[i].first, &edges[i].second);
                link[edges[i].first-1].push_back(edges[i].second-1);
                link[edges[i].second-1].push_back(edges[i].first-1);
        }

        vector<ll> used(n,0);
        ll ansc = 1;
        map<P, ll> ans;

        queue<P> que;
        que.push(P(0,0));
        while(!que.empty()){
                ll here, color;
                tie(here, color) = que.front();
                que.pop();

                ansc = max(ansc, color);
                used[here] = 1;

                ll i=1;
                for(ll v: link[here]){
                        if(!used[v]){
                                if(color==i) i++;
                                que.push(P(v, i));
                                ans[P(min(here,v)+1,max(here,v)+1)] = i;
                                i++;
                        }
                }
        }

        printf("%ld\n", ansc);
        for(P p: edges){
                printf("%ld\n", ans[p]);
        }
        return 0;
}


Measured memory_bytes: 15232
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[])=>{for(let i=0;i<a.length;i+=2)if(s==a[i])return a[i+1]};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};
const main = ()=>{
  out(or(nin(),3,5,7)?'YES':'NO');
}
main();

Measured memory_bytes: 7500
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		String S = nextString();
		ArrayList<String> sb = new ArrayList<>();
		int revFlg=-1;
		int Q = nextInt();
		int T=0 ;
		int F=0;
		char[] head = new char[Q];
		char[] tail = new char[Q];
		int hi=0;
		int ti=0;

		Arrays.fill(head, ' ');
		Arrays.fill(tail, ' ');

		char C=' ';
		for(int i=0;i<Q;i++){
			T=nextInt();
			if(T==2){
				F=nextInt();
				C=nextString().charAt(0);
			}
			if(T==1){
				revFlg*=-1;
			}else{
				if(F==1){
					if(revFlg==-1){
						head[hi]=C;
						hi++;
					}else{
						tail[ti]=C;
						ti++;
					}
				}else{
					if(revFlg==-1){
						tail[ti]=C;
						ti++;
					}else{
						head[hi]=C;
						hi++;
					}
				}
			}
			//System.out.println(i);
		}
		StringBuffer b ;
		String ans="";
		if(revFlg==-1){
			b=new StringBuffer();
			b.append(head);
			ans=b.reverse().toString().trim();

			b=new StringBuffer();
			b.append(S);
			ans+=b.toString().trim();

			b=new StringBuffer();
			b.append(tail);
			ans+=b.toString().trim();

		}else{
			b=new StringBuffer();
			b.append(tail);
			ans=b.reverse().toString().trim();

			b=new StringBuffer();
			b.append(S);
			ans+=b.reverse().toString().trim();

			b=new StringBuffer();
			b.append(head);
			ans+=b.toString().trim();
		}


		System.out.println(ans);
	}



	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

using namespace std;

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < sz(v);i++)


int main(){
    int n;
    int buf;
    vector<int> a;
    cin>>n;
    REP(i,n){
        cin>>buf;
        a.pb(buf);
    }
    sort(all(a),greater<int>());

    int x,y;
    int bd=2147483647;
    y=0;
    x=a[0];

    REP3(i,1,n){
        if(abs(x/2-a[i])<abs(x/2-y))y=a[i];
        if(abs(x/2-a[i])>bd)break;
        bd=abs(x/2-a[i]);
    }
    cout<<x<<" "<<y<<endl;


    return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
int GCD(int, int);



int main(void)
{
  int x, y, tmp, num; // numは最大公約数

  scanf("%d %d", &x, &y);

  if(y > x){
    tmp = x;
    x = y;
    y = tmp;
  }

  num = GCD(x, y);

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

  return 0;
}


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

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

int N;
const int MAX=101;
int  A[MAX];



void print(){
	for(int i=0;i<N;i++){
		if(i==0)
			cout<<A[i];
		else{
			cout<<" "<<A[i];
		}

	}
	cout<<endl;
}
void insertionsort(int A[]){
	print();
	for(int i=1;i<N;i++){
		for(int j=i;j>=0;j--){
			if(A[j]<A[j-1]){
				swap(A[j-1],A[j]);
			}
		}
		print();
	}
}

int main()
{
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	insertionsort(A);
	return 0;
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 15, M = 10;

int k;
int res[N];

void solve(int len, int t)
{
	if (len == t)
	{
		k -- ;
		if (!k)
		{
			for (int i = 0; i < len; i ++ ) cout << res[i];
			puts("");
			exit(0);
		}
		return;
	}
	
	for (int i = 0; i < M; i ++ )
		if (!(!i && !t) && (!t || abs(res[t - 1] - i) <= 1))
		{
			res[t] = i;
			solve(len, t + 1);
		}
}

int main()
{	
	cin >> k;
	for (int i = 1; i < N; i ++ ) solve(i, 0);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main () {
    int n, W;
    cin >> n >> W;
    vector <long long> dp(W + 1, 0);
    for (int i = 1; i <= n; i ++) {
        int v, w;
        cin >> v >> w;
        for (int j = W - v; j >= 0; j --) {
            dp[j + v] = max(dp[j + v], dp[j] + w);
        }
    }
    cout << dp[W];
    return 0;
}


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

typedef long long ll;

int n, m;

vector<pair<ll, ll>> p(100010);

int main(){
    cin >> n >> m;
    for (int i = 0; i < n; i++){
        cin >> p[i].first >> p[i].second;
    }
    p.resize(n);

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

    ll money = 0;
    ll cnt = 0;
    for (int i = 0; i < n; i++){
        if (cnt + p[i].second < m){
            money += p[i].first*p[i].second;
            cnt += p[i].second;
        } else {
            money += p[i].first * (m - cnt);
            cnt = m;
            break;
        }
    }

    cout << money << endl;
}




Measured memory_bytes: 1792
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Split(' ');

        var d = new int[n];
        for (int i = 0; i < n; i++)
        {
            d[i] = int.Parse(s[i]);
        }

        Array.Sort(d, (x1, x2) => x2 - x1);

        var left = m1(0, d);
        var right = m1(left.Item2, d);
        Console.WriteLine((long)left.Item1 * right.Item1);
    }

    static Tuple<int, int> m1(int i, int[] d)
    {
        for (; i < d.Length - 1; i++)
        {
            if (d[i] == d[i + 1])
            {
                return Tuple.Create(d[i], i + 2);
            }
        }
        return Tuple.Create(0, 0);
    }
}

Measured memory_bytes: 20576
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <queue>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

vector<int> node[100005];
vector<int> route;
bool U[100005];

bool dfs(int n, int g)
{
	if (U[n])return false;
	U[n] = true;
	route.push_back(n);
	if (n == g)
	{
		return true;
	}
	REP(i, node[n].size())
	{
		if (dfs(node[n][i], g))
		{
			return true;
		}
	}
	route.pop_back();
	return false;
}

int main()
{

	int N;
	cin >> N;

	REP(i, N - 1)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		node[a].push_back(b);
		node[b].push_back(a);
	}

	fill(U, U + N, false);
	dfs(0, N - 1);

	int fn = route[(route.size() + 1) / 2 - 1];
	int sn = route[(route.size() + 1) / 2];
	REP(i, node[fn].size())
	{
		if (node[fn][i] == sn)
		{
			node[fn].erase(node[fn].begin() + i);
			break;
		}
	}

	int fNum = 0;
	queue<int> q;
	q.push(0);
	fill(U, U + N, false);
	while (!q.empty())
	{
		fNum++;
		int n = q.front();
		q.pop();
		U[n] = true;
		REP(i, node[n].size())
		{
			int c = node[n][i];
			if (U[c])continue;
			q.push(c);
		}
	}

	if (fNum > N - fNum)
	{
		cout << "Fennec";
	}
	else
	{
		cout << "Snuke";
	}

	return 0;
}

Measured memory_bytes: 11000
N = int(input())
al = [chr(i) for i in range(97, 97+26)]
ans = ""
while True:
    temp = N % 26
    ans = al[temp-1] + ans
    if N // 26 == 0:
        break
    else:
        if N == 26:
            break
        if N % 26 == 0:
            N = N // 26 - 1
        else:
            N = N // 26

print(ans)


Measured memory_bytes: 9088
/*
 Author: nilesh8757
 */
#include<bits/stdc++.h>
 using namespace std;

#define FIO                     ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod                     1000000007
#define eps                     1e-9
#define setbits                 __builtin_popcount
#define gcd                     __gcd
#define rep(i,a,b)              for(int i=a;i<=b;i++)
#define repr(i,b,a)             for(int i=b;i>=a;i--)
#define forn(i,n)               for(int i=0;i<n;i++)
#define all(a)                  a.begin(), a.end()
#define in(a,b)                 ( (b).find(a) != (b).end())
#define pb                      push_back
#define fill(a,v)               memset(a, v, sizeof a)
#define endl                    "\n"
#define ff                      first
#define ss                      second
#define mp                      make_pair
#define minin(a)                *min_element (all(a))
#define maxin(a)                *max_element(all(a))
#define asort(c)                sort(all(c))
#define dsort(c)                sort(all(c), greater<int>()) 
#define PI                      3.14159265358979323846
#define int                     long long
typedef  vector<int>                 vi;
typedef  pair<int, int>              ii;
typedef  vector<ii>                 vii;
typedef  set<int>                    si;
typedef  map<int, int>              mii;
typedef  long double                 ld;


clock_t time_p=clock();
void timer()
{
    time_p=clock()-time_p;
    cerr<<"Execution Time: "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

int32_t main()
{
  FIO

  int n;
  cin>>n;
  string last,w;
  //last="-1";
  map<string , int> yes;
  cin>>w;
  last=w;
  yes[w]++;
  forn(i,n-1)
  {
  	cin>>w;
  	
       
       if(yes[w]>0)
       {
        cout<<"No"; exit(0);
       }
       else
       {
       	
       	 if(w.front()!=last.back())
         {
         	cout<<"No"; exit(0);
         }
       }
       yes[w]++;
  	   last=w;
  }
  cout<<"Yes";
  timer();
  return 0;
}  

Measured memory_bytes: 256
from collections import deque

N, K = list(map(int,input().split()))
ab = [list(map(int, input().split())) for _ in range(N - 1)]
MOD = 1000000007
if N == 1:
    print(K)
    exit()

tree = [[] for _ in range(N)]

for i in range(N - 1):
    tree[ab[i][0] - 1].append(ab[i][1] - 1)
    tree[ab[i][1] - 1].append(ab[i][0] - 1)


ans = K * (K - 1) % MOD

first = 0
for i in range(N):
    if len(tree[i]) == 1:
        first = i
        break

q = deque([[first, tree[first][0]]])

while q:
    parent, child = q.pop()
    count = 2
    for i in range(len(tree[child])):
        if tree[child][i] != parent:
            q.append([child, tree[child][i]])
            ans = ans * (K - count) % MOD
            count += 1

print(ans)


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

int main() {
    lint H, W, M;
    cin >> H >> W >> M;
    vector<pair<lint, lint>> A(M);
    rep(i, M) cin >> A[i].first >> A[i].second;

    map<lint, set<lint>> R, C;
    rep(i, M) {
        R[A[i].first].insert(A[i].second);
        C[A[i].second].insert(A[i].first);
    }

    vector<int> candidate_R(0);
    lint ma_R = -1;
    for (auto p : R) {
        ma_R = max(ma_R, (lint)p.second.size());
    }
    for (auto p : R) {
        if (p.second.size() == ma_R) candidate_R.push_back(p.first);
    }

    vector<int> candidate_C(0);
    lint ma_C = -1;
    for (auto p : C) {
        ma_C = max(ma_C, (lint)p.second.size());
    }
    for (auto p : C) {
        if (p.second.size() == ma_C) candidate_C.push_back(p.first);
    }

    // dump(candidate_R);
    // dump(candidate_C);
    dd(ma_R, ma_C);
    lint ans = ma_R + ma_C - 1;
    for (int i = 0; i < candidate_R.size(); i++) {
        for (int j = 0; j < candidate_C.size(); j++) {
            if (C[candidate_C[j]].count(candidate_R[i]) != 1) {
                ans = ma_R + ma_C;
                break;
            }
        }
    }

    cout << ans << endl;
    // rep(i, M) {
    //     B[i].first  = A[i].second;
    //     B[i].second = A[i].first;
    // }

    // sort(A.begin(), A.end());
    // sort(B.begin(), B.end());

    // rep(i, M) { cout << A[i].first << ' ' << A[i].second << endl; }
    // cout << '=' << endl;
    // rep(i, M) { cout << B[i].first << ' ' << B[i].second << endl; }

    // map<lint, lint> mpH, mpW;
    // rep(i, M) {
    //     mpH[A[i].first]++;
    //     mpW[B[i].first]++;
    // }
    // for (auto p : R) {
    //     d(p.first);
    //     dump(p.second);
    // }

    // for (auto p : C) {
    //     d(p.first);
    //     dump(p.second);
    // }
    return 0;
}

Measured memory_bytes: 96496
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  	long N, A, B;
  
  	cin >> N >> A >> B;
  
  	if (A == 0) {
      cout << 0 << endl;
      return 0;
    } else if (N < A) {
      cout << N << endl;
      return 0;
    } else if ((A + B) >= N) {
      cout << A << endl;
      return 0;
    } else if (B == 0) {
      cout << N << endl;
      return 0;
    }
  
  	long count = 0;
  	long waru = N / (A + B);
  	count = waru * A;
  
  	long amari = N % (A + B);
  	if (amari > A) {
      count += A;
    } else {
      count += amari;
    }
  	cout << count << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define en '\n'
#define pb push_back
#define mp make_pair
#define P pair<int, int>

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;

struct aaa {
	aaa() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
}aaaaa;

int main() {
	int a[4];
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	int c1 = 0, c4 = 0, c7 = 0, c9 = 0;
	for (int i = 0; i < 4; i++) {
		if (a[i] == 1) c1++;
		else if (a[i] == 4) c4++;
		else if (a[i] == 7) c7++;
		else if (a[i] == 9) c9++;
	}
	if (c1 == 1 && c4 == 1 && c7 == 1 && c9 == 1) {
		cout << "YES" << en;
	}
	else {
		cout << "NO" << en;
	}
}

Measured memory_bytes: 256
s = input()
if(s=='RRR'):
  ans = 3
elif(s[0:2]=='RR' or s[1:3]=='RR'):
  ans = 2
elif(s[0]=='R' or s[1]=='R' or s[2]=='R'):
  ans = 1
else:
  ans = 0

print(ans)

Measured memory_bytes: 9048
#include<cstdio>
#include<cmath>
#include<malloc.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
	int A,B,C,D,s;
	int m,n;
	while(~scanf("%d %d %d %d",&A,&B,&C,&D))
	{
		m=A*B;
		n=C*D;
		if(m>=n)
		printf("%d\n",m);
		else
		printf("%d\n",n);
	}
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  ll r = 1e9;
  for (int i = 0; i < s.size() - 2; i++) {
    r = min(r, abs(100ll * (s[i] - '0') + 10ll * (s[i + 1] - '0') + (s[i + 2] - '0') - 753ll));
  }
  cout << r << endl;
}


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

int main(){
    int N,K,r,ans=0;
    map<int,int> mp;
    vector<int> cnt;
    cin>>N>>K; 
    rep(i,0,N){cin>>r;++mp[r];} r=0;
    for(auto i=mp.begin();i!=mp.end();++i){cnt.push_back(i->second);++r;}
    sort(cnt.begin(),cnt.end());
    rep(i,0,r-K) ans+=cnt[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 10748