akhauriyash/Code-Regression huggingface dataset:
// abc166_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    REP(i, N) cin >> H[i];

    vector<bool> A(N, true);
    REP(i, M){
        int a, b;
        cin >> a >> b;
        a--; b--;

        if (H[a] < H[b]){
            A[a] = false;
        } else if (H[a] > H[b]){
            A[b] = false;
        } else {
            A[a] = false;
            A[b] = false;
        }
    }

    int ans = 0;
    REP(i, N){
        if (A[i]) ans++;
    }

    print(ans);


    return 0;
}


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

//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	int n;
	cin >> n;
	vector<int> d(n);
	FOR(i, 0, n) cin >> d[i];
	const int mod = 998244353;
	bool ok = d[0] == 0;
	FOR(i, 1, n) ok &= d[i] > 0;
	if (!ok){
		cout << 0 << endl;
		return 0;
	}

	vector<int> cnt(n, 0);
	for(auto i: d) cnt[i]++;
	while(cnt.back() == 0) cnt.pop_back();
	for(auto i: cnt) if (!i){
		cout << 0 << endl;
		return 0;
	}

	int ans = 1;
	FOR(i, 1, SZ(cnt)) FOR(j, 0, cnt[i]) ans = (ans * (LL) cnt[i - 1]) % mod;
	cout << ans << endl;	
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}


Measured memory_bytes: 4060
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}
int gcd(int x, int y){
	if(x<y){
    return gcd(y,x);
  }
  if(y==0){
    return x;
  }
  return gcd(y,x%y);
}
int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}






int main() {
  int N;
  cin>>N;
  int x[100001];
  for(int i=0;i<100001;i++){
    x[i]=0;
  }
  x[0]++;
  for(int i=0;i<N;i++){
    int z,y;
    cin>>z>>y;
    for(int j=z;j<=y;j++){
      x[j]++;
    }

  }
  int sum=0;
  for(int i=1;i<100001;i++){
    if(x[i]>0){
      sum++;
    }
  }
  cout<<sum<<endl;


  
 
  




  


  





  

  
  
  


  
  


  

  




  
  
}

  

  

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

#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()

using namespace std;

int main() {
    while (true) {
        int n, m;
        cin >> n >> m;
        if (n == 0)
            break;
        vector<int> scores(n, 0);
        REP(i, m) REP(j, n) {
            int p;
            cin >> p;
            scores[j] += p;
       }
       cout << *max_element(all(scores)) << endl;
    }
    return 0;
}


Measured memory_bytes: 3056
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

int main()
{
    int rp, max, K;
    cin >> rp >> max >> K;
    max -= rp;
    vector<int> T(K + 1);
    for (int i = 0; i <= K; i++) {
        cin >> T[i];
    }
    vector<vector<int>> dp(K + 1, vector<int>(max + 1, 0));
    for (int i = 0; i < K; i++) {
        dp[i][1] = T[0];
    }
    constexpr int INF = 1 << 30;
    vector<int> f(max + 1, INF);
    f[0] = 0;
    f[1] = 0;

    for (int j = 2; j <= max; j++) {
        for (int i = 1; i <= K; i++) {
            int mini = INF;
            for (int l = 1; l < j; l++) {
                mini = min(mini, dp[i - 1][j - l] + f[l] + l * T[i]);
            }
            dp[i][j] = mini;
            f[j] = min(f[j], mini);
        }
        dp[0][j] = f[j] + j * T[0];
    }
    cout << fixed << setprecision(15) << (long double)f[max] / max << endl;

    return 0;
}

Measured memory_bytes: 3404
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
#include<iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(n,x) for(ll i=0;i<n;i++) cin>>x[i];


