akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
namespace lc {
template <class T>
class CoordinateCompressor {
private:
	std::vector<T> m_coords;
public:
	CoordinateCompressor() : m_coords() { }
	void push(const T &x){
		m_coords.push_back(x);
	}
	size_t build(){
		sort(m_coords.begin(), m_coords.end());
		m_coords.erase(
			unique(m_coords.begin(), m_coords.end()), m_coords.end());
		return m_coords.size();
	}
	size_t compress(const T &x) const {
		return std::lower_bound(
			m_coords.begin(), m_coords.end(), x) - m_coords.begin();
	}
};
}
using namespace std;
typedef long long ll;
static const int INF = 1000000000;
int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<string> b(n);
	vector<int> x(n);
	lc::CoordinateCompressor<string> ccomp;
	for(int i = 0; i < n; ++i){
		cin >> b[i] >> x[i];
		ccomp.push(b[i]);
	}
	ccomp.build();
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ a[i] = ccomp.compress(b[i]); }
	vector<int> y(n);
	for(int i = 0; i < n; ++i){ y[a[i]] = x[i]; }
	int m;
	cin >> m;
	vector< vector<int> > conn(n);
	for(int i = 0; i < m; ++i){
		string ss, st;
		cin >> ss >> st;
		const int s = ccomp.compress(ss);
		const int t = ccomp.compress(st);
		conn[s].push_back(t);
		conn[t].push_back(s);
	}
	vector<int> group(n, -1);
	ll answer = 0;
	for(int i = 0; i < n; ++i){
		if(group[i] >= 0){ continue; }
		queue<int> q;
		q.push(i);
		group[i] = i;
		int minval = INF, count = 0;
		while(!q.empty()){
			const int u = q.front();
			q.pop();
			++count;
			minval = min(minval, y[u]);
			for(int j = 0; j < conn[u].size(); ++j){
				const int v = conn[u][j];
				if(group[v] < 0){
					group[v] = i;
					q.push(v);
				}
			}
		}
		answer += static_cast<ll>(minval) * count;
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 1784
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;

typedef long long ll;

const ll INF = 1e18;
const int BIG = 1e9;
const int maxN = 200;
const string FILENAME = "sample";

int n, k;
int v[maxN];

void read(){
	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> v[i];
	}
}

void solv(){
	int mx = 0;
	for(int i = 0; i <= k; i++){
		for(int j = 0; j <= n - i && j <= k - i; j++){
			for(int throwAway = 0; throwAway <= k - i - j; throwAway++){
				vector<int> vv;
				for(int run = 1; run <= i; run++){
					vv.push_back(v[run]);
				}

				for(int run = n; run >= n - j + 1; run--){
					vv.push_back(v[run]);
				}

				sort(vv.begin(), vv.end());
				int ans = 0;
				//cerr << i << ' ' << j << '\n';
				for(int run = vv.size() - 1; run >= throwAway; run--){
					ans += vv[run];
				}

				mx = max(mx, ans);
			}
		}
	}

	cout << mx << '\n';
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
#ifdef h4h4
	freopen((FILENAME + ".inp").c_str(), "r", stdin);
	freopen((FILENAME + ".out").c_str(), "w", stdout);
#endif

	read();
	solv();

	return 0;
}

Measured memory_bytes: 384
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [N, M] = input[0].map(Number);

  const adjacencies = [...Array(N + 1)].map(() => Array<number>());
  for (let i = 1; i <= M; i++) {
    const [A, B] = input[i].map(Number);

    adjacencies[A].unshift(B);
    adjacencies[B].unshift(A);
  }

  const distances: number[] = [];
  const parents: number[] = [];

  distances[1] = 0;

  const queue = [1];
  while (true) {
    const current = queue.pop();
    if (current === undefined) {
      break;
    }

    adjacencies[current].forEach((adjacency) => {
      if (distances[adjacency] !== undefined) {
        return;
      }

      distances[adjacency] = distances[current] + 1;
      parents[adjacency] = current;

      queue.unshift(adjacency);
    });
  }

  return `Yes\n${parents.slice(2).join("\n")}`;
};

console.log(main(read()));


Measured memory_bytes: 133808
n = int(input())
ta = []
for i in range(n):
    tmp = list(map(int,input().split()))
    ta.append(tmp)
vote=[1,1]
for v in ta:
    t_ratio=(vote[0]-1)//v[0]+1
    a_ratio=(vote[1]-1)//v[1]+1
    ratio = max(t_ratio,a_ratio)
    vote[0] = v[0] * ratio
    vote[1] = v[1] * ratio

print(sum(vote))

Measured memory_bytes: 39280
#include<stdio.h>
#include<stdlib.h>


int comp(const void *p1,const void *p2){
  long long int n1,n2;
  n1=*((const long long int *)p1);
  n2=*((const long long int *)p2);
  return (n2>n1)?1:-1;
}

