akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {
        long N = long.Parse(Console.ReadLine());

        string[] stList = new string[N];
        Dictionary<string, long> checkList = new Dictionary<string, long>();


        for (int i = 0; i < N; i++)
        {
            stList[i] = Console.ReadLine();
        }

        long ans = 0;

        for (int j = 0; j < N; j++)
        {
            var h1 = stList[j].ToArray();
            Array.Sort(h1);
            string k = String.Join("", (h1));
            if (checkList.ContainsKey(k))
            {
                ans += checkList[k];
                checkList[k] += 1;
            }
            else
            {
                checkList.Add(k,1);
            }
        }
        Console.WriteLine(ans);
    }
}

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

using namespace std;
#define int long long
#define N 666666
char str[N],st[N];
signed main(){
	int n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	cin>>(str+1);
	int len=strlen(str+1);
	int sum=0;
	int F=0;
	for(int i=b-1;i<=d+1;i++){
		if(str[i]=='.') sum++;
		else sum=0;
	//	cout<<sum<<'\n';
		if(sum>=3){
			F=1;
			break;
		}
	}
//	cout<<F<<'\n';
	int add=0;
	for(int i=a+1;i<=c;i++){
		if(str[i]=='#') add++;
		else add=0;
		if(add>1){
			cout<<"No";
			return 0;
		}
	}
	add=0;
	for(int i=b+1;i<=d;i++){
		if(str[i]=='#') add++;
		else add=0;
		if(add>1){
			cout<<"No";
			return 0;
		}
	}
	if(d>c){
		cout<<"Yes";return 0;
	}
	str[d]='#';
	add=0;
	int f=1;
	for(int i=a+1;i<=c;i++){
		if(str[i]=='#') add++;
		else add=0;
		if(add>1){
			f=0;break;
		}
	}
	if(f){
		cout<<"Yes";
	}else if(!f&&F){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 384
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (win, osx, linux)
 * Author: step_by_step
 * Time: 2020-03-19 17:35:03
**/

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
  
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("circus.in", "r", stdin);
    //freopen("circus.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    a = a * 60 + b;
    c = c * 60 + d;
    cout << max(0, c - a - e) << "\n";
    return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> h(n);
	for (int i = 0; i < n; i++) cin >> h[i];

	vector<vector<int>> relation(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		relation[a].push_back(b);
		relation[b].push_back(a);
	}

	for (int i = 0; i < n; i++) {
		sort(relation[i].begin(), relation[i].end());
		relation[i].erase(unique(relation[i].begin(), relation[i].end()), relation[i].end());
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		int count = 0;
		for (int j = 0; j < (int)relation[i].size(); j++) {
			if (h[relation[i][j]] < h[i]) count++;
		}
		if (count == (int)relation[i].size()) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 8800
#include<stdio.h>
int main(){
	unsigned long long a,b,x,s;
	scanf("%lld %lld %lld",&a,&b,&x);
	if(a%x==0)
		s=b/x-a/x+1;
	else
		s=b/x-a/x;
	printf("%lld\n",s);
	return 0;
	}

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



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n;
	string s;
	cin >> n >> s;
	int tot = accumulate(s.begin(), s.end(), 0, [&](int x, char c){ return x + c - '0'; });
	array<vector<int>, 2> prem; // tot-1, tot+1,   prem[i]: 2^i % d
	array<int, 2> init{};
	if(tot > 1){
		prem[0].push_back(1 % (tot - 1));
		for(auto i = 0; i < n; ++ i){
			prem[0].push_back(prem[0].back() * 2 % (tot - 1));
		}
		for(auto i = 0; i < n; ++ i){
			if(s[i] == '1'){
				init[0] = (init[0] + prem[0][n - 1 - i]) % (tot - 1);
			}
		}
	}
	prem[1].push_back(1 % (tot + 1));
	for(auto i = 0; i < n; ++ i){
		prem[1].push_back(prem[1].back() * 2 % (tot + 1));
	}
	for(auto i = 0; i < n; ++ i){
		if(s[i] == '1'){
			init[1] = (init[1] + prem[1][n - 1 - i]) % (tot + 1);
		}
	}
	for(auto i = 0; i < n; ++ i){
		if(s[i] == '1'){
			if(tot == 1){
				cout << "0\n";
			}
			else{
				int res = 1, x = (init[0] - prem[0][n - 1 - i] % (tot - 1) + (tot - 1)) % (tot - 1);
				while(x){
					++ res;
					x %= __builtin_popcount(x);
				}
				cout << res << "\n";
			}
		}
		else{
			int res = 1, x = (init[1] + prem[1][n - 1 - i]) % (tot + 1);
			while(x){
				++ res;
				x %= __builtin_popcount(x);
			}
			cout << res << "\n";
		}
	}
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 5724
#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> c(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        ++c[a];
        ++c[b];
    }
    for (int i = 0; i < N; ++i) {
        cout << c[i] << '\n';
    }
    return 0;
}


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


int main(void){
        int i;
        int n;
        int a[200200];
        int j;

        cin >> n;

  //      printf("done\n");
        for(i=0;i<n;i++){
                a[i] = 0;
        }
        for(i=1;i<n;i++){
                cin >> j;
                a[j-1]++;
        }

        for(i=0;i<n;i++){
                printf("%d\n", a[i]);
        }
        return 0;

}


Measured memory_bytes: 4544
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define     bit_1(a)       __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     pb             push_back
#define     pf             push_front
#define     mpr            make_pair
#define     ins            insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     vstr           vector<string>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))
#define     orderset1      tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define     orderset2      tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));
/// lcm(a,b)=a/gcd(a,b)*b (handle overflow)

bool sortinrev1(const pair<int,int>&a,const pair<int,int>&b)
{
    //return (a.first > b.first);
    if(a.first==b.first)return (a.second>b.second);
    else return (a.first > b.first);
}
bool sortinrev2(const pair<int,int>&a,const pair<int,int>&b)
{
    //return (a.first > b.first);
    if(a.first==b.first)return (a.second<b.second);
    else return (a.first > b.first);
}
int fx[]={1,-1,0,0};
int fy[]={0,0,1,-1};


int main()
{
    int d,t,s;
    cin>>d>>t>>s;
    if(t*s>=d)cout<<"Yes\n";
    else cout<<"No\n";
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1e9+7
#define EPS 1e-8
#define INF 1e9+10
#define INFL 1e18
typedef long long ll;
using namespace std;
int main()
{
   int N;
   cin >> N;
   double ans=0;
   rep(i,N){
       double a;
       cin >> a;
       ans+=1/a;
   }
   cout << fixed << setprecision(10) << 1/ans << endl;

}



Measured memory_bytes: 256
#include <stdio.h>
int n, d;
int a;

int main(){
    scanf("%d %d", &n, &d);
    if (fmod(n,2*d+1)==0) a = n/(2*d+1);
    else a = n/(2*d+1)+1;
    printf("%d", a);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
	int N,W;
	int v[100];
	int w[100];
	cin >> N >> W;
	for(int i=0;i<N;i++){
		cin >> v[i] >> w[i];
	}
	
	int DP[N+1][W+1];
	for(int i=0;i<=N;i++){
		DP[i][0] = 0;
	}
	for(int i=0;i<=W;i++){
		DP[0][i]=0;
	}
	for(int i=1;i<=N;i++)
		for(int j=1;j<=W;j++)
			if(j<w[i-1])
				DP[i][j] = DP[i-1][j];
			else{
				if(DP[i-1][j]>DP[i][j-w[i-1]]+v[i-1])
					DP[i][j]=DP[i-1][j];
				else
					DP[i][j]=DP[i][j-w[i-1]]+v[i-1];
			}

	cout << DP[N][W] << endl;
	
	return 0;
}
	

Measured memory_bytes: 5104
#include <bits/stdc++.h>
#define int long long int
#define endl '\n'
using namespace std;

void solve(){
    long double r; cin >> r;

    cout << 2*acos(-1)*r << endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3800
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author izban
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;

#ifdef HOME
#define db(x) { cerr << #x << " = " << x << endl; }
#define db2(x, y) { cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl; }
#define db3(x, y, z) { cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")" << endl; }
#define dbv(a) { cerr << #a << " = "; for (auto xxx: a) cerr << xxx  << " "; cerr << endl; }
#else
#define db(x) ;
#define db3(x, y, z) ;
#define db2(x, y) ;
#define dbv(a) ;
#endif

#define sz(a)  (int)(a).size()
#define all(a) (a).begin(),a.end()
#define pw(x)  (1LL << (x))


class A {
public:
    const string NO = "No";
    const string YES = "Yes";

    string solve(int n, int a, int b, int c, int d, string s) {
        a--;
        b--;
        c--;
        d--;
        for (int i = 1; i < n; i++) {
            if (s[i] == '#' && s[i - 1] == '#') {
                if (a < i - 1 && i < c) {
                    return NO;
                }
                if (b < i - 1 && i < d) {
                    return NO;
                }
            }
        }

        if (d < c) {
            for (int i = b; i <= d; i++) {
                if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
                    return YES;
                }
            }
            return NO;
        }
        return YES;
    }

    void solve(std::istream &in, std::ostream &out) {
        ios_base::sync_with_stdio(0);
        in.tie(0);

        int n, a, b, c, d;
        string s;
        in >> n >> a >> b >> c >> d >> s;
        out << solve(n, a, b, c, d, s) << endl;
    }
};


int main() {
    A solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;
int main(void)
{
    int a, b;
    cin >> a >> b;
    cout << (b - 1 + (a - 2)) / (a - 1) << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	string A,B,C;

	cin >> A >> B >> C;

	printf("A%cC\n",B[0]);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long dp[5005][5005],f[5005],t[5005];
int siz[5005];
vector<int>a[5005];
void dfs(int x,int fa){
    siz[x]=1;
    dp[x][1]=1;
    for(int i=0;i<a[x].size();i++){
        int u=a[x][i];
        if(u==fa)continue;
        dfs(u,x);
        for(int j=0;j<=siz[x];j++){
            t[j]=dp[x][j];
            dp[x][j]=0;
        }
        for(int j=0;j<=siz[x];j++)
            for(int k=0;k<=siz[u];k++)
                (dp[x][j+k]+=t[j]*dp[u][k]%mod)%=mod;
        siz[x]+=siz[u];
    }
    for(int i=0;i<=siz[x];i+=2)
        dp[x][0]=(dp[x][0]-dp[x][i]*f[i]%mod+mod)%mod;
}
int n,u,v;
int main(){
    scanf("%d",&n);
    for(int i=1;i<n;i++){
    	int u,v;
        scanf("%d%d",&u,&v);
        a[u].push_back(v);
        a[v].push_back(u);
    }   
    f[0]=1;
    for(int i=2;i<=n;i+=2)f[i]=f[i-2]*(i-1)%mod;
    dfs(1,0);
    printf("%lld",mod-dp[1][0]);
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    vector<int> lang[M];
    vector<int> nodes[N];
    vector<bool> visited(M, false);
    UnionFind uf(N);
    rep(i, N){
        int k; cin >> k;
        rep(j, k){
            int l; cin >> l;
            lang[l-1].push_back(i);
            nodes[i].push_back(l-1);
        }
    }
    rep(i, N){
        rep(j, nodes[i].size()){
            int l = nodes[i][j];
            if(!visited[l]){
                rep(k, lang[l].size()){
                    uf.merge(i, lang[l][k]);
                }
                visited[l] = true;
            }
        }
    }
    rep(i, N){
        if(uf.size(i) != N){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 8824
L = int(input())
c = [int(x) for x in input().split()]
cat, row, flag = [0]*101, [], 1
for i,j in enumerate(c):
    if j > 0 and cat[j] == 0:
        row.append(j)
        cat[j] = 1
    elif j < 0 and cat[-j] == 1 and row[-1] == -j:
        row.pop()
        cat[-j] = 0
    else:
        flag = 0
        break
if flag: print('OK')
else: print(i+1)


Measured memory_bytes: 5620
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
//#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
const lli INF = 1e18L+5;
/*
lli power(lli x,lli y)
{
	lli res=1;
	while(y>0)
	{
		if(y%2==1)
			res=(res*x)%mod;
		x=(x*x)%mod;
		y=y/2;
	}
	return res;
}
*/
int main()
{
	//cout.precision(10);
	//cout.setf(ios::fixed,ios::floatfield);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	lli T=1;
	//cin>>T;
	while(T--)
	{
		lli n,i,j,z,sum=0;
		vector<lli> v;
		cin>>n;
		for(i=0;i<n;i++)
		{
			cin>>z;
			v.pb(z);
		}
		for(i=0;i<n-1;i++)
		{
			for(j=i+1;j<n;j++)
			{
				sum+=(v[i]*v[j]);
			}
		}
		cout<<sum<<endl;
	}
}


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

int main() {
  string S; cin >> S;
  bool flag = true;
  
  if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) {
    flag = false;
  }
  
  if (flag) {
    cout << "Good" << endl;
  } else {
    cout << "Bad" << endl;
  }
  
  return 0;
}

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

int main() {
  int ans = 700;
  char c;
  for (int i = 0; i < 3; i++) {
    cin >> c;
    if (c == 'o') {
      ans += 100;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  vector<string> S(3);
  for (int i = 0; i < 3; i++) {
    cin >> S[i];
  }

  int usr = 0;
  while (true) {
    if (S[usr].empty()) {
      break;
    }
    char u = S[usr][0];
    S[usr].erase(S[usr].begin(), S[usr].begin()+1);
    usr = u-'a';
  }

  cout << (char)('A'+usr) << endl;
  return 0;
}


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


int main(){
    long long n,ans=0,a=0,b=0,c=0;
    
    cin >> n;
    int j=0;
    
    for(int i=0;i<n;i++){
        char s[15];
        cin >> s;
        for(j=0;s[j]!='\0';j++){
            if(s[j]=='A'&&s[j+1]=='B')ans++;
        }
        if(s[0]=='B')b++;
        if(s[j-1]=='A')a++;
        if(s[0]=='B'&&s[j-1]=='A')c++;
    }
    if(c==a && c==b && c>0){
        cout << ans + c - 1 << endl;
    }else{
        cout << ans + min(a,b) << endl;
    }
    
}

Measured memory_bytes: 256
from collections import deque
n=int(input())
a=[x for x in input().split()]
b=deque()
for i in range(n):
  if i%2==0:
    b.append(a[i])
  else:
    b.appendleft(a[i])
print(' '.join(list(b) if n%2==0 else list(b)[::-1]))

Measured memory_bytes: 26564
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#define CLR(x) memset((x), -1, sizeof(x))
const int MAXN = 1e5+5;
std::vector<int> G[MAXN];
int A[MAXN];  // Aoki
int T[MAXN];  // Takahashi
int N, u, v;

void bfs(int src, int (&D)[MAXN]) {
  CLR(D);
  std::queue<int> Q;
  D[src] = 0;
  Q.push(src);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int v: G[u]) {
      if (D[v] == -1) {
        D[v] = D[u] + 1;
        Q.push(v);
      }
    }
  }
}

int main() {
  scanf(" %d%d%d", &N, &u, &v);
  for (int i = 1; i < N; ++i) {
    int a, b;
    scanf(" %d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  bfs(u, T);
  bfs(v, A);
  int w = u;
  for (int i = 1; i <= N; ++i) {
    if ((A[i] > T[i]) && (A[i] > A[w])) {
      w = i;
    }
  }
  int ret = A[w] - 1;
  printf("%d\n", ret);
  return 0;
}

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

int N;
int A[2][100];

int dfs(int n, int row, int col, long long sum) {
    if (n == N) {
        return sum;
    }
    // printf("n: %d row: %d col: %d sum: %d\n", n, row, col, sum);

    int p1 = 0, p2 = 0;
    // 右
    if (row < N - 1) {
        p1 = dfs(n + 1, row + 1, col, sum + A[col][row + 1]);
    }

    // 下
    if (col < 1) {
        p2 = dfs(n + 1, row, col + 1, sum + A[col + 1][row]);
    }

    // printf("p1: %d p2: %d\n", p1, p2);
    if (p1 > p2) return p1;
    else return p2;
}
int main() {
    cin >> N;
    rep(i, 2)rep(j, N) cin >> A[i][j];

    // 2 ** 100 は無理
    long long ans = dfs(0, 0, 0, A[0][0]);
    cout << ans << endl;
}

Measured memory_bytes: 256
from bisect import bisect_right, bisect_left


n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
print(sum(bisect_left(a, i) * (n - bisect_right(c, i)) for i in b))


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

#define REP(i,n)    for(int i = 0; i < (int)n; i++)
#define MAX_N   100000
#define MAX_M   100000


void solve(){
    float n;
    cin >> n;
    float x = n / 1.08;
    int ans = x;
    if(x == ans)
        cout << ans << endl;
    else{
        ans++;
        int tmp = ans * 1.08;
        if(tmp == n)
            cout << ans << endl;
        else
            cout << ":(\n";
    }
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()

signed main() {
	int n;
	std::cin >> n;
	rep(i,n-1) {
		for(int j=i+1;j<n;j++) {
			int level = 1;
			for(int l=1;l<=n;l<<=1,level++) {
				if((i&l)!=(j&l)) {
					std::cout << level << ' ';
					break;
				}
			}
		}
		std::cout << ENDL;
	}


	return 0;
}


Measured memory_bytes: 512
n=int(raw_input())
s=[]
h=[]
c=[]
d=[]
ss=[]
hh=[]
cc=[]
dd=[]

for i in range(n):
	a=raw_input().split()
	
	if a[0]=="S":
		s.append(int(a[1]))
	elif a[0]=="H":
		h.append(int(a[1]))
	elif a[0]=="C":
		c.append(int(a[1]))
	elif a[0]=="D":
		d.append(int(a[1]))
for i in range(1,14):
	if i not in s:
		ss.append(i)
	if i not in h:
		hh.append(i)
	if i not in c:
		cc.append(i)
	if i not in d:
		dd.append(i)
for i in ss:
	print "S "+str(i)
for i in hh:
	print "H "+str(i)
for i in cc:
	print "C "+str(i)
for i in dd:
	print "D "+str(i)


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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  string s;
  cin >> s;
  const string kk = "keyence";
  REP(i,8) {
    int head_l = i, tail_l = kk.size() - i;
    if(s.substr(0,head_l)+s.substr(s.size()-tail_l, tail_l) == kk) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
/***** MAIN *****/


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

using ll=long long;
const ll MOD=1000000007;

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


Measured memory_bytes: 3624
# -*- coding: utf-8 -*-

# from time import time
# 
# start = time()


def six(n):
    n_str = str(n)
    while len(n_str) < 6:
        n_str = "0" + n_str

    return n_str


N, M = map(int, input().split())

id_list = [None] * M
dic_P = {}
info = []
info_idx = 0

for i in range(M):
    P, Y = map(int, input().split())
    id_list[i] = [P, Y, ""]
    if P in dic_P.keys():
        info[dic_P[P]].append([i, P, Y])
    else:
        dic_P[P] = info_idx
        info_idx += 1
        info.append([[i, P, Y]])

for group in info:
    group.sort(key=lambda a_i: a_i[2], reverse=False)
    for i, pair in enumerate(group):
        id = six(pair[1]) + six(i+1)
        id_list[pair[0]] = id

for id in id_list:
    print(id)

# print(time() - start)


Measured memory_bytes: 53152
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int k, x;
    readf("%s %s", &k, &x);
    readln;
    
    int mn = max(- (10 ^^ 6), x - k + 1);
    int mx = min(10 ^^ 6, x + k - 1);
    
    for (int i = mn; i <= mx; ++i) {
        if (i > mn) { write(' '); }
        write(i);
    }
    writeln();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long int 
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000001
#define MAXN        400005
#define mod         1000000007 
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll i,count=0,count1=0;
    for(i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]=='1'){
                count++;
            }
        }
        else{
            if(s[i]=='0'){
                count++;
            }
        }
    }
    for(i=0;i<s.size();i++){
        if(i%2==1){
            if(s[i]=='1'){
                count1++;
            }
        }
        else{
            if(s[i]=='0'){
                count1++;
            }
        }
    }
    count=min(count,count1);
    cout<<count;
}

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

int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    int res = 100*r + 10*g + b;
    if(res%4) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d,f,g,h,j,i;
	char z[101];
	scanf("%s",z);
	a=strlen(z);
	printf("%c%d%c\n",z[0],a-2,z[a-1]);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;

int main() {
  int w, a, b;
  cin >> w >> a >> b;

  if (b > (a+w)) {
    cout << b - (a+w) << endl;
  } else if (a > (b+w)) {
    cout << a - (b+w) << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define ull 		unsigned long long
#define ll 			long long
#define M 			1000000007
#define pb 			push_back
#define p_q 		priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios	    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp 			make_pair
#define lb 			lower_bound
#define ub			upper_bound
#define F           first
#define S           second
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a,n,b)	for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)		__builtin_popcountll(a)
#define hell 		(ull)1e9
#define re 			resize
#define un(a)		sort(a.begin(),a.end());a.resize(unique(a.begin(),a.end())-a.begin())
int n,a[(ll)1e5+1],freq[2][(ll)1e5+1];



signed main(void)
{ios
	cin>>n;
	rep(i,0,n)
	{
		cin>>a[i];
		freq[i%2][a[i]]++;
	}
	vii v,v1;
	rep(i,0,(ll)1e5+1){
		if(freq[0][i]!=0)
			v.pb({-freq[0][i],i});
	}
	v.pb({0,(ll)2e5+1});
	rep(i,0,(ll)1e5+1){
		if(freq[1][i]!=0)
			v1.pb({-freq[1][i],i});
	}
	v1.pb({0,(ll)2e5+1});
	sort(all(v));
	sort(all(v1));
	if(v[0].second!=v1[0].second){
		cout<<n+v[0].first+v1[0].first<<endl;
	}
	else{
		cout<<min(n+v[0].first+v1[1].first,n+v[1].first+v1[0].first)<<endl;
	}
}

Measured memory_bytes: 4980
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>

#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;
char a[1000];
char b[1000];
int main() {
ss(a)
ss(b)
    if(strlen(a)-strlen(b) == 0){
        for(int i = 0; i < strlen(a); i ++){
        pc(a[i])
        pc(b[i])
    }
    }else{
        for(int i = 0; i < strlen(a)-1; i ++){
        pc(a[i])
        pc(b[i])
    }
    pc(a[strlen(a)-1])
    }

    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <climits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;
typedef long long ll;
#define ln '\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define drep(i,n) int i = 0;for(;i<(n);++i)
#define FOR(i,s,e) for(int i=s;i<=(e);++i)
#define FORR(i,s,e) for(int i=s;i>=(e);--i)
#define fore(a, x) for(auto& a : x)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ft first
#define sd second
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define Fill(a,b) memset(a,b,sizeof(a))
template<typename T1, typename T2> bool Max(T1& a, T2 b) { return a<b ? a = b, 1 : 0; }
template<typename T1, typename T2> bool Min(T1& a, T2 b) { return a>b ? a = b, 1 : 0; }

const int N = 500;
ll inf = 1e10;
int tar[8];
ll g[N][N];
ll f[1 << 8][8];

void solve() {
  int n, m, r, u, v, w;
  cin >> n >> m >> r; 
  rep(i, r)cin >> tar[i], tar[i]--;
  rep(i, n)rep(j, n)g[i][j] = inf;
  rep(i, m) {
    cin >> u >> v >> w;
    u--, v--;
    g[u][v] = g[v][u] = w;
  }
  rep(k, n)rep(i, n)rep(j, n)Min(g[i][j], g[i][k] + g[k][j]);
  rep(sub, 1 << r) {
    rep(i, r)if ((1 << i) & sub) {
      int cur = sub - (1 << i);
      if (!cur) f[sub][i] = 0;
      else {
        f[sub][i] = inf;
        rep(j, r)if ((1 << j)&cur) {
          Min(f[sub][i], f[cur][j] + g[tar[i]][tar[j]]);
        }
        
      }
      //cout << "sub " << sub << " i " << i << " " << f[sub][i] << ln;
    }
  }
   ll ans = inf;
   rep(i, r)Min(ans, f[(1 << r)-1][i]);
   cout << ans << ln;


}


void init() {
  
}

int main(void) {
  ios::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
  //freopen("C:\\Users\\LENOVO\\Documents\\Visual Studio 2015\\Projects\\Test\\Input\\in.in", "r", stdin);

  init();
  int TC = 1;
#if 0
  cin >> TC; cin.get();
#endif
  FOR(TI, 1, TC) {
    //cout << "Case #" << TI << ": ";
    solve();
  }
  
  
  return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int n;
    cin >> n;
    vl a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(all(a));
    ll mn = a[0];
    ll ans = INF;
    rep1(i,n){
        ll tmp= __gcd(mn,a[i]);
        //cout << tmp << endl;
        ans = min({ans,mn,tmp});
    }
    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 1024
fn main(){
    let mut input = String::new();
    std::io::stdin().read_line(&mut input);
    let mut nums = input.split_whitespace().map(|x| x.parse::<i32>().unwrap());
    let a = nums.next().unwrap();
    let b = nums.next().unwrap();
    println!("{} {}", a*b, a*2+b*2);
}



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

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

int main(){

  int year, month, day;
  char c;

  cin >> year >> c >> month >> c >> day; 
  
  if(year <= 2019 and month <= 4 and day <= 30)
    pr("Heisei");
  else
    pr("TBD");
  
  return 0;

}


Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map(&:to_i)

asum = 0

A.each_with_index do |a, i|
  asum += a * ((-1) ** i)
end

result = [asum]

(N-1).times do |i|
  result << A[i] * 2 - asum
  asum = result.last
end

puts result.join(' ')


Measured memory_bytes: 14084
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var N int
  var A []int
  NextInt(&N)
  NextIntSlice(&A)
  X := 0
  for _, a := range A { X ^= a }
  B := make([]int, N)
  for i, a := range A {
    B[i] = X ^ a
  }
  WriteIntSlice(B)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  Write(B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 29952
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int n;  //スイッチの個数
    int m;  //電球の個数
    int ans = 0;
    cin >> n >> m;
    vector<int> a(n);   /* a[s]はビット列で、スイッチs(0-index)と
                           電球iがつながっていればa[s]のiビット目は1。
                           つながっていなければa[s]のiビット目は0 */

    rep(i, m) {
        int k;  //電球iとつながっているスイッチの個数
        cin >> k;
        rep(j, k) {
            int s;  //電球iとつながっているスイッチの番号
            cin >> s;
            s--;    //sを0-indexにする
            a[s] |= (1 << i);   /* 電球iがスイッチsとつながっていれば
                                   a[s]のiビット目を1にする */
        }
    }

    //すべての電球が点灯するようなビット列p
    int p = 0;
    rep(i, m) {
        int x;
        cin >> x;
        p |= (x << i);
    }

    //どのスイッチを押すか全探索
    // 00…0(0がn個)から11…1(1がn個)のbit列を全て調べる
    for(int b = 0; b < (1 << n); b++) {

        int t = 0;
        rep(s, n) {
            //bのsビット目が1だったら
            if( (b >> s) & 1 ) {
                //スイッチsを押す
                t ^= a[s];
            }
        }

        //電球が全て光ったら
        if(t == p) {
            //ansを1増やす
            ans++;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589
#define endl "\n"
#define int long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define fr(i,a,b) for (int i = (a); i < (b); ++i)

int dp[3001][3001];

void solve(){
    string s, t;
    cin >> s >> t;
    int n = sz(s), m = sz(t);
    fr(i, 0, n){
        fr(j, 0, m){
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            if(s[i] == t[j]) dp[i + 1][j + 1] = max(1 + dp[i][j], dp[i + 1][j + 1]);
        }
    }
    string ans = "";
    int i = n, j = m;
    while(i != 0 && j != 0){
        if(dp[i][j] == dp[i - 1][j]){
            --i;
            continue;
        }
        if(dp[i][j] == dp[i][j - 1]){
            --j;
            continue;
        }
        --i;
        --j;
        ans += s[i];
    }
    reverse(all(ans));
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    t = 1;
    //cin >> t;
    while(t--) {solve();}
    return 0;
}


Measured memory_bytes: 70656
object Main extends App {
  var array = Vector.empty[Int]
  var k = 0
  for(i<-1 to 6) {
    if (i == 6) {
      k = scala.io.StdIn.readInt()
    } else {
      array :+= scala.io.StdIn.readInt()
    }

  }
  val distance = array.max - array.min
  if (distance <= k) {
    println("Yay!")
  } else {
    println(":(")
  }

}

Measured memory_bytes: 25404
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int P,Q,R; cin >> P >> Q >> R;
    cout << min(P+Q,min(R+P,R+Q)) << endl;
}

Measured memory_bytes: 256
#define l(a,b) (long long)a*b/g(a,b)
int g(int n,int m){return n%m==0?m:g(m,n%m);}
int main(){int i,x,a[3],m[3],p[3];while(scanf("%d %d %d %d %d %d ",a,m,a+1,m+1,a+2,m+2),*a){for(i=3;i--;)for(p[i]=1,x=1;(x=(a[i]*x)%m[i])!=1;p[i]++);printf("%lld\n",l(l(p[0],p[1]),p[2]));}}

Measured memory_bytes: 0
#include<stdio.h>
#include<math.h>

static const int N = 10000;

main(){
  int n, i;
  int numbers[N];
  
  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &numbers[i]);
  }

  printf("%d\n", primary(numbers, n));
  return 0;
}

int primary(int numbers[], int n){
  int i, j, divisora, prime = 0;

  for(i = 0; i < n; i++){
    divisora = 0;
    if(numbers[i] == 1){
      divisora++;
    } else if(numbers[i] != 2){
        if(numbers[i] % 2 == 0){
	  divisora++;
        } else {
          for(j = 3; j <= sqrt(numbers[i]); j += 2){
	    if(numbers[i] % j == 0){
	      divisora++;
	      break;
	    }
          }
        }
    }
    if(divisora == 0){
       prime++; 
    }
  }
  return prime;
}

Measured memory_bytes: 632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <cstdlib>
#define mp make_pair
#define pb push_back
#define mem(i,a) memset(i,a,sizeof(i))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int INF=1000000007;
const int DMAX=100000+5;
const int MOD=6000000;
template<class T> inline void read(T &x){
    x=0; 
    T f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-'){
            f=-1;
        }
        ch=getchar();
    }
    while(ch<='9' && ch>='0'){
        x=x*10+(ch-'0');
        ch=getchar();
    }
    x*=f;
}
int k;
int n;
int a[DMAX];
int main(){
	read(n);
	read(k);
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	int ans=INF;
	for(int i=k;i<=n;i++){
		ans=min(ans,a[i]-a[i-k+1]);
	}
	printf("%d\n",ans );
	return 0;
}

Measured memory_bytes: 4132
#include <bits/stdc++.h>
using namespace std;
int main(){
	priority_queue<int> pq;
	int n ,m, sum=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&m);
		sum = sum+(m-1);
	}
	printf("%d",sum);
}

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

int main(){
    vector<int> cnt(5, 0);
    for (int i = 0; i < 6; i++) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    if (count(cnt.begin(), cnt.end(), 3) > 0) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

#[proconio::fastout]
fn main() {
	input! {
		n: usize,
		a: [(isize, isize); n],
	}
	let inf = 999999999999999999isize;

	let mut zmax = -inf;
	let mut zmin = inf;
	let mut wmax = -inf;
	let mut wmin = inf;
	for i in 0..n {
		let x = a[i].0;
		let y = a[i].1;
		zmax = max(zmax, x+y);
		zmin = min(zmin, x+y);
		wmax = max(wmax, x-y);
		wmin = min(wmin, x-y);
	}

	println!("{}", max(zmax-zmin,wmax-wmin));
}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

	int n;
	cin >> n;

	map<int, int> mp;
	int boss;

	for (int i = 1; i < n; i++) {
		cin >> boss;
		mp[boss]++;
	}

	for (int i = 1; i <= n; i++) {
		cout << mp[i] << endl;
	}

	return 0;
}

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

int main() {
    int x;
    cin >> x;
    int number = x / 100;
    int left = x % 100;
    if(number * 5 >= left){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
    
}



Measured memory_bytes: 384
def main():
    rev = {'b': 'd', 'd': 'b', 'p': 'q', 'q': 'p'}
    S = input()
    if len(S) % 2 == 1:
        print("No")
        return
    for i in range(len(S)//2):
        if S[i] != rev[S[len(S)-1-i]]:
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()


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

const ll INF = 1e9;

int main(){
    int h,n; cin >> h >> n;
    vector<int> a(n+1),b(n+1);
    rep(i,n) cin >> a[i] >> b[i];
    vector<ll> dp(h+10010,INF);
    dp[0] = 0;
    rep(i,n){
        rep(j,h+1){
            dp[j+a[i]] = min(dp[j+a[i]], dp[j]+b[i]);
        }
    }
    ll res = INF;
    for(int i=h;i<=h+10000;i++){
        res = min(res, dp[i]);
    }
    cout << res << endl;
}

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

int main () {
  int a , b , k ;
  cin >> a >> b >> k ;
  if( (( b - a + 1) / 2 ) < k ) {
    for(int i = a ; i <= b ; i++) cout << i << endl ;
  } else {
    for(int i = a ; i <= a + k - 1 ; i++ ) cout << i << endl ;
    for(int i = b - k + 1 ; i <= b ; i++ ) cout << i << endl ;
  }
}

Measured memory_bytes: 256