akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
signed main()
{
    int n; cin>>n;
    vector<int>v(n);
    vector<int>u(n);
    rep(i,n)cin>>v[i];
    rep(i,n)cin>>u[i];
    vector<bool>def(n,false);
    if(v[n-1]!=u[0])return puts("0")*0;
    def[0]=def[n-1]=true;
    for(int i=0; i<n;i++){
        if(i==0)continue;
        if(v[i-1]!=v[i]){
            def[i]=true;
            if(u[i]<v[i])return puts("0")*0;
        }
    }
    for(int i=n-1; i>=0;i--){
        if(i==n-1)continue;
        if(u[i]!=u[i+1]){
            def[i]=true;
            if(v[i]<u[i])return puts("0")*0;
        }
    }
    
    int ans=1;
    int MOD=INF+7;
    for(int i=0;i<n;i++){
        if(def[i])continue;
        ans*=min(v[i],u[i]);
        ans%=MOD;
    }
    cout<<ans%MOD<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	int n, l, sum = 0, k, min = INT_MAX;
	cin >> n >> l;

	int origi[n];

	for(int i = 0; i < n; i++){
		origi[i] = l + i;
		sum = sum + origi[i];
	}
	
	int sum2 = sum;

	for(int i = 0; i < n; i++){
		sum = sum - origi[i];
		if(abs(sum2 - sum) < min){
			min = abs(sum2-sum);
			k = i;
		}
		sum = sum + origi[i];

	}	
	int ans = sum - origi[k];
	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 256
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,m,x;
   cin >> n >> m >> x;
   vector<int> a(n+1),b(m+1);
   f(i,1,n+1){
      cin >> a[i];
   }
   f(i,1,m+1){
      cin >> b[i];
   }
   vector<int> pre(m+1);
   f(i,1,m+1){
      pre[i] = pre[i-1]+b[i];
   }
   int ans = upper_bound(all(pre),x)-pre.begin()-1;
   int cur = 0;
   f(i,1,n+1){
      cur += a[i];
      if(cur > x) break;
      int d = x-cur;
      auto k = upper_bound(all(pre),d)-pre.begin();
      ans = max(ans,i+k-1);
   }


   cout << ans << '\n';
   return 0;
}

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

using namespace std;

int main(){
  int n,w,v;
  while(cin >> n >> w, n){
    int N = 0;
    double p[11] = {0},d = 0,ans = 0;
    for(int i = 0 ; i < n ; i++){
      cin >> v; p[v/w]++;
      N = max(N,v/w);
      d = max(d,p[v/w]);
    }
    for(int i = 0 ; i < N ; i++){
      ans += (p[i]/d)*((double)(N-i)/N);
    }
    printf("%f\n",ans+0.01);
  }
  return 0;
}

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

#define maxn
#define FOR(i, l, r) for (int i=l; i<=r; ++i)
#define FORD(i, r, l) for (int i=r; i>=l; --i)
#define REP(i, r) for (int i=0; i<(int)r; ++i)
#define REPD(i, r) for (int i=(int)r-1; i>=0; --i)
#define fi first
#define se second
#define mk make_pair
#define nil NULL
#define y0 y902
#define y1 y232
#define x0 x92
#define x1 x899
#define next asdfa
#define sz size
#define Debug(X) {cerr << #X << " = " << X << '\n';}
#define PR(A, n) {cerr << #A << " = "; FOR(i, 1, n) cerr << A[i] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; REP(i, n) cerr << A[i] << ' '; cerr << '\n';}
typedef long long ll;
typedef double db;
typedef pair<db, db> dd;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int inf = 1e9;
template<class T> int getbit(T x, int pos) {return (x>>(pos-1)) & 1;}
template<class T> void turn_on(T &x, int pos) {x = x | ((T)1<<(pos-1));}
template<class T> void turn_off(T &x, int pos) {x = x & ~((T)1<<(pos-1));}
template<class T> T sqr(T a) {return a*a;}