int main(void){
  long long int *a;
  long long int i,n,b=0,sum1=0,sum2=0,k1,k2,k3,k4,k5,k6,k;
  //FILE *fp;
  //fp=fopen("sort_test.txt","w");

  scanf("%lld",&n);
  a=(long long int *)calloc(n,sizeof(long long int));
  for(i=0;i<n;i++) scanf("%lld",a+i);
  qsort(a,n,sizeof(long long int),comp);
  //for(i=0;i<n;i++) fprintf(fp,"%lld\n",a[i]);
  //fclose(fp);
  //連続した6つのパターン
  for(i=0;i<n-5;i++){
    //a[i]~a[i+5]までを総当たりで検索　できたらその時点でbreakしての総和を求める 
    //for(k1=0;k1<4;k1++){
      for(k2=1;k2<5;k2++){
	for(k3=k2+1;k3<6;k3++){
	  if(a[i]>=a[i+k2]+a[i+k3]) continue;
	  for(k4=1;k4<4;k4++){
	    if(/*k4==k1||*/k4==k2||k4==k3) continue;
	    for(k5=k4+1;k5<5;k5++){
	      if(/*k5==k1||*/k5==k2||k5==k3) continue;
	      for(k6=k5+1;k6<6;k6++){
		if(/*k6==k1||*/k6==k2||k6==k3) continue;
		if(a[i+k4]>=a[i+k5]+a[i+k6]) continue;
		//printf("0%lld%lld-%lld%lld%lld\n",k2,k3,k4,k5,k6);
		sum1=0;
		for(k=0;k<6;k++){
		  sum1+=a[i+k];
		}
		//goto label;
	      }
	    }
	  }
	}
      }
      //}
    if(sum1!=0) break;
  }
  //label:
  for(i=0;i<n-2;i++){
    if(a[i]<a[i+1]+a[i+2]){
      sum2+=(a[i]+a[i+1]+a[i+2]);
      i+=2;
      b++;
      if(b==2) break;
    }
  }
  
  if(sum1>sum2){
    printf("%lld\n",sum1);
  }else{
    printf("%lld\n",sum2);
  }
  
  
  free (a);
  return 0;
}

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

void gcd(int a,int b)
{
  int ans,p,q[10000];

  p=max(a,b); q[0]=min(a,b);
  for(int i=0;;i++){
    if(!q[i]){
      cout<<p<<" "; break;
    }
    q[i+1]=p%q[i]; p=q[i];
  }
}

int lcm(int a,int b)
{
  int ans=0,p=min(a,b),q=max(a,b);

  for(int i=1;;i++){
    for(int j=1;;j++){
      if(p*i==q*j){
	ans=p*i; break;
      }
      if(p*i<q*j) break;
    }
    if(ans) break;
  }
  cout<<ans<<endl;
}

int main()
{
  int a,b;

  while(cin>>a>>b){
    gcd(a,b); lcm(a,b);
  }
}


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

int main() {
  char c;
  cin >> c;
  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    cout << "vowel" << endl;
    else
      cout << "consonant" << endl;
}

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int N = 1e5 + 10;

int n;
vector<pii> adj[N];

int sz[N], pref[N];
int dfsSize(int u, int p) {
    sz[u] = 1; pref[u] = -1;
    for (auto e : adj[u]) {
        int v = e.first;
        if (v == p) continue;
        dfsSize(v,u);
        sz[u] += sz[v];
        if (pref[u] == -1 || sz[pref[u]] < sz[v])
            pref[u] = v;
    }
}

ll len[N];
void dfsLen(int u, int p, ll L) {
    len[u] = L;
    for (auto e : adj[u]) {
        int v,c; tie(v,c) = e;
        if (v == p) continue;
        dfsLen(v, u, L + c);
    }
}

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

    cin >> n;
    forn(_,n-1) {
        int u,v,c; cin >> u >> v >> c;
        u--; v--;
        adj[u].eb(v,c);
        adj[v].eb(u,c);
    }

    dfsSize(0,-1);
    int center = 0;
    while (pref[center] != -1 && sz[pref[center]]*2 > n) center = pref[center];

    dfsLen(center,-1, 0);
    ll ans = 0; forn(u,n) ans += 2LL*len[u];

    ll sub;
    dfsSize(center,-1);
    if (sz[pref[center]]*2 == n) {
        sub = len[pref[center]];
    }
    else {
        sub = 1e9;
        for (auto e : adj[center]) sub = min(sub, (ll) e.second);
    }

    ans -= sub;
    cout << ans << endl;

    return 0;

}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++)
    cin >> a.at(i);
  sort(a.begin(), a.end());
  auto it = lower_bound(a.begin(), a.end() - 1, a.at(n - 1) / 2);
  cout << a.at(n - 1) << ' ';
  if(it == a.end() - 1)
    cout << a.at(n - 2);
  else if(a.at(n - 1) / 2 - *(it - 1) < *it - a.at(n - 1) / 2)
    cout << *(it - 1);
  else
    cout << *it;
  cout << '\n';
}

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

int main() {
 int r,D;

 vector<int>vec(10);
 cin>>r>>D>>vec[0];
 for(int i=0;i<10;i++){
   vec[i+1]=r*vec[i]-D;
   cout<<vec[i+1]<<endl;
 }
}
   
  
  

Measured memory_bytes: 3616
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n,i;
	long long sum =0,a;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		sum+=(a-1);
	}
	cout<<sum;
	return 0;
}

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

#define mod 1000000007
#define pi 3.14159265358979
#define  PRE(x,p) cout<<setprecision(x)<<p; 
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl "\n"
#define high INT_MAX
#define low INT_MIN
#define ll long long int
using namespace std;
ll z;
ll a[500005];
vector<ll>v; 
// cout<<"CASE #"<<z<<": "<<""<<endl;
void solve() 
{ 
  ll n,i;
  cin>>n;
   ll pre[500005];
  for(i=1;i<=n;i++)
 { cin>>a[i];
  pre[i]=0;}
  
  for(i=1;i<=n;i++)
  {
          pre[i]=(pre[i-1]+a[i])%mod;
  }
  ll ans=0;
  for(i=n;i>=2;i--)
  {
         ans=(ans+(pre[i-1]*a[i])%mod)%mod; 
  }
  cout<<ans%mod;
  
 
}
 
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t=1;
//cin>>t;
for(z=1;z<=t;z++)
solve();
 