int main()
{
	
	ll n, k, q;
	cin >> n >> k >> q;
	vector<ll> x(q);
	rep(q, x);
	vector<ll> y(n, 0);
	for (ll i = 0; i < q; i++)
	{
		y[x[i] - 1]++;
	}
	for (ll i = 0; i < n; i++)
	{
		y[i] = k + y[i] - q;
	}
	for (ll i = 0; i < n; i++)
	{
		if (0 < y[i])
		{
			cout << "Yes" << "\n";
		}
		else
		{
			cout << "No" << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 4768
/**
*    created: 23.05.2020 12:32:12
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    if (m <= n) {
        cout << 0 << endl;
        return 0;
    }
    vector<int> x(m);
    rep(i,m) cin >> x[i];
    sort(x.begin(), x.end());
    int range = x[m-1] - x[0];
    vector<int> dif(m-1);
    rep(i,m-1) dif[i] = x[i+1] - x[i];
    sort(dif.rbegin(), dif.rend());
    int sum = range;
    rep(i,n-1) sum -= dif[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1e9+7;
using  P=pair<ll,ll>;
int main(){
  ll N,K;
  long double ans;
  cin>>N>>K;
  ll maxkaisuu=0;
  queue<ll> q;
  for(ll i=1;i<=N;i++){
    ll count=0;
    ll x=i;
    while(x<K){
      x*=2;
      count++;
    }
    q.push(count);
    maxkaisuu=max(maxkaisuu,count);
  }
  ll sum=0;
  while(!q.empty()){
    ll a=maxkaisuu-q.front();
    q.pop();
    sum+=(1<<a);
  }
  ans=(long double)sum/(long double)(1<<maxkaisuu)/(long double)N;
  cout<<fixed<<setprecision(12)<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

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

    int h, w;
    h=w=100;

    vector<vector<char> > ans(h,vector<char>(w,'.'));
    for(int i=0; i<h/2; i++){
        for(int j=0; j<w; j++){
            if(A>0 && i%2==0 && j%2){
                A--;
                continue;
            }else{
                ans[i][j]='#';
            }
        }
    }
    for(int i=h-1; i>=h/2; i--){
        for(int j=0; j<w; j++){
            if(B>0 && i%2 && j%2){
                ans[i][j]='#';
                B--;
            }
        }
    }

    cout << h << ' ' << w << endl;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cout << ans[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
import math
n, d = map(int, input().split())
xy = []
for i in range(n):
    x, y = map(int, input().split())
    xy.append([x, y])
c=0
for i in xy:
    dist = math.sqrt((i[0]**2)+(i[1]**2))
    c += 1 if dist<=d else 0
print(c)

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

int main() {
  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());

  long L = -2e18, R = 2e18;
  while (R - L > 1) {
    long M = (L + R) / 2, cnt = 0;
    for (int i = 0; i < N; i++) {
      if (A.at(i) < 0) {
        int l = i, r = N;
        while (r - l > 1) {
          int m = (l + r) / 2;
          (A.at(i) * A.at(m) < M) ? r = m : l = m;
        }
        cnt += N - r;
      } else {
        int l = i, r = N;
        while (r - l > 1) {
          int m = (l + r) / 2;
          (A.at(i) * A.at(m) < M) ? l = m : r = m;
        }
        cnt += l - i;
      }
    }
    (cnt < K) ? L = M : R = M;
  }
  cout << L << "\n";
}

Measured memory_bytes: 1920
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 main(){
  int n;
  cin>>n;
  n%=10;
  if(n==3)cout<<"bon"<<"\n";
  else if(n==0||n==1||n==6||n==8){
    cout<<"pon"<<"\n";
  }else cout<<"hon"<<"\n";
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
// initialize: UnionFind UF(N)

class UnionFind {                                              // OOP style
private:
	vector<int> p, rank, setSize;
	// p = path toward the root of disjoint set; p[i] = i means it is root
	// rank = upper bound of the actual height of the tree; not reliable as accurate measure
	// setSize = size of each disjoint set

	int numSets;
public:
	UnionFind(int N) {
		setSize.assign(N, 1);
		numSets = N;
		rank.assign(N, 0);
		p.assign(N, 0);
		for (int i = 0; i < N; i++) p[i] = i;	// each belongs to its own set
	}

	int findSet(int i) {
		return (p[i] == i) ? i : (p[i] = findSet(p[i]));		// path compression: cut short of the path if possible
	}

	bool isSameSet(int i, int j) {
		return findSet(i) == findSet(j);
	}

	void unionSet(int i, int j) {
		if (!isSameSet(i, j)) {
			numSets--;
			int x = findSet(i), y = findSet(j);
			// rank is used to keep the tree short
			if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
			else {
				p[x] = y; setSize[y] += setSize[x];
				if (rank[x] == rank[y]) rank[y]++;
			}
		}
	}

	int numDisjointSets() {		// # of disjoint sets
		return numSets;
	}

	int sizeOfSet(int i) {		// size of set
		return setSize[findSet(i)];
	}
};

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

	int n, m, i, j, k, a, b, ct;
	cin >> n >> m;
	vector<int> pr(n + 1);
	for (i = 1; i <= n; i++) cin >> pr[i];
	UnionFind uf(n + 1);
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		uf.unionSet(a, b);
	}

	map<int, set<int>> ss;
	for (i = 1; i <= n; i++) ss[uf.findSet(i)].insert(i);

	ct = 0;
	for (auto p : ss) {
		for (auto pp : p.second) {
			if (p.second.find(pr[pp]) != p.second.end()) ct++;
		}
	}
	cout << ct << "\n";

	return 0;
}


Measured memory_bytes: 15872
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main(){
    string s;
    cin>>s;
    int ans=0,k=0,l=0,m;
    rep(i,s.size()-1){
        if(s[i]==s[i+1]){
            k++;
        }
        else{
            ans+=1+2*(k/3);
            if(k%3==2)ans++;
            m=k%3;
            if(l==1){
                if(m==1){
                    ans++;
                    m--;
                }else if(m==2)m--;
            }
            l=m;
            k=0;
        }
    }
    ans+=1+2*(k/3);
    if(k%3==2)ans++;
    m=k%3;
    if(l==1&&m==1)ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;

map<pll, ll> mp;

ll power(ll x, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res = (res * x) % mod;
        }
        x = (x * x) % mod;
        n /= 2;
    }
    return res;
}

ll solve(ll n, ll k) {
    pll p(n, k);
    if (mp.find(p) != mp.end())
        return mp[p];
    if (n < 0)
        return 0;
    if (k == 0)
        return 1;
        
    ll x = (1LL) << (k - 1);
    if (n >= 4 * x - 1)
        return power(3, k);
    ll res = (solve(n - 2 * x, k - 1) + solve(n - x, k - 1) + solve(n, k - 1)) % mod;
    mp[p] = res;
    //cerr << p.first << " " << p.second << " " << res << endl;
    return res;
}

void solve() {
    ll n;
    cin >> n;
    cout << solve(n, 62) << endl;
}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

int main() {
	char S[5] = { 0,0,0,0 ,0};
	scanf("%s", &S[0]);
	int flag = 0;

	for (int i = 0; i<3; i++) {
		if (S[i] == S[i + 1]) {
			flag = 1;
		}
	}

	if (flag == 1) {
		printf("Bad\n");
	}
	else {
		printf("Good\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll h[2],m[2],k;
    cin>>h[0]>>m[0]>>h[1]>>m[1]>>k;
    cout<<(h[1]-h[0])*60+m[1]-m[0]-k;
    
}


Measured memory_bytes: 3544
def factorization(n):
    res = set()
    tmp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if tmp % i == 0:
            while tmp % i == 0:
                tmp //= i
            res.add(i)
    res.add(tmp)
    return res

a, b = map(int,input().split())
ans = factorization(a) & factorization(b) | {1}
print(len(ans))


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

typedef long long ll;
typedef long double ld;
using namespace std;
//mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back

int main() {
    ll n;
    cin >> n;
    string ans;
    while(n) {
        ans += ('a' + (n-1) % 26);
        n = (n-1)/26;
    }
    reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll INF = 1LL << 30;

ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}

int main(void){
    int M,D; cin >> M >> D;
    
    int count = 0;
    for(int i = 1; i <= M; i++){
        for(int j = 1; j <= D; j++){
            string s = to_string(j);
            if(s.size() == 2){
                int d1 = s[0] - '0';
                int d2 = s[1] - '0';
                if((d1>=2 && d2>=2) && (d1 * d2 == i)){
                    count++;
                }
            }
        }
    }
    cout << count << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  ll n = s.size();
  vll l(n);
  ll tmp = 0;
  vll num(2020, 0);

  ll ss = 1;
  for(int i=n-1;i>=0;i--){
    tmp = (tmp + ss*(s[i]-'0'))%2019;
    l[i] = tmp;
    num[l[i]]++;
    ss = (ss*10)%2019;
  }

  tmp = 0;
  ll ans = 0;
  for(int i=n-1;i>=0;i--){
    ans += num[tmp];
    tmp = l[i];
    num[l[i]]--;
    //std::cout << l[i] << '\n';
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4640
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
ll L;
const int maxN = 2e5 + 10;
int nxt[maxN][2];
int sz = 0;
void add(string& s) {
    int root = 0;
    for (int i = 0; i < s.size(); i++) {
        if (nxt[root][s[i] - '0'] == -1) {
            nxt[root][s[i] - '0'] = ++sz;
        }
        root = nxt[root][s[i] - '0'];
    }
}
ll xr = 0;
void upd(ll x) {
    ll p = 1;
    while (x % 2 == 0) {
        p *= 2;
        x /= 2;
    }
    xr ^= p;
}
void dfs(int v, int p) {
    if (nxt[v][0] == -1 && nxt[v][1] == -1) {
        return;
    }
    if (nxt[v][0] != -1 && nxt[v][1] != -1) {
        dfs(nxt[v][0], p + 1);
        dfs(nxt[v][1], p + 1);
    }
    else if (nxt[v][0] == -1) {
        dfs(nxt[v][1], p + 1);
        upd(L - p);
    }
    else {
        dfs(nxt[v][0], p + 1);
        upd(L - p);
    }
}
int f[105];
void gogo() {
    f[0] = 1;
    for (int i = 1; i <= 50; i++) {
        set < int > c;
        c.insert(0);
        int p = 0;
        for (int j = i - 1; j >= 0; j--) {
            p ^= f[j];
            c.insert(p);
        }
        while (c.count(f[i])) f[i]++;
        cout << i << " " << f[i] << endl;
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    gogo();
//    exit(0);
//    freopen("input.txt", "r", stdin);
    memset(nxt, -1, sizeof nxt);
    cin >> n >> L;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        add(s);
    }
    dfs(0, 0);
    cout << (xr == 0 ? "Bob" : "Alice");
    return 0;
}


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

int gcd(long long int a,long long int b){
  return __gcd(a,b);
}
int lcm(long long int a,long long int b){
  return a*b/gcd(a,b);
}

int main(void){
  long long int a,b;
  while(cin>>a>>b){
    long long int ma = max(a,b);
    long long int mi = min(a,b);
    cout<<gcd(ma,mi)<<" "<<lcm(ma,mi)<<endl;
  }
}

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

using namespace std;

int n,a[200010],num[200010];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	    scanf("%d",&a[i]);
	for(int i=n;i>=1;i--)
	{
		int num1=0;
		for(int j=2*i;j<=n;j=j+i)
			num1=num1+num[j];
		if(num1%2==a[i])
		    num[i]=0;
		else
		    num[i]=1;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	    if(num[i]==1)
	        ans++;
	printf("%d\n",ans);
	for(int i=1;i<=n;i++)
	    if(num[i]==1)
	        printf("%d ",i);
	printf("\n");
	return 0;
} 

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

int main() {
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			printf("%dx%d=%d\n", i, j, i*j);
		}
	}
	return 0;
}

Measured memory_bytes: 3164
import java.io.*;
import java.util.*;
public class Main {
    private static void solver(InputReader sc, PrintWriter out) throws Exception {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c=  sc.nextInt();
        int d = sc.nextInt();
        int k = sc.nextInt();
        a  = (a * 60) + b;
        c = (c*60) + d;
        int ans = (c- a -k);
        ans = Math.max(0,ans);
        out.println(ans);
    }
    private static long gcd(long a, long b){
        if(b==0) return a;
        return  gcd(b, a%b);
    }
    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}
class Pair implements Comparable<Pair>{
   long x,y;
   Pair(long x, long y){
       this.x = x;
       this.y = y;
   }
   public int compareTo(Pair p){
       return (int)(this.x - p.x);
   }

}

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

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

  priority_queue<int64_t> A;
  for(int i=0; i<N; i++){
    int64_t in; cin >> in;
    A.push(in);
  }

  if(N == 1){
    cout << (A.top() >> M) << endl; 
    return 0;
  }

  while (M > 0){
    int x = A.top()/2;
    A.pop();
    A.push(x);

    M--;
  }

  int64_t ans = 0;
  while (!A.empty()){
    ans += A.top();
    A.pop();
  }

  cout << ans << endl;

}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int start = max(a, c);
  int end = min(b, d);
  cout << max(0, end - start) << "\n";

  return(0);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int gcd(int a, int b) {
    if (a%b == 0) {
        return b;
    } else {
        return gcd(b, a%b);
    }
}
int main() {
    int n, x;
    cin >> n >> x;
    int xi, g;
    cin >> xi;
    g = abs(x-xi);
    for (int i=1; i<n; i++) {
        int xi;
        cin >> xi;
        g = gcd(g, abs(x-xi));
    }
    cout << g << endl;
}

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

    B = []
    for i in range(N):
        B.append([A[i],i+1])

    sort_B = sorted(B)
    ans = []
    for i, j in sort_B:
        ans.append(j)

    print(*ans)
main()

Measured memory_bytes: 71724
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
#define MOD 1000000007
typedef long long Int;

string sstr, tstr;
vector<int> s, t;
Int a, b, c, d, q;
int main(){
  cin >> sstr;
  cin >> tstr;
  s.push_back(0);
  t.push_back(0);
  for(int i = 0;i < sstr.size();i++){
    if(sstr[i] == 'A')s.push_back(1);
    else s.push_back(2);
    s[i+1] += s[i];
    s[i+1] %= 3;

  }

  for(int i = 0;i < tstr.size();i++){
    if(tstr[i] == 'A')t.push_back(1);
    else t.push_back(2);
    t[i + 1] += t[i];
    t[i+1] %= 3;

  }
  
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> a >> b >> c >> d;
   
    if((s[b] - s[a-1] - t[d] + t[c-1])%3==0)cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;  
}

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;

//READ THE PROBLEM!
//ll or int?

//Template contributed by GitHub user bqi343


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

	string s;
	cin >> s;
	int num = 0;
	for (int i = 0; i < 3; i++) {
        if (s.at(i) == '1') num++;
	}

	cout << num << endl;

	return 0;
}



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

int main(){
  int H, W;
  cin >> H >> W;
  string x(W+2, '#');
  vector<vector<char>> v(H, vector<char>(W));

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> v.at(i).at(j);
    }
  }

  for(int i = 0; i < W+2; i++){
    cout << x[i];
  }
  cout << endl;
  for(int i = 0; i < H; i++){
    cout << '#';
    for(int j = 0; j < W; j++){
      cout << v.at(i).at(j);
    }
    cout << '#' << endl;
  }
  for(int i = 0; i < W+2; i++){
    cout << x[i];
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
const int N = 3e5 + 233;

char str[N];
int n, st[N], top;

int main(void) {
	scanf("%s", str + 1);
	n = strlen(str + 1);
	for (int i = 1; i <= n; i++) {
		int ch = str[i];
		if (ch == 'T') {
			if (st[top] == 'S') --top;
			else st[++top] = ch;
		} else {
			st[++top] = ch;
		}
	}
	cout << top << "\n";
}
				


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, t;
    cin >> n >> t;
    vector<pair<long double, pair<ll, ll>>> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i].second.first >> x[i].second.second;
        x[i].first = (long double)x[i].second.first / (x[i].second.second + 1);
    }
    sort(x.rbegin(), x.rend());
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; i++) {
        tie(a[i], b[i]) = x[i].second;
        a[i]++;
    }
    debug(a, b);
    vector<ll> dp(n + 1, t + 1);
    dp[0] = 0;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) {
            break;
        }
        for (int j = cnt; j >= 0; j--) {
            if (j == cnt) {
                if (dp[cnt + 1] > a[i] * (dp[cnt] + 1) + b[i]) {
                    dp[cnt + 1] = a[i] * (dp[cnt] + 1) + b[i];
                    cnt++;
                }
                continue;
            }
            if (dp[j + 1] > a[i] * (dp[j] + 1) + b[i]) {
                dp[j + 1] = a[i] * (dp[j] + 1) + b[i];
            }
        }
    }
    debug(dp);
    vector<ll> y;
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] != 1) break;
        y.emplace_back(b[i] + 1);
        if (i != n - 1) y[n - 1 - i] += y[n - 2 - i];
    }
    int ans = cnt;
    for (int j = 0; j < y.size(); j++) {
        ll s = y[j];
        if (s > t) break;
        int i = upper_bound(dp.begin(), dp.end(), t - s) - dp.begin();
        ans = max(ans, i + j);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13428
#include<bits/stdc++.h>
#define N 55
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
const double EPS = 1e-8;

double cross(P a, P b){ return imag(conj(a)*b); }

struct Circle{
  P c; //?????????
  double r; //??????
  Circle(P c=P(0,0), double r=0):c(c),r(r){}
};

P rotate(P p, double rad){
  double x = real(p) * cos(rad) - imag(p) * sin(rad);
  double y = real(p) * sin(rad) + imag(p) * cos(rad);
  return P(x,y);
}

vector<L> tangentCC(Circle c1, Circle c2){
  vector<L> res;
  double d = abs(c1.c - c2.c);
  if(d < EPS) return res;
  if(c1.r + c2.r < d - EPS){
    double t = acos((c1.r + c2.r) / d);
    res.push_back(L(c1.c + rotate(c1.r / d * (c2.c-c1.c), t), c2.c + rotate(c2.r / d * (c1.c-c2.c), t)));
    res.push_back(L(c1.c + rotate(c1.r / d * (c2.c-c1.c), -t), c2.c + rotate(c2.r / d * (c1.c-c2.c), -t)));
  }
  else if(c1.r + c2.r < d + EPS){
    P p = c1.c + c1.r / d * (c2.c-c1.c);
    res.push_back(L(p, p + rotate(c2.c-c1.c, M_PI/2.0)));
  }
  if(abs(c1.r-c2.r) < d - EPS){
    double t1 = acos((c1.r - c2.r) / d), t2 = M_PI - t1;
    res.push_back(L(c1.c + rotate(c1.r / d * (c2.c-c1.c), t1), c2.c + rotate(c2.r / d * (c1.c-c2.c), -t2)));
    res.push_back(L(c1.c + rotate(c1.r / d * (c2.c-c1.c), -t1), c2.c + rotate(c2.r / d * (c1.c-c2.c), t2)));
  }
  else if(abs(c1.r - c2.r) < d + EPS){
    P p = c1.c + c1.r / d * (c2.c-c1.c);
    res.push_back(L(p, p + rotate(c2.c-c1.c, M_PI/2)));
  }
  return res;
}

double getDistanceSP(L s, P p){
  return abs(cross(s.second - s.first, p - s.first) / abs(s.second - s.first));
}

Circle c[N][2];

int main(){
  int n,x,y,r,m;
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<n;i++){
      cin>>x>>y>>r>>m;
      c[i][0]=Circle(P(x,y),r);
      c[i][1]=Circle(P(x,y),r+m);
    }
    int ans=1;
    for(int i=0;i<n;i++)
      for(int j=0;j<2;j++)
	for(int k=i+1;k<n;k++)
	  for(int l=0;l<2;l++){
	    vector<L> r=tangentCC(c[i][j],c[k][l]);
	    for(int a=0;a<r.size();a++){
	      int sum=0;
	      for(int b=0;b<n;b++){
		double d=getDistanceSP(r[a],c[b][0].c);
		if(c[b][0].r-EPS<=d&&d<=c[b][1].r+EPS)sum++;
	      }
	      ans=max(ans,sum);
	    }
	  }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3348
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { std::cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { std::cin >> first; Scan(rest...); }
#define OUT(d) std::cout<<d;
#define FOUT(n, d) std::cout<<std::fixed<<std::setprecision(n)<<d;
#define SOUT(n, c, d) std::cout<<std::setw(n)<<std::setfill(c)<<d;
#define SP std::cout<<" ";
#define TAB std::cout<<"\t";
#define BR std::cout<<"\n";
#define FLUSH std::cout<<std::flush;
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define MAT(type, c, m, n) std::vector<std::vector<type>> c(m, std::vector<type>(n));for(auto& r:c)for(auto& i:r)std::cin>>i;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
#define PAIR std::pair<int, int>
#define IN(a, x, b) (a<=x && x<b)
#define SHOW(d) {std::cerr << #d << "\t:" << d << "\n";}
#define SHOWVECTOR(v) {std::cout << #v << "\t:";for(const auto& i : v){std::cout << i << " ";}std::cout << "\n";}
#define SHOWVECTOR2(v) {std::cout << #v << "\t:\n";for(const auto& i : v){for(const auto& j : i){std::cout << j << " ";}std::cout << "\n";}}
#define SHOWPAIRVECTOR2(v) {std::cout << #v << "\t:\n";for(const auto& i : v){for(const auto& j : i){std::cout<<'('<<j.first<<", "<<j.second<<") ";}std::cout << "\n";}}
#define SHOWPAIRVECTOR(v) {for(const auto& i:v){std::cout<<'('<<i.first<<", "<<i.second<<") ";}std::cout<<"\n";}
#define CHECKTIME(state) {auto start=std::chrono::system_clock::now();state();auto end=std::chrono::system_clock::now();auto res=std::chrono::duration_cast<std::chrono::nanoseconds>(end-start).count();std::cerr<<"[Time:"<<res<<"ns  ("<<res/(1.0e9)<<"s)]\n";}
#define SHOWQUEUE(a) {std::queue<decltype(a.front())> tmp(a);std::cout << #a << "\t:";for(int i=0; i<static_cast<int>(a.size()); ++i){std::cout << tmp.front() << "\n";tmp.pop();}std::cout << "\n";}

//#define int ll
using ll = long long;
using ull = unsigned long long;
constexpr int INFINT = 1 << 30;
constexpr ll INFLL = 1LL << 60;
constexpr double EPS = 0.0000000001;
constexpr int MOD = 1000000007;

signed main() {
	INIT;
	VAR(std::string, w);
	std::vector<int> cnt(26, 0);
	REP(i, w.size()) {
		++cnt[w[i] - 'a'];
	}
	bool ok = true;
	REP(i, 26) {
		if (cnt[i] % 2 == 1) {
			ok = false;
		}
	}
	OUT(((ok) ? "Yes" : "No"))BR;
	return 0;
}


Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
map<string,int>m;
int n,top;
string s[200005];
char ch[105];
int main(){
	in(n);
    for(int i=1;i<=n;i++){
        scanf("%s",ch);
        string ss=ch;
        if(!m[ss]){
            s[++top]=ss;
            m[ss]=1;
        }
        else m[ss]++;
    }
    sort(s+1,s+1+top);
    int ans=0;
    for(int i=1;i<=top;i++)ans=max(ans,m[s[i]]);
    for(int i=1;i<=top;i++){
        if(m[s[i]]==ans){
            int len=s[i].size();
            for(int j=0;j<len;j++){
                char cc=s[i][j];
                printf("%c",cc);
            }
            puts("");
        }
    }
	return 0;
}


Measured memory_bytes: 34944
w=sorted(list(input()))
n=len(w)

if n%2!= 0:
    print('No')
else:
    x,y=[],[]
    for i in range(int(n/2-1)):
        x.append(w[2*i])
        y.append(w[2*i+1])
    print('Yes') if x==y else print('No')

Measured memory_bytes: 3060
#include<stdio.h>
#define N 2000


int solve(int ,int);

int i,A[N],m[N],q,n;

int main()
{
  
  scanf("%d",&n);

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

  scanf("%d",&q);

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

  for(i=0;i<q;i++)
    {
      //makeConvination();
      if(solve(0,m[i]) == 1)printf("yes\n");
      else printf("no\n");
    }
  return 0;
}



int solve(int i,int m)
{
  int res;
  if(m == 0) return 1;
  else if(i>= n)return 0;

  res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
    
}



Measured memory_bytes: 2108
#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);
  }
  for (;;) {
    sort(a.begin(), a.end());
    if (a.size() == 1) break;
    for (int i = 1; i < a.size(); i++) {
      if (a.at(i) % a.at(0) == 0) {
        a.erase(a.begin() + i);
      } else {
        a.at(i) = a.at(i) % a.at(0);
      }
    }
  }
  cout << a.at(0);
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int count(int counter, int in) {
	if (in == 0) return counter;
	counter += in % 10;
	in /= 10;
	int c = count(counter, in);
}
int main() {
	int a;
	cin >> a;
	int counter = count(0, a);
	cout << counter << endl;
}

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

int main() {
  int n, q;
  cin >> n;
  vector<int> cnt(1e6, 0);
  ll ans = 0;
  rep(i, n) {
    int a;
    cin >> a;
    cnt.at(a)++;
    ans += a;
  }

  cin >> q;
  rep(i, q) {
    int b, c;
    cin >> b >> c;
    ans += (c - b) * cnt.at(b);
    cout << ans << endl;
    cnt.at(c) += cnt.at(b);
    cnt.at(b) = 0;
  }

  return 0;
}

Measured memory_bytes: 7168
using System;
using System.Linq;

namespace AtCoder {
    class Program {
        static string s;
        static int[] pow;
        static int[] memo;

        static int Pow(int n) {
            if(pow[n] > 0) return pow[n];
            if(n == 1) return pow[n] = 1;
            return pow[n] = Pow(n - 1) * 10 % 2019;
        }

        static int Get(int n) {
            if(memo[n] >= 0) return memo[n];
            if(n == 0) return memo[n] = 0;
            if(n == 1) return memo[n] = s[^1] - '0';
            return memo[n] = (Get(n - 1) + (s[^n] - '0') * Pow(n)) % 2019;
        }

        static void Main() {
            s = Console.ReadLine();
            pow = new int[s.Length + 1];
            memo = new int[s.Length + 1];
            Array.Fill(memo, -1);
            var count = new int[2019];
            for(int i = 0; i <= s.Length; i++)
                count[Get(i)]++;
            Console.WriteLine(count.Where(x => x > 0).Sum(x => x * (x - 1) / 2));
        }
    }
}

Measured memory_bytes: 29056
using System;

class p
{

    //i,i+1文字目からi-1文字目を決めて返す
    static char backChar(string s,char[] temp,int i)
    {
        if (temp[i] == 'S')//i文字目が羊
        {
            if (s[i] == 'o')//羊かつ〇なら両側が同じ
                return temp[i + 1];
            else //羊かつ×なら両側が異なる
            {
                if (temp[i + 1] == 'S') return 'W';
                else return 'S';
            }
        }
        else //i文字目が狼
        {
            if (s[i] == 'x')//狼かつ×なら両側が同じ
                return temp[i + 1];
            else //狼かつ〇なら両側が異なる
            {
                if (temp[i + 1] == 'S') return 'W';
                else return 'S';
            }
        }
    }

    //i-1,i文字目からi+1文字目を決めて返す
    static char nextChar(string s,char[] temp,int i)
    {
        if (temp[i] == 'S')//i文字目が羊
        {
            if (s[i] == 'o')//羊かつ〇なら両側が同じ
                return temp[i - 1];
            else //羊かつ×なら両側が異なる
            {
                if (temp[i - 1] == 'S') return 'W';
                else return 'S';
            }
        }
        else //i文字目が狼
        {
            if (s[i] == 'x')//狼かつ×なら両側が同じ
                return temp[i - 1];
            else //狼かつ〇なら両側が異なる
            {
                if (temp[i - 1] == 'S') return 'W';
                else return 'S';
            }
        }
    }

    static void Main(string[] a)
    {
        int N = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        //s は o と x のみからなる長さ N の文字列
        char[] t = new char[N];
        //t は長さ N で S と W のみからなる文字列;解がない場合の-1を代入
        char[] temp = new char[N];
        //１，２文字目を仮定してシミュレーションするための文字列temp
        char lastNext;
        char firstBack;
        bool flag = false;

        string[] strarray = { "SS", "SW", "WS", "WW" };

        foreach (string str in strarray)
        {
            if (flag != false) break;
            temp[0] = str[0];
            temp[1] = str[1];
            for (int i = 1; i < N - 1; i++)
            {
                temp[i + 1] = nextChar(s, temp, i);
            }
            lastNext = nextChar(s, temp, N - 1);
            firstBack = backChar(s, temp, 0);
            if (lastNext == temp[0] && firstBack == temp[N - 1])
            {
                flag = true;
                for (int i = 0; i < N; i++)
                    t[i] = temp[i];
            }
        }

        if (flag)
        {
            for (int i = 0; i < N; i++) Console.Write(t[i]);
        }
        else Console.Write("-1");
        Console.WriteLine();

    }
}

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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int a,b;

signed main() {
    cin >> a >> b;
    rep1(i,3) {
        if (a != i && b != i) cout << i << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX_N 101
#define START_V 1
#define WILD -1

struct vertex
{
	int N[MAX_N];
	int len_N;
	int d;
} typedef vertex;

vertex V[MAX_N];

void bfs(int);
void reSetDistance(int, int);

int main()
{
	int i, j;
	int n, u;
	
	scanf("%d", &n);
	for(i = 1; i <= n; i++)
	{
		scanf("%d %d", &u, &V[i].len_N);
		for(j = 1; j <= V[i].len_N; j++)
		{
			scanf("%d", &V[i].N[j]);
		}
	}
	
	bfs(n);
	
	for(i = 1; i <= n; i++)
	{
		printf("%d %d\n", i, V[i].d);
	}
	
	return 0;
}

void bfs(int n)
{
	int i;
	
	for(i = 1; i <= n; i ++)
	{
		V[i].d = WILD;
	}
	
	reSetDistance(START_V, 0);
}

void reSetDistance(int t, int d)
{
	int i;
	int next;
	
	V[t].d = d;
	
	for(i = 1; i <= V[t].len_N; i++)
	{
		next = V[t].N[i];
		
		if(V[next].d == WILD || V[next].d > d + 1)
		reSetDistance(next, d + 1);
	}
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int N = 2e5 + 1;
int n , m , avail[N];
vector <int> adj[N];
queue <int> Q;
int bfs(int x){
    int temp = 1;
    Q.push(x);
    avail[x] = true;
    while (!Q.empty()){
        int u = Q.front(); Q.pop();
        for (auto v : adj[u])
            if (!avail[v]){
                temp++;
                avail[v] = true;
                Q.push(v);
            }
    }
    return temp;
}
int main(){
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        int u , v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int ans = 1;
    for (int i = 1; i <= n; i++) ans = max(ans ,bfs(i));
    cout << ans;
}

Measured memory_bytes: 15420
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m;
pair<int,int> p[N];
struct node{
	int v, ne, id;
}edge[N << 1];
int head[N], tot;
void add(int x, int y, int id)
{
	edge[++tot].v = y;
	edge[tot].id = id;
	edge[tot].ne = head[x];
	head[x] = tot;
}
int sta[N], vis[N];
int siz[N], cnt[N];
int tot1, tot2;
void dfs(int son, int fa, int id)
{
	siz[son] = sta[son];
	vis[son] = 1;
	tot2 += sta[son];
	for (int i = head[son]; i; i = edge[i].ne)
	{
		if (edge[i].v == fa) continue;
		if (vis[edge[i].v]) continue;
		dfs(edge[i].v, son, edge[i].id);
		siz[son] += siz[edge[i].v];
	}
	cnt[id] = siz[son] % 2;
}
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
	scanf("%d%d", &p[i].first, &p[i].second);
	sort(p + 1, p + n + 1);
	int pre = 0;
	for (int i = 1; i <= n; i++)
	{
		if (pre != p[i].second) sta[i] = 1;
		else sta[i] = 0;
		pre ^= sta[i];
		if (sta[i]) tot1++;
	}
	sta[n + 1] = pre;
//	for (int i = 1; i <= n + 1; i++)
//	cout << sta[i] << " ";
//	cout <<endl;
	if (sta[n + 1]) tot1++;
	if (tot1 == 0)
	{
		printf("0\n\n");
		return 0;
	}
	int st = -1;
	for (int i = 1; i <= m; i++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		int x = lower_bound(p + 1, p + n + 1, make_pair(l, 0)) - p;
		int y = upper_bound(p + 1, p + n + 1, make_pair(r, 1)) - p - 1;
		if (x > y) continue;
		if (st == -1) st = x;
		add(x, y + 1, i);
		add(y + 1, x, i);
//		cout << x<<" "<< y + 1 <<i << endl;
	}
	for (int i = 1; i <= n + 1; i++)
	{
		tot2 = 0;
		if (!vis[i]) dfs(i, 0, 0);
//		cout << i << tot2<<endl;
		if (tot2 % 2) 
		{
			printf("-1\n");
			return 0;
		}
	}
	vector<int> ans;
	for (int i = 1; i <= m; i++)
		if (cnt[i]) ans.push_back(i);
	printf("%d\n", ans.size());
	for (int i = 0; i < ans.size(); i++)
	{
		if (i > 0) printf(" ");
		printf("%d", ans[i]);
	}
	printf("\n");
}

Measured memory_bytes: 13564
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int n,m,q;
vector<int> a,b,c,d;
int score(vector<int> &A){
    int res = 0;
    for(int i=0;i<q;i++){
        if(A[b[i]] - A[a[i]] == c[i]) res += d[i];
    }
    return res;
}
int dfs(vector<int> &A){
    if(A.size() == n){
        return score(A);
    }
    int res = 0;
    int p = 0;
    if(!A.empty()) p = A.back();
    for(int v=p;v<m;v++){
        A.push_back(v);
        res = max(res,dfs(A));
        A.pop_back();
    }
    return res;
}
int main(){
    cin >> n >> m >> q;
    a.resize(q); b.resize(q); c.resize(q); d.resize(q);
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i]; --b[i];
    }
    vector<int> A;
    cout << dfs(A) << endl;
}

Measured memory_bytes: 3632