int main() {
    //freopen("orprob.inp", "r", stdin);
    //freopen("orprob.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0);
    ll A, B;
    cin >> A >> B;
    bool ok = false;
    ll res = 1;
    FORD(i, 61, 1) {     ///Notice
        if (getbit(A, i)==1) continue;
        if (ok) res += (1LL<<(i-1));
        else if (getbit(B, i)==1) {
            ok = true;
            bool check = true;
            int p = i-1;
            while (p>0 && getbit(B, p)==0) --p;
            //if (p==i-1) {res += (1LL<<p); continue;}
            FORD(j, i-1, p+1) {
                if (getbit(A, j)==1) check = false;
            }
            if (check) {
                res += (1LL<<(i-1));
                continue;
            }
            res += (1LL<<p);
            FORD(j, i-1, 1) {
                if (getbit(A, j)==0) res += (1LL<<(j-1));
            }
            res++;
        }
    }
    cout << res;
}



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

#define ll long long
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
#define vi vector < int >
#define pii pair < int, int >

const int N = 1e5 + 7;
const int mod = 1e9 + 7;

ll dp[N][2];
int n;

vi g[N];

void dfs (int v = 1, int p = 0){
    dp[v][0] = dp[v][1] = 1;
    for (int to : g[v]){
        if (to != p){
            dfs(to, v);
            dp[v][0] = (dp[v][0] * (dp[to][0] + dp[to][1])) % mod;
            dp[v][1] = (dp[v][1] * dp[to][0]) % mod;
        }
    }
}

main(){
    scanf("%d", &n);
    for (int i = 1; i < n; i++){
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].pb(b);
        g[b].pb(a);
    }
    dfs();
    printf("%lld", (dp[1][0] + dp[1][1]) % mod);
}


Measured memory_bytes: 14208
n=int(input())
arr = list(map(int,input().split()))
cur = 0
seq=1
ans=0
for i in range(n):
    if cur==arr[i]:
        seq+=1
    else:
        cur=arr[i]
        ans+=seq//2  
        seq=1
else:
    ans+=seq//2
print(ans)


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

int main() {
  int n;
  cin>>n;
  if (n==111) {
    cout<<999<<endl;
  }
  else if (n==119) {
    cout<<991<<endl;
  }
  else if (n==191) {
    cout<<919<<endl;
  }
  else if (n==199) {
    cout<<911<<endl;
  }
  else if (n==911) {
    cout<<199<<endl;
  }
  else if (n==919) {
    cout<<191<<endl;
  }
  else if (n==991) {
    cout<<119<<endl;
  }
  else if (n==999) {
    cout<<111<<endl;
  }
  
}


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