return 0;
}

Measured memory_bytes: 6784
#include <iostream>
using namespace std;
int main(){
  int n=0;
  int m;
  cin >>m;
  n += m*100;
  cin >>m;
  n += m*10;
  cin >>m;
  n += m;
  
  if(n%4==0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  uint64_t N;
  cin >> N;
  vector<uint64_t> A(N);
  vector<uint64_t> B(64);
  vector<uint64_t> beki(64);

  uint64_t num = 1;
  for (uint64_t b = 0; b < 64; ++b) {
    B[b] = 0;
    beki[b] = num % 1000000007;
    num *= 2;
  }
  ArrayInput(A);
  for (uint64_t i = 0; i < N; ++i) {
    for (uint64_t b = 0; b < 63; ++b) {
      if ((A[i] >> b) & 0x01) B[b]++;
    }
  }
  uint64_t res = 0;
  vector<uint64_t> tmp(63);
  uint64_t calc = 0;
  for (uint64_t i = 0; i < (N - 1); ++i) {
    for (uint64_t b = 0; b < 63; ++b) {
      if ((A[i] >> b) & 0x01) {
        B[b]--;
        res += (((N - 1) - i) - (B[b])) * beki[b];
      } else {
        res += (B[b]) * beki[b];
      }
      res %= 1000000007;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

int main(){
    int N,M=1000000000,m=0;
    cin>>N;
    int A[1000];
    for(int i=0;i<N;i++){
        cin>>A[i];
        M=min(M,A[i]);
        m=max(m,A[i]);
    }
    cout<<abs(M-m)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using Int = int64_t;
static const Int MOD = 1e9 + 7;
Int add(Int a, Int b) {
    a %= MOD;
    b %= MOD;
    return (a + b) % MOD;
}
Int Mul(Int a, Int b) {
    a %= MOD;
    b %= MOD;
    return (a * b) % MOD;
}
int main() {
    Int N, K;
    cin >> N >> K;
    vector<Int> A(N);
    for (auto& i : A) cin >> i;
    Int a = 0, b = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (A[i] > A[j]) {
                b++;
                if (j > i) a++;
            }
        }
    }
    cout << add(Mul(a, K), Mul(b, K * (K - 1) / 2)) << endl;
}


Measured memory_bytes: 256
n,c=map(int,input().split())
bangumi=[tuple(map(int,input().split())) for i in range(n)]
jikan=[0]*(10**5+1)

#チャンネルごとにソート
from operator import itemgetter
bangumi=sorted(bangumi, key=itemgetter(2,0))

nowch=0
syuryo=0
for s,t,c in bangumi:
  if c==nowch and s==syuryo:
    for i in range(s+1,t+1): #時刻Sでの重複数え上げを防ぐ
      jikan[i]+=1
  else:
    for i in range(s,t+1):
      jikan[i]+=1
  nowch=c
  syuryo=t

#print(bangumi)
print(max(jikan))

Measured memory_bytes: 26952
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a==1)a=14;
			if(b==1)b=14;
			if(a>b)System.out.println("Alice");
			if(a<b)System.out.println("Bob");
			if(a==b)System.out.println("Draw");
	}
}

Measured memory_bytes: 23252
fun min(a:Int,b:Int):Int{
    return if( a<b ) a
    else b
}

fun main(args: Array<String>) {

    val n = readLine()!!.toInt()
    val inf = n*100

    val dp = IntArray(n+1){ inf }
    dp[0] = 0

    for ( i in 0 until n){
        var s = 1
        var t = 1
        while( i+s <= n ){
                           dp[i+s] = min( dp[i+s], dp[i]+1 )
            if( i+t <= n ) dp[i+t] = min( dp[i+t], dp[i]+1 )
            s *= 6
            t *= 9
        }
    }

    println( dp[n] )

}



Measured memory_bytes: 33684
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		set<string> st;
		for (int j = 1; j < s.size(); j++) {
			string s1 = s.substr(0, j);
			string s2 = s.substr(j);
			st.emplace(s2 + s1);
			reverse(s1.begin(), s1.end());
			st.emplace(s1 + s2);
			st.emplace(s2 + s1);
			reverse(s2.begin(), s2.end());
			st.emplace(s1 + s2);
			st.emplace(s2 + s1);
			reverse(s1.begin(), s1.end());
			st.emplace(s1 + s2);
			st.emplace(s2 + s1);
		}
		st.emplace(s);
		reverse(s.begin(), s.end());
		st.emplace(s);

		cout << st.size() << endl;
	}
}


Measured memory_bytes: 3128
S=input()
T=input()
a=len(S)
b=len(T)
m=a-b
ans=b
if m!=0:
    for i in range(m):
        cnt=b
        for j in range(b):
            if S[i+j]==T[j]:
                cnt-=1
        ans=min(cnt,ans)
else:
    cnt=b
    for i in range(a):
        if S[i]==T[i]:
            cnt-=1
    ans=min(cnt,ans)
print(ans)

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

int main()
{
  int N;
  cin >> N;
  vector<long long int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end(), greater<int>());
  vector<long long int> V;
  for (int i = 0; i < N - 1; i++)
  {
    if (A.at(i) == A.at(i + 1))
    {
      V.push_back(A.at(i));
      i++;
    }
  }
  if ((int)V.size() < 2)
    cout << 0 << endl;
  else
    cout << V[0] * V[1] << endl;
}


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