int main(){
  int N;
  cin >> N;
  vector <string> vec(N);
  for(int m=0; m<N; m++){
    cin >> vec.at(m);
  }
  for(int i=0; i<N; i++){
    if(vec.at(i) == "Y"){
      cout << "Four" << endl;
      break;
    }
    else {
      if(i == N-1){
      cout << "Three" << endl;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N;
	string S;

	cin >> N;
	cin >> S;
	int cnt = 0;

	for (int i = 0; i < N - 2; i++)
	{
		if (S.substr(i, 3) == "ABC")
			cnt++;
	}
	cout << cnt << endl;
}



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


int main(){
 int a, b, c, d, e, k;
 cin >> a >> b >> c >> d >> e >> k;

 if((e-a)>k) cout << ":(" << endl;
 else cout << "Yay!" << endl;
   }


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

namespace _0017
{
    public class Program

    {
        public static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string res = string.Join("", line.Select(x => ('a' <= x && x <= 'z') ? Char.ToUpper(x) : x));
            Console.WriteLine(res);              
        }
    }
}


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

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
//const------------------------------------------------------------------------------------------------------------------------
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;

//global-----------------------------------------------------------------------------------------------------------------------
LL a, b, n, ans = 0;
vector<LL> ar;
vector<LL> sum_ar;
//#define DEBUG
//function--------------------------------------------------------------------------------------------------------------------

int main() {
	while ( scanf( "%lld", &n ) && n ) {
		sum_ar.PB( 0 );
		ans = -INF;
		rep( i, n ) {
			scanf( "%lld", &a );
			ans = max( a, ans );
			sum_ar.PB( sum_ar[ i ] + a );
		}
		rep( i, n ) {
			FOR( j, i + 1, n + 1 ) {
#ifdef DEBUG
				debug(i)
				debug(j)
#endif
				ans = max( ans, sum_ar[ j ] - sum_ar[ i ] );
			}
		}
		printf( "%lld\n", ans );
		sum_ar = vector<LL>();
	}
	return 0;
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define pcnt(b) __builtin_popcount(b)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,a,b,pass=0;
    string s;
    cin>>n>>a>>b>>s;
    string ans[n];
    int bc=0;
    rep(i,0,n){
        if(s[i]=='c'){ans[i]="No";}
        else if(s[i]=='a'){
            if(pass<a+b){
                ans[i]="Yes";
                pass++;
            }
            else{
                ans[i]="No";
            }
        }
        else{
            if(bc<b&&(pass<a+b)){
                ans[i]="Yes";
                pass++;
            }
            else{
                ans[i]="No";
            }
            bc++;
        }
    }
    rep(i,0,n){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 6224
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

const int N=55;
const int MAX_S=2501;
vector<tuple<int,int,int>>edges[N];
int n,m,S;
vector<pair<int,int>>_exchange;

void dijkstra(int s)
{
  vector<vector<ll>>dist(n,vector<ll>(MAX_S,1e15));
  dist[s][S]=0;
  priority_queue< pair<ll,pair<int,int>>, vector<pair<ll,pair<int,int>>>,greater< pair<ll,pair<int,int>> > >pq; //{dist,{src,silver_coins}}
  pq.push({0,{s,S}});

  while(!pq.empty()){
    int curr_dist=pq.top().first;
    int node=pq.top().second.first;
    int silver=pq.top().second.second;
    pq.pop();
    if(dist[node][silver]<curr_dist)  continue;

    for(auto x:edges[node]){
      if(get<1>(x)<=silver){
        if( dist[get<0>(x)][silver-get<1>(x)] > dist[node][silver]+get<2>(x) ){
          dist[get<0>(x)][silver-get<1>(x)] = dist[node][silver]+get<2>(x);
          pq.push({dist[get<0>(x)][silver-get<1>(x)],{get<0>(x),silver-get<1>(x)}});
        }
      }
    }
    int new_s=min(MAX_S-1,silver+_exchange[node].first);
    if(dist[node][new_s]>dist[node][silver]+_exchange[node].second){
      dist[node][new_s]=dist[node][silver]+_exchange[node].second;
      pq.push({dist[node][new_s],{node,new_s}});
    }
  }

  for(int i=1;i<n;i++){
    int ans=1e15;
    for(int k=0;k<MAX_S;k++){
      ans=min(ans,dist[i][k]);
    }
    cout<<ans<<"\n";
  }
}
signed main(){
  fastio
  cin>>n>>m>>S;
  S=min(S,MAX_S-1);  //check with bigger limits
  for(int i=0;i<m;i++){
    int u,v,cost_req,time_req;cin>>u>>v>>cost_req>>time_req;
    u--;v--;
    edges[u].emplace_back(v,cost_req,time_req);
    edges[v].emplace_back(u,cost_req,time_req);
  }
  for(int i=0;i<n;i++){
    int silver,time;cin>>silver>>time;
    _exchange.emplace_back(silver,time);
  }
  dijkstra(0);
  return 0;
}

Measured memory_bytes: 7280
#include <stdio.h>

int main(void){
    int mod = 1000000007;
    int N, M;
    scanf("%d%d", &N, &M);
    long fib[N+1]; //fib[i] は i+1段の段数がある時の上りの数
    fib[0] = 1;
    fib[1] = 1;
    fib[2] = 2;
    for (int i = 3; i < N+1; i++){
        fib[i] = (fib[i-2] + fib[i-1]) % mod;
    }
    
    int a[M+1];
    a[0] = -1;
    long ans = 1;
    for (int i = 1; i < M+1; i++){
        scanf("%d", &a[i]);
        if(a[i] - a[i-1] == 1){
            printf("%d\n", 0);
            return 0;
        }
    }
    for (int i = 1; i < M+1; i++){
        ans *= fib[(a[i] - a[i-1]) - 2];
        ans = ans%mod;
    }
    ans *= fib[N-a[M]-1];
    ans = ans%mod;
    printf("%ld\n", ans);
    return 0; 
}


Measured memory_bytes: 1152
x = gets.to_i

(-1000..1000).each{|a|
  a5 = a**5
  b5 = a5-x
  ub = 1000
  lb = -1000
  32.times{|j|
    mid = (ub+lb)/2
    if b5 <= mid**5
      ub = mid
    else
      lb = mid
    end
  }
  if ub**5 == b5
    puts [a,ub]*" "
    exit
  end
}

Measured memory_bytes: 14336
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;

using namespace std;
using Graph = vector<vector<int>>;
Graph G;

/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}

int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/
int main()
{
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	
	
	ll N, K;
	cin >> N >> K;
	ll t1 = N%K;
	ll t2 = abs(t1 - K);

	ll ans = min(t1, t2);
	

	cout << ans << endl;
	/*int N, M;
	cin >> N >> M;
	vector<int> data(N);
	double sum = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> data[i];
		sum += data[i];
	}
	int cnt = 0;
	for (auto& i : data)
	{
		if (i >= sum / (4 * M)) cnt++;
	}
	
	if (cnt>=M)
	{
		cout << "Yes" << endl;

	}
	else
	{
		cout << "No" << endl;
	}*/
	
	return 0;

}


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

using namespace std;

int n, k;
int a[maxn];

int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1;i <= n;i++) scanf("%d", &a[i]);
	for(int i = k + 1;i <= n;i++){
		if(a[i] > a[i - k]) puts("Yes");
		else puts("No");
	}
}

Measured memory_bytes: 4540
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var n, p int
	fmt.Scan(&n)

	sc.Split(bufio.ScanWords)
	ps := []int{}
	for i := 0; i < n; i++ {
		p = nextInt()
		ps = append(ps, p)
	}

	count := 0
	for i := 1; i < n-1; i++ {
		if (ps[i] > ps[i-1] && ps[i] < ps[i+1]) || (ps[i] < ps[i-1] && ps[i] > ps[i+1]) {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			int count = 0;
			for(;n!=1;){
				if(n%2 == 0){
					n /= 2;
				}else{
					n*=3;
					n+=1;
				}
				count++;
			}
			System.out.println(count);
		}

	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

}

Measured memory_bytes: 12000
#include<iostream>
#include<string>
using namespace std;
int main(){
long n,i,d[5],f[5],t=0;
string s;
while(cin>>n){
for(i=4;i>=0;i--){d[i]=n%10;n/=10;}
if(t==1)cout<<endl;
s="";for(i=0;i<5;i++){if(d[i]<5)s+='*';else s+=' ';}cout<<s<<endl;
s="";for(i=0;i<5;i++){if(d[i]>4)s+='*';else s+=' ';}cout<<s<<endl;
cout<<"====="<<endl;
for(i=0;i<5;i++){d[i]%=5;f[i]=0;}
s="";for(i=0;i<5;i++){if(f[i]==1||d[i]>0)s+='*';else{s+=' ';f[i]=1;}}cout<<s<<endl;
s="";for(i=0;i<5;i++){if(f[i]==1||d[i]>1)s+='*';else{s+=' ';f[i]=1;}}cout<<s<<endl;
s="";for(i=0;i<5;i++){if(f[i]==1||d[i]>2)s+='*';else{s+=' ';f[i]=1;}}cout<<s<<endl;
s="";for(i=0;i<5;i++){if(f[i]==1||d[i]>3)s+='*';else{s+=' ';f[i]=1;}}cout<<s<<endl;
s="";for(i=0;i<5;i++){if(f[i]==1||d[i]>4)s+='*';else{s+=' ';f[i]=1;}}cout<<s<<endl;
t=1;
}
return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define ld double
#define oo 2e18
#define OS tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

string s;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> s;
    if (s[s.size() - 1] == '1' || s[0] == '0') {
        return cout << "-1\n", 0;
    }
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '1') {
            if (s.size() - i - 2 >= 0 && s[s.size() - i - 2] != '1') {
                return cout << "-1\n", 0;
            }
        }
    }
    int last = s.size() - 1;
    for (int i = s.size() - 2; i >= 0; i--) {
        cout << i + 1 << " " << last + 1 << "\n";
        if (s[i] == '1') last = i;
    }
    return 0;
}