int main() {
  int A,B;
  A=0;
  int N;
  cin >> N;
  vector<int>a(N);
  vector<int>b(N);
  vector<int>c(N-1);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> b.at(i);
  }
  for(int i=0;i<(N-1);i++){
    cin >> c.at(i);
  }
  for(int i=0;i<N;i++){
    A=A+b.at(i);
  }
  for(int i=0;i<(N-1);i++){
    if((a.at(i+1)-a.at(i))==1){
      A=A+c.at(a.at(i)-1);
    }
  }

  
cout << A << endl;

}






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

int main(){
  int n; cin>>n;
  vector<int> p(n);
  
  int dif=0;
  for(int i = 0; i<n; i++){
    cin >> p[i];
    if(p[i] != i+1) dif++;
  }
  
  if(dif==2 || dif==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

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

using namespace std;

int main()
{
    int a, b, k;
    cin >> a >> b >> k;
    int m = k;
    set<int> s;
    for(int i=a;i<=b;i++)
    {
        if(k == 0)
            break;
        k--;
        //cout << i << endl;
        s.insert(i);
    }
    for(int i=b;i>=a;i--)
    {
        if(m == 0)
            break;
        m--;
        //cout << i << endl;
        s.insert(i);
    }
    for(auto it=s.begin();it!=s.end();it++)
    {
        cout << *it <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        long[] dp = new long[n+1];
        for(int i = 0; i < m; i++){
            int a = scanner.nextInt();
            dp[a] = -1;
        }
        dp[0] = 1;
        if(dp[1] == 0){
            dp[1] = 1;
        }else{
            dp[1] = 0;
        }
        for(int i = 2; i <= n; i++){
            if(dp[i] >= 0){
                dp[i] = (dp[i-1] + dp[i-2])%1000000007;
            }else{
                dp[i] = 0;
            }
        }
        System.out.println(dp[n]);
    }
}



Measured memory_bytes: 48424
// 連結成分
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>
#include<stack>

using namespace std;

#define MAX_N 100000

// 値の定義
const int INV = -1;

// 友達関係を保持する配列
vector<int> v_Link[MAX_N + 1];

// 接続情報を保持する配列
int ary_connection[MAX_N + 1];

void search_relation(int u_ID, int id);

int main(void)
{
    int n, m, q, s, t;

    for(int i = 0; i < MAX_N + 1; i++)
    {
        // 配列の初期化
        ary_connection[i] = INV;
    }

    cin >> n >> m;

    for(int i = 0; i < m; i++)
    {
        cin >> s >> t;

        // 友達関係を双方向に設定する
        v_Link[s].push_back(t);
        v_Link[t].push_back(s);
    }

    int id = 1;

    for(int u = 0; u < n; u++)
    {
        if( ary_connection[u] == INV )
        {
            // 友達関係の検索を実施
            search_relation(u, id++);
        }
    }

    cin >> q;

    for(int i = 0; i < q; i++)
    {
        cin >> s >> t;

        // 質問の結果を表示する
        if( ary_connection[s] == ary_connection[t] )
        {
            // 友達関係が存在する
            printf("yes\n");
        }
        else
        {
            printf("no\n");
        }
    }

    return 0;
}

// 友達関係を検索するための関数
// u_ID : 友達関係を検索する最初のユーザーID
// id   : ary_connection[]に設定するID値
void search_relation(int u_ID, int id)
{

    int user_id;

    queue<int> Q;

    // 開始点をキューにプッシュして, 友達関係を保存する
    Q.push(u_ID);
    ary_connection[u_ID] = id;

    while( !Q.empty() )
    {
        // キューの先頭要素を取得して, 削除する
        // ( 各ユーザーの巡回は1回だけ )
        int u = Q.front();
        Q.pop();

        for(int v = 0; v < v_Link[u].size(); v++)
        {
            // 接続関係にあるユーザーの検索
            user_id = v_Link[u][v];

            if( ary_connection[user_id] == INV )
            {
                // ----- 繋がっている頂点が見つかった -----

                // 接続関係を保存する
                ary_connection[user_id] = id;

                // キューにプッシュして, 検索を継続する
                Q.push(user_id);
            }
        }
    }

    return;
}



Measured memory_bytes: 8952
#!/usr/bin/env ruby
n, m, k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)


sum_a = [0]

n.times do |i|
  sum_a.push(sum_a[i] + a[i])
end

sum_b = [0]
m.times do |i|
  sum_b.push(sum_b[i] + b[i])
end

ans = 0
j = m

0.upto(n) do |i|
  break if sum_a[i] > k

  while sum_b[j] + sum_a[i] > k
    j -= 1
  end

  ans = [ans, i + j].max
end

puts ans


Measured memory_bytes: 49404
"""
方針　各桁を0にするか1にするかは独立に考えてよい

K = 10101 の時
0か1か好きに選べる桁をfとして
* X = 10101
* X = 10100
* X = 100ff
* X = 0ffff
を試し、最大になるものを選ぶ

2**39 < 10**12 < 2**40　なので40桁について考え
fのときどっちを選ぶとよいかを前計算しておく"""

# -*- coding: utf-8 -*-
def  inpl(): return list(map(int, input().split()))

N, K = inpl()
A = inpl()

L = [0]*40  # (i桁目が1である数)
for i in range(N):
    for j in range(40):
        L[j] += (A[i] >> j)&1

default = [(N - L[i]) * (2**i) if (K>>i)&1 == 1 else L[i] * (2**i) for i in range(40)]
free = [max(L[i] * (2**i), (N-L[i])*(2**i)) for i in range(40)]

ans = sum([K^A[i] for i in range(N)])
for i in range(40):
    if (K >> i)&1 == 1:
        ans = max(ans,
                  sum(free[:i]) + L[i]*(2**i) + sum(default[i+1:]))
print(ans)


Measured memory_bytes: 14620
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll,ll> pll;
vector<ll> A;
int main(){
 ll n,ans=0,x,temp=-1,sum=1;
 cin>>n;
 rep(i,n){
     cin>>x;
     if(temp==x)
     {
         sum+=1;
     }
     else if(i!=0){
         ans+=sum/2;
         sum=1;
     }
     temp=x;
 }
 if(sum>1)ans+=sum/2;
 cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 
#define ALL(a)  (a).begin(),(a).end()



using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int a, int b)
{
	return a == 0 ? b : gcd(b % a, a);
}
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}