Measured memory_bytes: 1616
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc;
	static Map<String, Integer> wordMap = new HashMap<>();
	public static void main(String[] args){
		sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		out.println(solve());
		out.flush();
	}

	static String solve(){
		int N = sc.nextInt();
		String end = "";
		String word;
		String res = "Yes";
		for(int i=0;i<N;i++){
			word = sc.next();
			if(word.substring(0,1).equals(end)||end == ""){
				end = word.substring(word.length()-1,word.length());
				if(wordMap.containsKey(word)){
					res="No";
					break;
				}else{
					wordMap.put(word, 1);
				}
			}else{
				res="No";
				break;
			}
		}
		return res;
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 22484
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scanner=new Scanner(System.in);

		String s=scanner.next();

		List<String> data=new ArrayList<String>();

		for(int i=0;i<s.length();i++) {

			String buf=String.valueOf(s.charAt(i));

			if(!data.contains(buf)) {
				data.add(buf);
			}
		}

		for(int i='a';i<='z';i++) {

			char buf=(char)i;

			if(!data.contains(String.valueOf(buf))) {
				System.out.println(buf);
				break;
			}


		}

		if(data.size()==26) {
			System.out.println("None");
		}






		scanner.close();

	}

	public static int getsumofkakuketa(int n) {

		int result=0;

		while(true) {

			result+=n%10;

			if(n/10!=0) {
				n/=10;
			}else {
				return result;
			}
		}



	}

	public static boolean isMacthed(int a,int b,int sum) {

		if(sum>=a && sum<=b) {
			return true;
		}else {
			return false;
		}

	}



}







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