long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}






int main(){
  long long N;
  cin>>N;
  long long A[N];
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  long long S[N+1];
  S[0]=0;
  for(int i=0;i<N;i++){
    S[i+1]=S[i]+A[i];
  }
  sort(S,S+N+1);
  long long tmp=1;
  long long sum=0;
  for(int i=0;i<N+1;i++){
    if(S[i]==S[i+1]){
      tmp++;
    }else{
      if(tmp>1){
        sum+=tmp*(tmp-1)/2;
        tmp=1;
        
      }
    }

  }
  cout<<sum<<endl;
  




  
}


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

int a, b, c;

int main()
{
	cin >> a >> b >> c;

	if ((a == b && b != c) || (b == c && c != a) || (c == a && a != b))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; 
const int N = 1e6 + 5;

int main(void) {
	int n; cin >> n;
	int a[n];
	bool b[N];
	memset(b, 0, sizeof(b));

	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a, a+n);

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (!b[a[i]]) {
			if (a[i] != a[i + 1]) {
				++ans;
			}

			for (int j = 1; a[i] * j <= 1e6; ++j) {
				b[a[i] * j] = true;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5404
from collections import deque
import sys


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())


class Graph:
    def __init__(self, n, is_directed=False):
        """
        :param n: 頂点数
        :param is_directed: 有向グラフ(True)か無向グラフか(False)
        """
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.is_directed = is_directed

    def add_edge(self, u, v):
        """uからvへの(有向な)辺をつなぐ"""
        self.graph[u].append(v)
        if not self.is_directed:
            self.graph[v].append(u)

    def search(self, start, mode):
        '''開始地点から各頂点まで幅/深さ優先探索を行って得られた距離のリストを返す
        Args:
          start(int): 開始地点となる頂点
          mode(str): 幅優先探索(b)か深さ優先探索(d)を指定

        Returns:
          List[int]: 開始地点からの距離(未到達の場合は-1)
        '''
        dists = [-1] * self.n
        que = deque([start])
        dists[start] = 0
        if mode == 'b':
            get_v = que.popleft
        else:
            get_v = que.pop
        while que:
            now_v = get_v()
            for next_v in self.graph[now_v]:
                if dists[next_v] != -1:
                    continue
                que.append(next_v)
                dists[next_v] = dists[now_v] + 1
        return dists


n = I()
g = Graph(n, is_directed=True)
for _ in range(n):
    u, k, *v = LI()
    u -= 1
    if v == []:
        continue
    for vi in v:
        vi -= 1
        g.add_edge(u, vi)
res = g.search(0, 'b')
for i in range(n):
    print(i + 1, res[i])



Measured memory_bytes: 6032
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const int K = 26;

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

    int d;
    cin >> d;
    vector<int> c(K);
    for (int i = 0; i < K; ++i) {
        cin >> c[i];
    }
    vector<vector<int>> s(d, vector<int>(K));
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < K; ++j) {
            cin >> s[i][j];
        }
    }
    vector<int> ans;
    vector<int> last(26, -1);
    for (int i = 0; i < d; ++i) {
        vector<double> x;
        for (int j = 0; j < K; ++j) {
            x.push_back((double) s[i][j] * s[i][j] * sqrt(c[j] * (i - last[j])));
        }

        double sum = 0;
        for (int j = 0; j < K; ++j) {
            sum += x[j];
        }
        for (int j = 0; j < K; ++j) {
            x[j] /= sum;
        }

        double prob = (double) (rand() % RAND_MAX) / (double) RAND_MAX;
        double cur = 0;
        for (int j = 0; j < K; ++j) {
            if (cur + x[j] <= prob) {
                cur += x[j];
                continue;
            }
            ans.push_back(j);
            last[j] = i;
            break;
        }
    }

    for (auto u : ans) {
        cout << u + 1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#define ll long long
using namespace std;

int main(){
    string a;
    cin>>a;
    ll l=a.size();
    for (ll i=0; i<l; i++) cout<<"x";
    cout<<endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;

int n,m,ans=0,tmp[200005];
struct Student{
    int l,r;
    bool operator<(const Student &b)const{
        return l!=b.l?l<b.l:r>b.r;
    }
}s[200005];
priority_queue<int,vector<int>,greater<int> > q;

int main(){
//  freopen("data.in","r",stdin);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&s[i].l,&s[i].r);
    sort(s+1,s+n+1);
    int h=1,t=m;
    for(int i=1;i<=n;i++){
        q.push(s[i].r);
        if(h<=t&&h<=s[i].l)h++;
        else{
            tmp[++tmp[0]]=q.top();
            q.pop();
        }
    }
    sort(tmp+1,tmp+tmp[0]+1);
    for(int i=tmp[0];i>=1;i--){
        if(h<=t&&tmp[i]<=t)t--;
        else ans++;
    }
    printf("%d",ans);
}

Measured memory_bytes: 3192
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))

heap = []
for i in a:
    heapq.heappush(heap, -i)


for i in range(m):
    x = - heapq.heappop(heap)
    x = x // 2
    heapq.heappush(heap, - x)



print(sum(map(lambda n: int (-n), heap)))


Measured memory_bytes: 64920
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;

int m[16][16];
int n;
int cou=0;

void magic(int a,int b){
	if(a==n&&b==n) magic(0,0);
	else{
		if(a>=n) magic(0,b);
		else if(b>=n) magic(a,0);
		else if(a<0) magic(n-1,b);
		else if(m[a][b]>0) magic(a-1,b+1);
		else{
			m[a][b]=cou;
			cou++;
			if(cou==n*n+1) return;
			magic(a+1,b+1);
		}
	}
}

int main(){
	while(cin>>n,n!=0){
		rep(i,n)rep(j,n) m[i][j]=0;
		
		cou=1;
		int x=(n+1)/2-1;
		int y=x+1;
		magic(x,y);
		rep(i,n){
			rep(j,n){
				printf("%4d",m[j][i]);
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1192
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def mat_mul_opt(_mat_info):
    rc_info.extend(list(map(int, _mat_info[0])))
    rc_info.extend(list(map(lambda x: int(x[1]), _mat_info[1:])))

    for l in range(2, mat_num + 1):
        for i in range(1, mat_num - l + 2):
            j = i + l - 1
            ans[i][j] = 1e7
            for k in range(i, j):
                ans[i][j] = min(ans[i][j], ans[i][k] + ans[k + 1][j] +
                                rc_info[i - 1] * rc_info[k] * rc_info[j])

    return ans[1][mat_num]


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    mat_num = int(_input[0])
    mat_info = tuple(map(lambda x: x.split(), _input[1:]))

    rc_info = []
    ans = [[0] * (mat_num + 1) for _ in range(mat_num + 1)]
    print(mat_mul_opt(mat_info))

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

int main(){
  int N,x,a,b;
  cin >> N;
  x=N/1.08;
  a=x*1.08;
  b=(x+1)*1.08;
  if (a==N){
  cout << x << endl;
  }
  else if (b==N){
  cout << x+1 << endl;  
  }
  else {
  cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int n;string s;
int num[26];
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>s;
    for(int i=0;i<n;i++){
        num[s[i]-'a']++;
    }
    ll ans = 1;
    for(int i=0;i<26;i++){
        ans=ans*(num[i]+1)%mod;
    }
    cout<<--ans<<endl;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <bitset>

#define rep(i, a, b) for ( ll i = (a); i < (b); i++ )
#define per(i, a, b) for ( ll i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

const int MAX_ROW = 100005;
const int MAX_COL = 100;

struct BitMatrix {
  int H, W;
  bitset<MAX_COL> val[MAX_ROW];
  BitMatrix(int h = 1, int w = 1) : H(h), W(w) {}
  inline bitset<MAX_COL>& operator [] (int i) { return val[i]; }
};

int xor_elimination(BitMatrix &A) {
  //rep(i, 0, A.H) cout << A[i] << endl;
  //cout << "\n";
  int COL = A.W, ROW = A.H;
  int rank = 0;
  for (int col = COL-1; col>=0; col--) {
    int pivot = -1;
    for (int row = rank; row<ROW; row++) {
      if (A[row][col]) {
        pivot = row;
        break;
      }
    }
    
    if (pivot == -1) continue;
    swap(A[pivot], A[rank]);
    
    for (int row = 0; row<ROW; row++) {
      if (row != rank && A[row][col]) A[row] ^= A[rank];
    }
    
    rank++;
  }
  return rank;
}
/*
bool is_make_xor(BitMatrix &A, int rank, long long num) {
  for (int i=0; i<rank; i++) {
    int p = -1;
    for (int j=A.
  
  }
  

}
*/

int n;
ll a[100005], ans;

int main(void) {
  cin >> n;
  
  BitMatrix M(n, MAX_COL);
  rep (i, 0, n) {
    cin >> a[i];
    M[i] = a[i];
  }
  
  for (int d=61; d>=0; d--) {
    int num = 0;
    for (int i=0; i<n; i++) num += M[i][d];
    
    if (num%2) {
      ans += (1LL<<d);
      for (int i=0; i<n; i++) M[i][d] = 0;
    }
  }
 
  int rank = xor_elimination(M);
  
  bitset<MAX_COL> b;
  rep(i, 0, rank) b ^= M[i];
  
  rep(i, 0, 62) ans += (1LL<<(i+1))*b[i];
  
  cout << ans << endl;
   
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	
	int N;
	vector<pair<ll,ll>> ar;
	vector<ll> br;		
	cin>>N;
	REP(i,N){
		ll a;
		cin>>a;
		ar.emplace_back(a,i);
		br.push_back(a);
	}
	
	sort(ar.begin(),ar.end());
	
	ll poll = N/2 - 1;
	for(ll i = 0; i < N; i++ ){
		
		auto pos = br[i];

			if(pos <= ar[poll].first){
				cout<<ar[poll+1].first<<endl;
			}
			else{
				cout<<ar[poll].first<<endl;
			}
	}

	return 0;
}



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

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

  int n;
  cin >> n;
  ll ans = 0;
  int index = 1;
  while (index <= n)
  {
    if(index % 3 != 0 && index % 5 != 0) ans += index;
    index++;
  }
  cout << ans <<endl;

  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll h,w;
    cin>>h>>w;
    char a[h][w];
    for(ll i=0;i<h;i++)
    {
        for(ll j=0;j<w;j++)
        {
            cin>>a[i][j];
        }
    }
    ll dp[h][w];
    dp[0][0]=1;
    ll i=0,j=0;
    bool wall=false;
    while(i<h)
    {
        if(a[i][0]=='#')
            wall=true;
        if(wall)
            dp[i][0]=0;
        else
            dp[i][0]=1;
        i++;
    }
    wall=false;
    while(j<w)
    {
        if(a[0][j]=='#')
            wall=true;
        if(wall)
            dp[0][j]=0;
        else
            dp[0][j]=1;
        j++;
    }
    for(i=1;i<h;i++)
    {
        for(j=1;j<w;j++)
        {
            if(a[i][j]=='#')
            {
                dp[i][j]=0;
            }
            else
            {
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
            }
        }
    }
    cout<<dp[h-1][w-1]<<"\n";
}


Measured memory_bytes: 9088
N, M, C = map(int, input().strip().split(" "))
B = list(map(int, input().strip().split(" ")))
count = 0

for _ in range(N):
    A = list(map(int, input().strip().split(" ")))
    s = 0
    for a, b in zip(A, B):
        s += a * b
    s += C
    if s > 0:
        count += 1

print(count)

Measured memory_bytes: 62180
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
#define INF 1000000001;
using namespace std;
struct Edge{int from, to, cost;};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    set<int> st;
    REP(i,n){

        int in;
        cin >> in;
          
        if(st.count(in))st.erase(in);
        
        else st.insert(in);
        
    }

    cout << st.size() << endl;

    return 0;
}


Measured memory_bytes: 4992
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
	ll A, B;
	cin >> A >> B;
	bool swapped = false;
	if (A > B) {
		swap(A, B);
		swapped = true;
	}
	cout << "100 100" << endl;
	A--;
	auto ans = make_vec_nd(false, 100, 100);
	ll x = 0;
	ll y = 0;
	while (A < B) {
		ans[x][y] = true;
		B--;
		x += 2;
		if (x >= 100) {
			x = 0;
			y += 2;
		}
	}
	if (x > 0) {
		x = 0;
		y++;
	}
	while (A > 0) {
		ans[x+1][y+1] = true;
		ans[x+2][y+1] = true;
		ans[x+3][y+1] = true;
		ans[x+1][y+2] = true;
		ans[x+3][y+2] = true;
		ans[x+1][y+3] = true;
		ans[x+2][y+3] = true;
		ans[x+3][y+3] = true;
		x += 4;
		A--;
		if (x + 4 >= 100) {
			x = 0;
			y += 4;
		}
	}
	rep(y,0,100) {
		rep(x,0,100) {
			if ((ans[x][y] && !swapped) || (!ans[x][y] && swapped)) {
				cout << '#';
			} else {
				cout << '.';
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 504
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]


def bfs(i, j):  # 引数はスタートの位置(i, j)
    q = deque()
    q.append((i, j))
    log = [[-1] * w for _ in range(h)]
    log[i][j] = 0
    distance = 0
    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    while q:
        p = q.popleft()
        for x, y in d:
            nx = p[0] + x
            ny = p[1] + y
            if not(0 <= nx < h and 0 <= ny < w):  # 迷路の外にはでれない
                continue
            elif s[nx][ny] == "#":  # 壁には進めない
                continue
            elif log[nx][ny] >= 0:  # 探索済みは探索しない
                continue
            else:
                log[nx][ny] = log[p[0]][p[1]] + 1
                q.append((nx, ny))
                if distance < log[nx][ny]:
                    distance = log[nx][ny]
    return distance


distance = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":  # start地点は壁でない
            continue
        else:
            temp = bfs(i, j)
            if temp >= distance:
                distance = temp
print(distance)

Measured memory_bytes: 43888
#include "bits/stdc++.h"
using namespace std;

int main(){
  int N, Y;
  cin >> N >> Y;
  for(int i = 0; i <= N; i++){
    for(int j = 0; j <= N - i; j++){
      int k = N - i - j;
      if(i * 10000 + j * 5000 + k * 1000 == Y){
        cout << i << " " << j << " " << k << endl;
        return  0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;
ll oddsolve(ll a){
    return (a+1)/2 % 2;
}
ll solve(ll a){
    if(a%2==0){
        return oddsolve(a+1)^(a+1);
    }else{
        return oddsolve(a);
    }
}

int main(){
    fast_io

    ll a, b;
    cin>>a>>b;
    cout<<(solve(b)^solve(a-1))<<endl;
    return 0;

}


Measured memory_bytes: 256
def myAnswer(H:int,W:int,S:list) -> None:
   XY = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
   index = []
   ans = [[0]*W for _ in range(H)]
   for i in range(H):
      for j in range(W):
         if(S[i][j] == "#"):
            ans[i][j] = "#"
            index.append([i,j])
   for i,j in index:
      for x,y in XY:
         if(0 > (j + x) or (j + x) >= W or 0 > (i + y) or (i + y) >= H):
            continue
         elif(ans[y+i][x+j]== "#"):
            continue
         else:
            ans[y + i][x + j] += 1
   for a in ans:
      string = ""
      for s in a:
         string += str(s)
      print(string)

def modelAnswer(H:int,W:int,S:list) -> int:
   dx = [1,0,-1,0,1,-1,-1,1]
   dy = [0,1,0,-1,1,1,-1,-1]
   for i in range(H):
      for j in range(W):
         if(S[i][j] == "#"):continue

         num = 0
         for d in range(8):
            ni = i + dy[d]
            nj = j + dx[d]
            if(ni < 0 or H <= ni):continue
            if(nj < 0 or W <= nj):continue
            if(S[ni][nj] == "#"): num+=1
         
         S[i][j] = str(num )
   for s in S:
      ans = ""
      for a in s:
         ans += a
      print(ans)
def main():
   H,W = map(int,input().split())
   S = [list(input()) for _ in range(H)]
   myAnswer(H,W,S[:])
if __name__ == '__main__':
   main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
//#include <map>
//#include <set>
//#include <list>
//#include <cmath>
//#include <ctime>
//#include <deque>
//#include <queue>
//#include <stack>
//#include <string>
//#include <bitset>
//#include <cstdio>
//#include <limits>
//#include <vector>
//#include <climits>
//#include <cstring>
//#include <cstdlib>
//#include <fstream>
//#include <numeric>
//#include <sstream>
//#include <iomanip>
//#include <iostream>
//#include <algorithm>
//#include <unordered_map>

using namespace std;

#define file freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.141592653589793238462643383279502884
#define MAX 200010
#define mod 1000000007
#define EPS 1E-9
#define int long long
#define endl "\n"

int fix(int cur, int m)
{
    return ((cur%m) + m) % m;
}

int fast_power(int x, int y,int m)
{
    if (y == 0)
        return 1;
    int temp = fast_power(x, y / 2, m) ;
    temp = (temp*temp)% m;
    if (y % 2 != 0)
        temp = (temp*x)% m;
    return temp;

}


int32_t main()
{
    //freopen("C:/Users/Joe/Desktop/tests/in11.txt", "r", stdin);
    //freopen("C:/Users/Joe/Desktop/tests/out11.txt", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.tie(0);

    int t=1;
    //cin >> t;
    while(t--)
    {
        int a,b;
        cin >> a >> b;
        if(a<b)
            cout << 0 << endl;
        else
            cout << 10 << endl;
        
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
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;
}

string replaceAll(string& replacedStr, string from, string to) {
	int pos = replacedStr.find(from);
	int toLen = to.length();
	if (from.empty())
	{
		return replacedStr;
	}
	while ((pos = replacedStr.find(from, pos)) != string::npos)
	{
		replacedStr.replace(pos, from.length(), to);
		pos += toLen;
	}
	return replacedStr;
}

int main() {
	vector<string> sample = { "dream","dreamer","erase","eraser" };
	string s; cin >> s;
	reverse(sample.begin(), sample.end());
	for (int i = 0; i < 4; i++) {
		reverse(sample.at(i).begin(), sample.at(i).end());
	}
	reverse(s.begin(), s.end());
	for (int i = 0; i < 4; i++) {
		replaceAll(s, sample.at(i), "");
	}
	if (s == "") {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
N = int(input())
L = list(map(int,input().split()))
dec = 10**18
Ans = 1
# print(len(L))
if(0 in L):
    print(0)
else:
    for i in L:
        Ans = Ans * i
        if dec < Ans:
            print(-1)
            break
    else:
        print(Ans)

Measured memory_bytes: 21792
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

ll a[1000100];

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

  int n, x, y;
  cin >> n >> x >> y;

  x--;
  y--;

  // i -> j への最短経路を考える
  // 経路のパターンは最大3つ
  // 1. i -> j へ ショートカットを使わずに直線で移動する
  // 2. i -> x, y -> j へショートカットを使って移動する
  // 3. i -> y, x -> j へショートカットを使って移動する

  rep(i, n) {
    rep(j, i + 1, n) {
      int dist = abs(i - j);
      dist = min(dist, abs(i - x) + 1 + abs(j - y));
      dist = min(dist, abs(i - y) + 1 + abs(j - x));
      a[dist]++;
    }
  }

  rep(i, 1, n) {
    cout << a[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n=int(input())
sp = {}
for i in range(n):
  s,p = list(input().split(' '))
  if s not in sp.keys():
    sp[s] = [[int(p), i+1]]
  else:
    sp[s].append([int(p),i+1])
for a in sorted(sp.items()):
  for p,i in sorted(a[1], reverse=True):
    print(i)

Measured memory_bytes: 3060
/* h-ex9_1
   Ohshima */

#include <stdio.h>
//スタックに格納するデータの最大数
#define SIZE 10

//スタックの定義
typedef struct stack{
  int size;
  int count;
  char data[SIZE];
  char *top;
}stack;

//スタックの初期化
void initialize_stack(stack *stk){
  stk->count = 0;
  stk->size = SIZE;
  stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
  if(stk->count >= stk->size){
    fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
    exit(1);
  }else{
    stk->top--;
    *(stk->top) = elem;
    stk->count++;
  }
}

//データの取り出し
void pop(stack *stk){
  if(stk->count <= 0){
    fprintf(stdout, "Error: stack underflow.\n");
    exit(1);
  }else{
    stk->top++;
    stk->count--;
  }
}

int main(void){
  stack stk;
  char tmp;
  int i;
  //スタックを初期化（ポインタ渡しで関数にわたすこと）
  initialize_stack(&stk);
  //1文字ずつ標準入力から受け取り以下を実行
  while(scanf("%c", &tmp) != EOF && tmp != '\n'){
    //B以外の文字のときスタックにデータを追加
    if(tmp != 'B'){
      push(&stk, tmp);
    }else{
      //Bがきた場合、文字列が空でないならデータを取り出す
      if(stk.count > 0){
        pop(&stk);
      }
    }
  }
  //最後に、スタックに残っている文字を古いものから1文字ずつ出力
  for(i = 0; stk.count-- > 0; i++){
    putchar(stk.data[SIZE - 1 - i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 1596
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val S = input.next()
    var count = 0
    var i = 0
    var j = S.length - 1
    
    while (i < j) {
      if (S[i++] != S[j--]) {
        ++count
      }
    }
    
    println(count)
  }
}

Measured memory_bytes: 36116