using namespace std;

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

int main() {
    string S;
    cin >> S;

    rep(i, S.size()){
        if(i % 2 == 0) cout << S.at(i);
    }
    cout << endl;
}

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

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

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

const int N = 100001;
int a[N];
vector<pair<int,int> > v;
int main() {
	ios_base::sync_with_stdio(0);

	ll n,m;
	ll sum = 0;
	cin >> n >> m;
	ll ans = INF;
	forn(i,n){
		ll x,y;
		cin >> x >> y;
		v.pb({x,y});
	}
	
	sort(all(v));
	for(int i = 0; i < v.size(); i++){
		sum += v[i].second;
		if (sum >= m){
			cout << v[i].first << endl;
			return 0;
		}
	}
  	return 0;
}




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

#define ll int64_t
const long MOD = 1e9 + 7;


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

ll lcm( ll m, ll n )//最小公倍数
{
  return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm


int main()
{
  ll a, b, n;
  a = 1;
  cin >> n;
  for (int i = 0; i < n; ++i)
  {
    a*=(i+1);
    a%=MOD;
  }

  cout << a << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    int cnt = B / A;
    if (cnt >= C) {
        cout << C << endl;
    } else {
        cout << cnt << endl;
    }
}

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

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

    std::string ans = "No";
    std::string s = std::to_string(n);
    if((s[1] == s[2]) &&((s[0] == s[1]) || (s[2] == s[3]))){
        ans = "Yes";
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const int nax=1000*1007;

int n;
ll tab[nax];

ll s;

ll pre[nax];
ll suf[nax];

ll dp[nax];

void wypisz(ll v)
{
	debug() << imie(v);
	printf("%lld %lld\n", (s+v)/2, (s-v)/2);
	exit(0);
}

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		scanf("%lld", &tab[i]);
		s+=tab[i];
	}
	ll x=0;
	for (int i=2; i<=n; i+=2)
		x+=tab[i];
	if (!(n&1))
		wypisz(max(x, s-x)-min(x, s-x));
	//~ ll wyn=max(x, s-x)-min(x, s-x);
	for (int i=1; i<=n; i++)
		pre[i]=tab[i]-pre[i-1];
	//~ for (int i=n; i; i--)
		//~ suf[i]=tab[i]-suf[i+1];
	//~ for (int i=2; i<=n; i+=2)
		//~ wyn=max(wyn, min(pre[i]+abs(suf[i+1]), abs(pre[i-1])+suf[i]));
	//~ wypisz(wyn);
	ll wyn=x-(s-x);
	
	ll bsa=-1e9;
	ll bsb=1e9;
	ll bss;
	while(bsa<bsb)
	{
		bss=(bsa+bsb+2)>>1;
		
		ll naj=0;
		for (int i=1; i<=n; i+=2)
		{
			if (pre[i]-bss>=naj)
			{
				dp[i]=1;
				naj=min(naj, -pre[i+1]);
			}
			else
			{
				dp[i]=0;
			}
		}
		
		
		
		if (dp[n])
			bsa=bss;
		else
			bsb=bss-1;
	}
	debug() << imie(bsa);
	
	wyn+=2*bsa;
	
	wypisz(wyn);
	return 0;
}


Measured memory_bytes: 12544
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
using namespace std;

ll a,b,c,k;
int main(){
	// debug;	
	ios;

	cin>>a>>b>>c>>k;
	ll ans;
	if(a >= k) ans = k;
	else if(a+b >= k) ans = a;
	else {
		ans = a-(k-a-b);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main() {
	string str;
	cin >> str;
	string rec;
	rep(i, str.length()) {
		if (str[i] == 'B') {
			if (rec.length() != 0) {
				rec = rec.erase(rec.length() - 1);
			}
		}
		else if (str[i] == '1') {
			rec = rec + "1";
		}
		else if (str[i] == '0') {
			rec = rec + "0";
		}
	}
	cout << rec << endl;
	return 0;
}

Measured memory_bytes: 256
/*input
9 2
RRRLRLRLL
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    ll n, k;
    string s;
    cin >> n >> k >> s;
    int ans = 0, cnt = 0;
    rep(i, n-1) {
        if (s[i] == s[i+1]) {
            ans++;
        }
        else if (cnt < 2*k) {
            ans++;
            cnt++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,d;
    cin >> n >>d;
    int cnt=0;
    vector<vector<int>> a(n,vector<int> (d));
    rep(i,n) rep(j,d) cin >> a[i][j];
    rep(i,n-1){
        for(int j=i+1;j<n;j++){
            int ans=0;
            rep(k,d){
                ans+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
            }
            if((int)sqrt(ans)==sqrt(ans)){
                cnt++;
            }
        }
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main{
	
	static final Scanner s=new Scanner(System.in);
	
	public static void main(String[] __){
		int w=s.nextInt(),a=s.nextInt(),b=s.nextInt();
		if(a>b) {
			int buf=a;
			a=b;
			b=buf;
		}
		System.out.println(Math.max(0,b-a-w));
	}
}

Measured memory_bytes: 21716
#define C

#ifdef C
#include <stdio.h>
#include <string.h>
#define abs(a) ((a) < 0 ? -(a) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define isdigit(a) ((a) >= '0' && (a) <= '9' ? true : false)
#endif
#ifdef Cpp
#include <bits/stdc++.h>
using namespace std;
#endif

#define freopen(x) freopen(x".in", "r", stdin);freopen(x".out", "w", stdout)
#define repl(i, t) for (int i = fi[t]; i; i = ne[i])
#define rep(i, a, b) for (int i = (int) a;  i <= (int) b; ++i)
#define per(i, a, b) for (int i = (int) a;  i >= (int) b; --i)
#define _r read()
#define readtype long long

typedef long long var;

const int INF = 0x3f3f3f3f;

readtype read();

char s[200010];

int main() {
  scanf("%s", s + 1);
  var t = 0, last = 0;
  int n = strlen(s + 1), res = 0;
  rep(i, 1, n) {
    t = t * 27 + s[i] - 'a' + 1;
    if (t == last) continue;
    last = t, t = 0, res++;
  }
  printf("%d\n", res);
  return 0;
}

readtype read() {
  readtype a = 0, c = getchar(), s = 0;
  while (!isdigit(c)) s |= c == '-', c = getchar();
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return s ? -a : a;
}


Measured memory_bytes: 384
n,m=map(int,input().split())
li=[input().split() for i in range(m)]

l=[0]*n
cnt_ac=0
cnt_wa=0
for p,s in li:
 p=int(p)
 p-=1
 if l[p]=='AC':
  continue
 elif l[p]!='AC' and s=='AC':
  cnt_ac+=1
  cnt_wa+=l[p]
  l[p]='AC'
 elif l[p]!='AC' and s=='WA':
  l[p]+=1
print(cnt_ac,cnt_wa)

Measured memory_bytes: 32908
h,w=map(int,input().split())
S=[]
for i in range(h):
    S.append(input())
    
cnt=0
D=[[10**9]*w for _ in range(h)]
D[0][0]=0
for i in range(h):
    for j in range(w):
        for x,y in [(0,1),(1,0)]:
            if i+x>=h or j+y>=w:
                continue
            if S[i][j]!=S[i+x][j+y]:
                D[i+x][j+y]=min(D[i][j]+1,D[i+x][j+y])
            else:
                D[i+x][j+y]=min(D[i][j],D[i+x][j+y])
                
                
if S[0][0]=='#':
    print(1+D[h-1][w-1]//2)
else:
    print(D[h-1][w-1]//2+(S[0][0]!=S[h-1][w-1]))

Measured memory_bytes: 3064
n = int(input())
arr = list(map(int,input().split()))
dic = {}
for i in arr:
    if i not in dic:
        dic[i]=1
    else:
        dic[i]+=1
ans=0
for j in dic.keys():
    t=dic[j]
    ans+=(t*(t-1))//2
for i in arr:
    sm = ans-(dic[i]-1)
    print(sm)

Measured memory_bytes: 24748
#include<stdio.h>

int main(){
	int a ,b,N;
	scanf("%d",&N);
	a = N%10;
	b = (N-a)/10;
	if (a == 9){
		printf("Yes \n");
}else if(b ==9){
		printf("Yes \n");
}  else
	{
	printf("No\n");
}
return 0 ;
}

Measured memory_bytes: 128
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<String>();
    if v[0] == v[1] {
        println!("H");
    } else {
        println!("D");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
from collections import defaultdict
def soinnsuubunnkai(n):
  dic = defaultdict(int)
  i = 2
  while i * i <= n:
    while n % i == 0:
      dic[i] += 1
      n //= i
    i += 1
  if n != 1:
    dic[n] += 1
  return list(dic.values())
  
def saiki(values, score, ind, end):
  if ind == end:
    return score
  return saiki(values, score * values[ind], ind + 1, end) * 2+ \
         saiki(values, score, ind + 1, end)

while True:
  n = int(input())
  if n == 0:
    break
  values = soinnsuubunnkai(n)
  print((saiki(values, 1, 0, len(values)) + 1) // 2)





Measured memory_bytes: 5992
#include<stdio.h>
  #define N 101
void def(int);

int array[N][N];

int farray[N],darray[N];
int coarray[N],time,n;
 
  int main(){
  int i,j,v,v2,k;
  
  scanf("%d",&n);
  
for(i = 0;i < n;i++){

    coarray[i] = 0;

    for(j = 0;j < n;j++){

      array[i][j] = 0;
    }
  }
  time = 0;
  for(i = 0;i < n;i++){
    
scanf("%d%d",&v,&k);

    for(j = 0;j < k;j++){

      scanf("%d",&v2);
      array[v - 1][v2 - 1] = 1;
    }
  }
  for(i = 0;i < n;i++){
    if(coarray[i] == 0)def(i);
  }
  for(i = 0;i < n;i++){

    printf("%d %d %d\n",i + 1,darray[i],farray[i]);
  }

  return 0;

}


void def(int num)
{
  int i;
  coarray[num] = 1;
  darray[num]=++time;

  for(i = 0;i < n;i++){

    if(array[num][i] == 1){

      if(coarray[i] == 0)def(i);
     }
  }
  coarray[num] = 2;
  farray[num]=++time;
}
 

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

#define rep(i, u) for (int i = 0; i < u; i++)

using ll = long long;
using ull = unsigned long long;

int main() {
  int r, c;
  int a[101][101] = {0};
  cin >> r >> c;
  rep(i, r) rep(j, c) cin >> a[i][j];
  rep(i, r) rep(j, c) a[i][c] += a[i][j], a[r][j] += a[i][j];
  rep(i, r) a[r][c] += a[i][c];
  rep(i, r + 1) {
    rep(j, c + 1) {
      cout << a[i][j];
      if (j == c) cout << endl;
      else cout << ' ';
    }
  }
  return 0;
}



Measured memory_bytes: 3116
from sys import stdin
N,K = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
cums = [0]*1001
cnt = 0
for i in range(1001):
    cnt += i
    cums[i] = cnt

p_new = [cums[j]/j for j in P]
sp = sum(p_new[0:K])

ans = []
ans.append(sp)
cnt = 0
for k in range(K,N):
    sp = sp + p_new[k]
    sp = sp - p_new[cnt]
    cnt += 1
    ans.append(sp)

print(max(ans))

Measured memory_bytes: 25188
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double pi = Math.PI;
        double s = r*r*pi;
        double c = r*2*pi;
        System.out.printf("%f %f\n", s, c);
        sc.close();
    }
}


Measured memory_bytes: 28240
import bisect

S = list(str(input()))
T = list(str(input()))

X = [[] for _ in range(26)]
for i, c in enumerate(S):
    # a = 0, b = 1, ..., z = 25
    j = ord(c) - ord('a')
    X[j].append(i + 1)

# print(X)

# Sの繰り返し数
div_cnt = 0
# 現在のindex
now = 0

for c in T:
    # a = 0, b = 1, ..., z = 25
    j = ord(c) - ord('a')

    # Sにない文字がTにある場合
    if len(X[j]) == 0:
        print(-1)
        exit()

    next = bisect.bisect_right(X[j], now)
    # print(c,now,next)

    if next == len(X[j]):
        div_cnt += 1
        now = X[j][0]
    else:
        now = X[j][next]

ans = div_cnt * len(S) + now
print(ans)


Measured memory_bytes: 87748
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
 
using namespace std;
 
 
int main() {
 
	int x, a, b;
 
	cin >> x >> a >> b;
 
	if (a >= b) {
		cout << "delicious" << endl;
	}else if(x >= b - a)
	{
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
 
	}
 
}

Measured memory_bytes: 256
from collections import defaultdict

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

N, K, L = map(int, input().split())

road = UnionFind(N)
railway = UnionFind(N)

for _ in range(K):
    p, q = map(int, input().split())
    road.union(p-1, q-1)

for _ in range(L):
    p, q = map(int, input().split())
    railway.union(p-1, q-1)

counter = defaultdict(int)
for i in range(N):
    counter[(road.find(i), railway.find(i))] += 1
ans = []
for i in range(N):
    ans.append(counter[(road.find(i), railway.find(i))])

print(*ans)


Measured memory_bytes: 117584
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
#define fprint(NUM,X) cout << fixed << setprecision(NUM) << (X) << endl
#define fprints(NUM,X,Y) cout << fixed << setprecision(NUM) << (X) << " " << (Y) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];
#define MAX 100000

vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX],parent[MAX],lowest[MAX],timer;

void dfs(int current,int prev){
  prenum[current] = lowest[current] = timer;
  timer++;

  visited[current] = true;

  int next;

  for(int i = 0;i < G[current].size();i++){
    next = G[current][i];
    if(!visited[next]){
      parent[next] = current;
      dfs(next,current);
      lowest[current] = min(lowest[current],lowest[next]);
    }else if(next != prev){
      lowest[current] = min(lowest[current],prenum[next]);
    }
  }
}

void art_points(){
  for(int i = 0;i < N;i++)visited[i] = false;
  timer = 1;
  dfs(0,-1);

  set<int> ap;
  int np = 0;
  for(int i = 1;i < N;i++){
    int p = parent[i];
    if(p == 0)np++;
    else if(prenum[p] <= lowest[i])ap.insert(p);
  }
  if(np > 1)ap.insert(0);
  for(set<int>::iterator it = ap.begin();it != ap.end();it++){
    cout << *it << endl;
  }
}

int main(){
  int m;
  cin >> N >> m;
  for(int i = 0;i < m;i++){
    int s,t;
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  art_points();
  return 0;
}


Measured memory_bytes: 7020
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vi h(n);
    rep(i, n) cin >> h[i];
    int up = 0, down = 0;
    loop(i, 1, n) {
      if (h[i] - h[i - 1] >= 0) cmax(up, h[i] - h[i - 1]);
      if (h[i - 1] - h[i] >= 0) cmax(down, h[i - 1] - h[i]);
    }
    cout << up << " " << down << endl;
  }
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,A,B;
  cin >> N >> A >> B;
  cout << min(A*N,B) << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[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(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 384
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/

//var min, min2, count: Int!
//for i in 1...10 {
//    let x = readInt()!
//    if i == 1 {
//        min = x
//        count = 1
//    } else if x < min {
//        min2 = min
//        min = x
//        count = 1
//    } else if x == min && count == 1 {
//        min2 = x
//        count = 2
//    }
//}
//print(min2)

/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (A, B, K) = (input[0], input[1], input[2])
for i in A...min(A+K-1, B) {
    print(i)
}
let start = min(max(A+K, B-K+1), B+1)
for i in start..<B+1 {
    print(i)
}


Measured memory_bytes: 1152