akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, data):
        """
        サイズベースのunion_find
        与えられたdataまでの長さの配列を作成
        配列は1から開始する
        それがunionfindの親となり初めは自分自身
        またsizeも定義し初期値は1
        ・union findのグループのサイズの求め方
        1.あるxのグループの親を取得
        union_find = UnionFind(N)
        par_x = union_find.find(x)
        2.その親のsizeがそのグループのサイズになっている
        size = union_find.size[par_x]
        """
        self.parent = {}
        self.size = {}
        for i in range(1, data+1):
            self.parent[i] = i
            self.size[i] = 1


    def find(self, x):
        """
        与えられた値に対してその親ノードを返却
        """
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x]) # self.parentに入れ直しているのは次findするとき高速になるよう再起により親を直接結んでいる
            return self.parent[x]


    def same(self, x, y):
        """
        与えられた2つの値が同一グループ(親)かチェック
        """
        return self.find(x) == self.find(y)


    def unite(self, x, y):
        """
        与えられた2つの値を同一のグループ(親)にする
        """
        x = self.find(x)
        y = self.find(y)
        if x == y: # すでに同じグループなら何もしない
            return
        if self.size[x] > self.size[y]: # ランクが異なる場合小さい方の親を大きい方にする
            self.parent[y] = x
            self.size[x] += self.size[y]
            return
        elif self.size[x] < self.size[y]:
            self.parent[x] = y
            self.size[y] += self.size[x]
            return
        else: # ランクが同じ場合どちらかの親にする その際親にした方の値のランクをあげる
            self.parent[x] = y
            if self.size[x] == self.size[y]: self.size[y] += self.size[x]
            return

if __name__ == '__main__':
    N,M,K = map(int, input().split())
    union_find = UnionFind(N)

    kankei = [[] for i in range(N+1)]
    for i in range(M):
        A,B = map(int, input().split())
        union_find.unite(A,B)
        kankei[A].append(B)
        kankei[B].append(A)

    for i in range(K):
        C,D = map(int, input().split())
        if union_find.same(C,D):
            kankei[C].append(D)
            kankei[D].append(C)

    ans = ""
    for i in range(1,N+1):
        ans += str(union_find.size[union_find.find(i)]-len(kankei[i])-1) + " "

    print(ans.rstrip())

Measured memory_bytes: 47332
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

Weight chinese_postman(const Graph &g) {
    size_t V=g.size();
    vector<vector<Weight>> h(V, vector<Weight>(V, INF));
    vector<size_t> deg(V);

    Weight total=0;
    for (size_t i=0; i<V; ++i)
        for (const Edge &e: g[i]) {
            if (e.src > e.dst) continue;

            if (h[e.src][e.dst] > e.weight)
                h[e.src][e.dst] = h[e.dst][e.src] = e.weight;

            ++deg[e.src], ++deg[e.dst];
            total += e.weight;
        }

    vector<size_t> oddnode;
    for (size_t i=0; i<V; ++i)
        if (deg[i] & 1)
            oddnode.push_back(i);

    for (size_t k=0; k<V; ++k)
        for (size_t i=0; i<V; ++i)
            for (size_t j=0; j<V; ++j)
                if (h[i][j] > h[i][k] + h[k][j])
                    h[i][j] = h[i][k] + h[k][j];

    size_t n=oddnode.size();
    vector<Weight> dp(1<<n, INF); dp[0]=0;

    for (size_t s=0; s<(1u<<n); ++s)
        for (size_t i=0; i<n; ++i) {
            if (1<<i & s) continue;

            for (size_t j=i+1; j<n; ++j) {
                if (1<<j & s) continue;

                size_t u=oddnode[i], v=oddnode[j];
                dp[1<<i|1<<j|s] = min(dp[1<<i|1<<j|s], dp[s]+h[u][v]);
            }
        }

    return total + dp[(1<<n)-1];
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t;
        Weight d;
        scanf("%zu %zu %lld", &s, &t, &d);

        join(g, s, t, d);
    }

    printf("%lld\n", chinese_postman(g));
    return 0;
}

Measured memory_bytes: 2796
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char *argv[])
{
  int n, k = -1, i, j;
  int *A, *B, *C;

  scanf("%d", &n);
  A = (int *)malloc(sizeof(int) * n);
  B = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
    k = (int)fmax(k, A[i]);
    B[i] = 0;
  }
  C = (int *)malloc(sizeof(int) * (k + 1));

  for (i = 0; i <= k; i++) C[i] = 0;
  for (i = 0; i < n; i++) C[A[i]]++;
  //for (i = 1; i <= k; i++) C[i] += C[i-1];
  j = 0;
  while (C[j] == 0) j++;
  for (i = 0; i < n; i++) {
    B[i] = j;
    C[j]--;
    while (C[j] == 0) j++;
  }

  for (i = 0; i < n; i++) {
    if (i != n - 1) printf("%d ", B[i]);
    else printf("%d\n", B[i]);
  }

  return 0;
}

Measured memory_bytes: 16272
s = input()

a = 200000
z = 0
for i in range(len(s)):
    if s[i] == 'A' and a > i:
        a = i
    if s[i] == 'Z' and z < i:
        z = i

# print(s[a:z + 1]) # slice (don't include s[z + 1])
print(z - a + 1)


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

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

using namespace std;


int main(){
    int n, k, q;
    cin >> n >> k >> q;
    vector<long> point(n, k-q);
    rep(i, q){
        int ans;
        cin >> ans;
        point[ans-1]++;
    }

    rep(i, n){
        if (point[i] > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
ll combb[400000];
ll factt[400000];
const ll MOD = 998244353LL;

class ModuloCombination {
private:
  vector<ll> fact, fact_inv;

  static ll mod_pow(ll a, ll n){
    if(n == 0) return 1;
    if(n%2 == 0) return mod_pow((a * a) % MOD, n / 2);
    return (a * mod_pow(a, n - 1)) % MOD;
  }

public:
  ModuloCombination(ll N): fact(N + 1), fact_inv(N + 1) {
    fact[0]=1;
    for(ll i = 1; i < N + 1; i++) {
      fact[i] = (i * fact[i - 1]) % MOD;
    }
    for(ll i = 0; i < N + 1; i++) {
      fact_inv[i] = mod_pow(fact[i], MOD - 2);
    }
  }

  ll operator()(ll n, ll r) {
    return (((fact[n] * fact_inv[r]) % MOD) * fact_inv[n - r]) % MOD;
  }
};

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  ll n,a,b,k;cin>>n>>a>>b>>k;
  ll cnt=0;
  ModuloCombination C(n);
  for(int i=0;i<=n;i++){
    if((k-a*i)%b!=0)continue;
    ll j=(k-a*i)/b;
    if(j<0)continue;
    if(j>n)continue;
    cnt+=(C(n,i)*C(n,j))%MOD;
    cnt%=MOD;
  }

  P(cnt);

  return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>



using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
/*
 execution in cmd of windows: g++ p1.cpp -op1
  
  
  p1
 
 */
typedef double dd;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl <<"\n"
#define con continue
#define br break
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
ll mx=INT_MAX;
ll mi=INT_MIN;
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define all(v) v.begin(), v.end()
#define fsort(v) sort(all(v))  
#define rsort(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(all(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define sumv(v,x) accumulate(v.begin(),v.end(),x);
const ll mod = 1000000007;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const ll MOD=1e9+7;
#define io { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define cer cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#define cs ll t;cin>>t;while(t--)
#define cs1 ll t;t=1;while(t--)

int main()
{
   #ifndef ONLINE_JUDGE
        ifstream cin("in.in");
        ofstream cout("out.out");
    #endif
    
        io;
        //////////////////////////////////
         cs1{
             ll i,j,s=0,c,k,q=0,n,m=0,e;
             ll b,a,d;
             cin>>a>>b>>c>>d;
             q=-INF;
             q=max(q,a*c);
             q=max(q,a*d);
             q=max(q,b*c);
             q=max(q,b*d);
             cout<<q nl;
        }
        //////////////////////////////////
        cer;
}


Measured memory_bytes: 3800
n=int(input())
a=list(map(int,input().split()))
ans=float('inf')
for i in range(n):
    tmp=0
    while(1):
        if a[i]%2==0:
            tmp+=1
            a[i]//=2
        else:
            break
    ans=min(ans,tmp)
print(ans)

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

namespace ConsoleApplication14
{
    class Program
    {
        static void Main()
        {
            while (true)
            {
                string a = Console.ReadLine();
                if (a == "-") break;
                int s = 0;
                int c = int.Parse(Console.ReadLine());
                for(int d = 0; d < c; d++)
                {
                    int y = int.Parse(Console.ReadLine());
                    s += y;
                }
                int u = a.Length;
                int r = s % u;
                for(int t = 0; t < u - r; t++)
                {
                    Console.Write(a[r+t]);
                }
                for(int q = 0; q < r; q++)
                {
                    Console.Write(a[q]);
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9008
#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;
  string S;
  cin >> N >> Q >> S;
  int a[N];
  a[0] = 0;
  rep(i, N - 1){
    a[i + 1] = a[i];
    if(S[i] == 'A' && S[i + 1] == 'C'){
      a[i + 1] += 1;
    }
  }
  rep(i, Q){
    int l, r;
    cin >> l >> r;
    cout << (a[r - 1] - a[l - 1]) << endl;
  }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout <<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;

  VAR(int, H, W);
  vector< string > s(H);
  REP(hi, H) {
    cin >> s[hi];
    if (s[hi] == string(W, '.')) {
      hi--;
      H--;
    }
    // debug(s[hi]);
  }

  REP(wi, W) {
    bool ng = true;
    REP(hi, H) {
      ng &= (s[hi][wi] == '.');
    }
    if (!ng) continue;
    REP(hi, H)
      FOR(wj, wi, W) 
      s[hi][wj] = s[hi][wj + 1];
    wi--;
    W--;
  }

 
  REP(hi, H) {
    REP(wi, W) {
      OUT(s[hi][wi]);
    }
    BR;
  } 
  return 0;
}


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

using namespace std;

int C(int a,int b){
    if(a<b) return 0;
    
    int ret=1;
    for(int i=0;i<b;i++){
        ret*=a-i;
    }
    
    for(int i=0;i<b;i++){
        ret/=i+1;
    }
    
    //printf("C(%d,%d)=%d\n",a,b,ret);
    
    return ret;
}

int main(){
    int N,M;
    cin>>N>>M;
    
    cout<<C(N,2)+C(M,2)<<endl;
    
    return 0;
}



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

using namespace std;

void solveA()
{
    int a, b;
    cin >> a >> b;
    int coins = 0, t = 2;
    while(t--){
        if (a >= b){
            coins += a;
            a--;
        }
        else{
            coins += b;
            b--;
        }
    }

    cout << coins << endl;
}

void solveB()
{
    int p, q, r;
    int ans = 0;
    cin >> p >> q >> r;
    int menor = min(p, q);
    menor = min(menor, r);
    ans = menor;
    if (menor == p){
        ans += min(q, r);
    }
    else
    if (menor == q){
        ans += min(r, p);
    }
    else{
        ans += min(p, q);
    }

    cout << ans << endl;
}

void solveC()
{
    int a[5], k;
    for (int i = 0; i < 5; i++){
        cin >> a[i];
    }
    cin >> k;
    int maior = a[0], menor = a[0];
    for(int i = 1; i < 5; i++){
        maior = max(maior, a[i]);
        menor = min(menor, a[i]);
    }
    int dist = maior - menor;
    if (dist > k)
        cout << ":(\n";
    else
        cout << "Yay!\n";

}

int main(int qtd, char* nome[])
{
    solveC();

    return 0;
}

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

using namespace std;

int main() {
    string m;
    int i, c = 0;

    cin >> m;
    for(i = 0; i < m.length(); i++) {
        if(m[i] == '1') {
            c++;
        }
    }

    cout << c << endl;

    return 0;
}

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

int main() {
  ll n,m; cin >> n >> m;
  if(n == 1){
    n += 13;
  }
  if(m == 1){
    m += 13;
  }
  if(n>m){
    cout << "Alice";
  }
  else if(n<m){
    cout << "Bob";
  }
  else{
    cout << "Draw";
  }
}

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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

// policy-based
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;	


using namespace std;


typedef int ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
 
const ll MAX = 2e6+10;
const ll inf = 1e9;


int main(){
	fastio;
	ll a = 0;
	string s,t;
	cin>>s>>t;
	f(i,0,s.size()) if(s[i]!=t[i]) a++;
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 3800
from math import log2
import decimal

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

decimal.getcontext().prec = 28

ans = decimal.Decimal(0)

for i in range(1, N+1):
    if i < K:
        power = -(-(log2(K) - log2(i))//1)
        prob = decimal.Decimal(1/((2**power) * N))
    else:
        prob = decimal.Decimal(1/N)

    #print(prob)
    ans = decimal.Decimal(ans + prob)
    #print(ans)

print(ans)

Measured memory_bytes: 10268
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	int sum[3] = {};
	for (int i = 0; i < n; i++){
		int x; scanf("%d", &x);
		if (x <= a) sum[0]++;
		else if (x <= b) sum[1]++;
		else sum[2]++;
	}
	printf("%d\n", min(sum[0], min(sum[1], sum[2])));
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
        string s;
        const string ref = "CODEFESTIVAL2016";
        cin >> s;
        int c = 0;
        for(int i=0; i<ref.size() && s!=ref; ++i){
                if(ref[i] != s[i]){
                        s[i] = ref[i];
                        ++c;
                }
        }
        cout << c << endl;
        return 0;
}

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

namespace ABC140B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            int[] A = ReadInt().Select(x => x - 1).ToArray();
            int[] B = ReadInt();
            int[] C = ReadInt();

            int sum = 0;
            for (int i = 0; i < N; i++)
            {
                sum += B[A[i]];

                if (i != 0 && A[i] - A[i - 1] == 1) sum += C[A[i - 1]];
            }

            Console.WriteLine(sum);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl "\n"


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

    unordered_map<string, int> mp;
    int n; cin >> n;
    for_(i, 0, n) {
        string temp; cin >> temp;
        mp[temp] += 1;
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

    return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(char a, char b) {
	return a > b;
}

int main() {
	char a[110], b[110];
	cin >> a >> b;
	sort(a, a + strlen(a));
	sort(b, b + strlen(b), check);
	string x = a, y = b;
	Yes(x < y);
	return 0;
}

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

int main(){
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for(int i = 0; i < n; i++)  cin >> a[i];
    vector<int> b = a;
    sort(b.begin(), b.end());
    multiset<int> pos;
    while(q-- > 0){
        string s;
        int x;
        cin >> s >> x;
        if(s[0] == 'A'){
            pos.insert(upper_bound(b.begin(),b.end(),a[--x])-b.begin()-1);
        }else if(s[0] == 'R'){
            pos.erase(pos.find(upper_bound(b.begin(),b.end(),a[--x])-b.begin()-1));
        }else if(s[0] == 'C'){
            int ng = pos.size()==0 ? n : n-1-*(pos.rbegin());
            if(ng > x){
                cout << "NA" << endl;
                continue;
            }
            int l = -1, r = 1000000000;
            while(r-l > 1){
                int mid = (l+r)/2, tmpng = ng, bef = 0;
                for(auto it = pos.begin(); it != pos.end(); it++){
                    tmpng += max(0, (int)(lower_bound(b.begin(),b.end(),b[*it]-mid)-b.begin())-bef);
                    bef = *it+1;
                }
                if(tmpng <= x)  r = mid;
                else            l = mid;
            }
            cout << r << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 10720
/*
 * Binary Search.c
 *
 *  Created on: 2015/02/15
 */
 
#include <stdio.h>
 
int S[100000]={0},T[50000]={0};
 
 
//void printarray(int a[],int n){
//  int i;
//  for(i=0;i<n;i++){
//      printf("%d ",a[i]);
//  }printf("\n");
//}
 
int main(){
    int n,q;
    int i,j,counter=0;
    int start,end;
 
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&S[i]);
    }
 
    scanf("%d",&q);
    for(j=0;j<q;j++){
        scanf("%d",&T[j]);
    }
 
 
    for(i=0;i<q;i++){
 
        start=0,end=n;
 
        while(start < end){
            int middle = (start + end) / 2;
 
            if(S[middle] > T[i]){
                end = middle;
            }
            else if(S[middle] < T[i]){
                start = middle + 1;
            }
            else if(S[middle] == T[i]){
                counter++;
                break;
            }
        }
    }
 
    printf("%d\n",counter);
 
    return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll X; cin >> X;
    ll now = 100, years = 0;
    while(1){
      now = (ll)((double)now * 1.01);
      years++;
      if(now >= X) break;
    }
    cout << years;

  	return 0;
}

Measured memory_bytes: 3652
#include "stdio.h"
int main(){
    int L, A, B, C,D,E,F,G,max = 0;
    scanf("%d",&L);
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&D);
    
    if(A % C != 0){
        F = A/C + 1;
//        printf("F = %d\n",F);
    }else{ F = A/C;
//        printf("F = %d\n",F);
    }
    if(B % D != 0){
        G = B/D + 1;
//        printf("G = %d\n",G);
    }else{ G = B/D;
//        printf("G = %d\n",G);
    }
    
    if(F >= G){
    max = L - F;
    }else if(F < G){
    max = L - G;
    }
    printf("%d\n",max);
    return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		long[] A = new long[N+1];
		for (int i = 0; i < N+1; i++) {
			A[i] = sc.nextLong();
		}
		
		long[] B = new long[N];
		for (int i = 0; i < N; i++) {
			B[i] = sc.nextLong();
		}
		
		long ans = 0;
		for (int i = 0; i < B.length; i++) {
			long t = B[i];
			
			long i1 = A[i];
			long i2 = A[i+1];
			
			if (t >= i1) {
				t -= i1;
				ans += i1;
			} else {
				ans += t;
				continue;
			}
			
			if (t >= i2) {
				t -= i2;
				ans += i2;
				A[i+1] = 0;
			} else {
				ans += t;
				A[i+1] -= t;
			}
			
		}
		
		System.out.println(ans);
		
	}
	
}



Measured memory_bytes: 87784
m = ""
while True:
    S = input()
    if S == "-":
        break

    S = list(S)
    L = S
    n = int(input())
    for i in range(n):
        m = int(input())
        for j in range(m):
            t = L.pop(0)
            L.append(t)

    L = "".join(L)
    print(L)

Measured memory_bytes: 7740
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

const int N=1e5+5;

int t,n,a[N],mem[N];

int dp(int pos)
{
    if (pos==n-1)return 0;
    if (mem[pos]!=-1)return mem[pos];
    int ans=1e9+5;
    ans=min(ans,abs(a[pos]-a[pos+1])+dp(pos+1));
    if (pos+2<n)
    ans=min(ans,abs(a[pos]-a[pos+2])+dp(pos+2));
    return mem[pos]=ans;
}

int main()
{
    t=1;
    while(t--)
    {
        memset(mem,-1,sizeof mem);
        cin >> n;
        for (int i=0;i<n;i++)
        {
            cin >> a[i];
        }
        cout << dp(0) << endl;
    }
}


Measured memory_bytes: 4096
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n, k;
	cin >> n >> k;
	vector<ll> p(n), c(n);
	rep(i, n) cin >> p[i], p[i]--;
	rep(i, n) cin >> c[i];
	ll ans = -1e18;
	rep(i, n){
		ll cur = i;
		ll tot = 0LL, mx = -1e18;
		vi vis(n, 0);
		ll nw = 0LL;
		rep(j, min(k, n)){
			if(vis[cur]) break;
			nw++;
			vis[cur] = 1;
			tot += c[p[cur]];
			mx = max(mx, tot);
			cur = p[cur];
		}
		if(tot <= 0){
			ans = max(ans, mx);
			continue;
		}
		ans = max(ans, mx);
		if(k <= nw) continue;
		ll nm = k / nw;
		ll rem = k % nw;
		ans = max(ans, (nm - 1) * tot + mx);
		ll tot1 = 0LL, mx1 = -1e18;
		cur = i;
		rep(j, rem + 1){
			mx1 = max(mx1, tot1);
			tot1 += c[p[cur]];
			cur = p[cur];
		}
		ans = max(ans, nm * tot + mx1);
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

#define N 100001

void swap(int A[], int i, int j) {
    int temp = A[i];
    A[i] = A[j];
    A[j] = temp;
}

int partition(int A[], int p, int r) {
    int x = A[r - 1];
    int i = p - 1;
    for (int j = p; j < r - 1; j++) {
        if (A[j] <= x) {
            i++;
            swap(A, i, j);
        }
    }

    swap(A, r - 1, i+1);

    return i+1;
}

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

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

    int index = partition(A, 0, n);

    for (int i = 0; i < n; i++) {
        if (i != 0) cout << " ";
        if (i == index) {
            cout << "[" << A[i] << "]";
        } else {
            cout << A[i];
        }
    }
    cout << endl;
}


Measured memory_bytes: 3372
#include <bits/stdc++.h>
#define ll long long int
#define f(i,a,n) for(i=a;i<n;i++)
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define test() ll tc;cin>>tc;while(tc--)

using namespace std;

const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;
const ll INF = 1e13;


/*ll fact(ll n);

ll comb(ll n, ll r)
{
    return fact(n) / (fact(r) * fact(n - r));
}

ll fact(ll n)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
        res = ((res%mod * i%mod)%mod)%mod;
    return res;
}


ll power(ll x, ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}

*/


void dfs(ll node,vector<ll> adj[],ll dp[],bool vis[])
{
    vis[node]=true;

    for(ll i=0;i<adj[node].size();i++)
    {
        if(!vis[adj[node][i]])
        {
            dfs(adj[node][i],adj,dp,vis);
        }

        dp[node] = max(dp[node],1+dp[adj[node][i]]);
    }
}



ll findlongestpath(vector<ll> adj[],int n)
{
    ll dp[n+1];
    memset(dp,0,sizeof(dp));
    bool vis[n+1];
    memset(vis,false,sizeof(vis));


    ///call dfs for every unvisited node
    for(ll i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            dfs(i,adj,dp,vis);
        }
    }

    ll ans=0;
    for(ll i=0;i<n+1;i++)
    {
        ans=max(ans,dp[i]);
    }
    return ans;


}


int main()
{
        fast();
        ll n,m,a,b;
        //m->edges,n->node
        cin>>n>>m;
        vector<ll> adj[n+1];
        for(ll i=0;i<m;i++)
        {
            cin>>a>>b;
            adj[a].push_back(b);
        }
        cout<<findlongestpath(adj,n);

        return 0;
}


Measured memory_bytes: 9984
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int d = sc.nextInt();

        int[][] list = new int[n][d];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
              list[i][j] = sc.nextInt();
            }
        }

        int count = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int sum = 0;
                for (int k = 0; k < d; k++) {
                    int value = list[i][k] - list[j][k];
                    sum += value * value;
                }
                double root = Math.sqrt(sum);
                int seisu = (int) root;
                if ((double)seisu - root == 0) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
char a[50][50];
char b[50][50];
int main() {
    int k,s;
    cin>>k>>s;
    int cnt=0;
    REP(i,k+1){
        REP(j,k+1){
                if(i+j<=s && s-(i+j)<=k){
                    cnt++;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}

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

int main() {
  int N, M, L = 0;
  cin >> N >> M;
  if(M <= N) {
    printf("0\n");
    return 0;
  }
  
  vector<int> X(M);
  vector<int> dX(M-1);
  for (int i = 0; i < M; i++){
    cin >> X.at(i);
  }
  sort(X.begin(), X.end());
  for (int i = 0; i < M-1; i++){
    dX.at(i) = X.at(i+1) - X.at(i);
  }
  sort(dX.begin(), dX.end());
  for (int i = 0; i < M - N; i++){
    L += dX.at(i);
  }
  
  printf("%d\n",L);  
}

Measured memory_bytes: 1024
s = input()

# print(s[5:], s[:5])

t = 0
import itertools
for i in range(0, len(s)):
    for j in list(itertools.combinations([i for i in range(1, len(s))], i)):
        j = list(j)
        j.append(len(s))
        # print(s[:j[0]])
        t += int(s[:j[0]])
        for k in range(len(j)-1):
            # print(s[j[k]:j[k+1]])
            t += int(s[j[k]:j[k+1]])
print(t)

Measured memory_bytes: 40304
import copy
n=int(input())
a=[int(input()) for i in range(5)]

w=sorted(a)
"""
b=[i  for i in range(5)if a[i]==w[0] and (n>a[i] and a[i]!=a[i-1])]
#b=a.index(w[0])
ans=0
m=1
b.append(6)
for i in b:
    ans=ans+i-m
    m=i
    



x=(n//w[0] if n>w[0] else 0)
m=0
wa=copy.copy(a)
for i in a:
    if m==i:
        wa.remove(i)
    m=i


ans=x*(wa.count(w[0]))+ans
"""
##print(ans)
print(-(-n//w[0])+4)

Measured memory_bytes: 3444
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include <numeric>
#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++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 99999999

using namespace std;


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


ll m = 1000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

int p[100010];
int main() {
	int N;
	p[0] = 0;
	cin >> N;
	FOR(i,1, N+1) {
		cin >> p[i];
	}
	int ans = 0;
	FOR(i, 1, N + 1) {
		if (p[i] == i) {
			if (p[i + 1] == i + 1) {
				ans++;
				i++;
			}
			else ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
l, r = map(int, input().split(' '))
if (r - l) > 2019:
  r = l + 2019
ary = [num for num in range(l, r+1)]
# print(ary)
ans = 10000

for i in range(len(ary) -1):
  for j in range(i+1, len(ary)):
    tmp = (ary[i] * ary[j]) % 2019
    if tmp < ans:
      ans = tmp
    if ans == 0:
      break

print(ans)

Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){
  string s;
  cin >> s;
  if(stoi(s.substr(0,4))<2019){ cout << "Heisei" << endl; return 0;}
  if(stoi(s.substr(0,4))==2019 && stoi(s.substr(5,2))<4){ cout << "Heisei" << endl; return 0;}
  if(stoi(s.substr(0,4))==2019 && stoi(s.substr(5,2))==4 && stoi(s.substr(8,2))<31){ cout << "Heisei" << endl; return 0;}

  cout << "TBD" << endl; 
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}

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

using namespace std;

#define ll long long

ll MIN(ll num1,ll num2){
    return num1<num2?num1:num2;
}

int main(){

    ll A,B,C;
    cin>>A>>B>>C;
    if(A%2==0||B%2==0||C%2==0)cout<<0<<endl;
    else{
        cout<<MIN(A*B,MIN(B*C,C*A))<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <map>
#include <unordered_set>
#include <tuple>
#include <queue>
#include <set>
#include <cstring>
#include <functional>
#include <random>
#include <chrono>

#define ar array
#define all(arr) (arr).begin(), (arr).end()
#define range(i, n) for (int i=0; i < n; ++i)
#define rall(arr) (arr).rbegin(), (arr).rend()

typedef long long ll;
typedef long double ld;

using namespace std;

const ll INF = 1e18;
const int INFi = 2e9;
const int maxN = 1e5 + 5;
const int md2 = 998244353;
const int md = 1e9 + 7;

double getTime() { return clock() / (double) CLOCKS_PER_SEC; };

int mul(int a, int b) {
    return (1ll * a * b) % md;
}

int binpow(int a, int b) {
    if (b <= 0) return 1;
    if (b % 2) return mul(binpow(a, b - 1), a);
    int m = binpow(a, b / 2);
    return mul(m, m);
}

int rev(int a) {
    return binpow(a, md - 2);
}

int fact[maxN];
void init() {
    fact[0] = 1;
    for(int i = 1; i < maxN; ++i) fact[i] = mul(fact[i-1], i);
}

int C(int n, int k) {
    return mul(fact[n], rev(mul(fact[k], fact[n-k])));
}

void solve() {
    init();
    int s; cin >> s;
    int ans = 0;
    for(int cnt = 1; cnt <= s; ++cnt) {
        int curs = s - 3 * cnt;
        if (curs < 0) break;
        ans = (ans + C(curs + cnt - 1, cnt - 1)) % md;
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //cout << setprecision(15) << fixed;
    int tests = 1;
    //cin >> tests;
    range(_, tests) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4028
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc =new Scanner(System.in);
		int n,q;
		n = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<n;i++){
			nums[i] = sc.nextInt();
		}
		q = sc.nextInt();
		int[] data = new int[q];
		for(int i=0;i<q;i++){
			data[i] = sc.nextInt();
		}
		Arrays.sort(nums);
		int ans =0;
		for(int i=0;i<q;i++){
			if(search(nums,data[i])){
				ans++;
			}
		}
		System.out.println(ans);
		
		
	}
	public static boolean search(int[] nums,int x){
		int l =0; 
		int r = nums.length-1;
		while(l<=r){
			int mid = l+(r-l)/2;
			if(nums[mid]==x){
				return true;
			}else if(nums[mid]>x){
				r =mid-1;
			}else{
				l =mid+1;
			}
		}
		return false;
	}
}

Measured memory_bytes: 68652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long Q = sc.nextInt();
		long H = sc.nextInt();
		long S = sc.nextInt();
		long D = sc.nextInt();
		long N = sc.nextInt();
		sc.close();
		long a = Math.min(4 * Q, Math.min(2 * H, S));
		long ans = Math.min((N / 2) * D + (N % 2) * a, a * N);
		System.out.println(ans);
	}
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int a,b;cin>>a>>b;){
		if(a+b==15)
			cout<<'+'<<endl;
		else if(a*b==15)
			cout<<'*'<<endl;
		else
			cout<<'x'<<endl;
	}
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
using namespace std;

#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 ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

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

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

string s;

int main() {
    //freopen("in.txt", "r", stdin);
    
    cin >> s;
    string s2;
    FOR (i,0,s.size())
    if (s[i] != 'x')
    {
        s2 += s[i];
    }
    bool ok = 1;
    FOR (i,0,s2.size())
    if (s2[i] != s2[SZ(s2)-i-1])
        ok = 0;
    if (!ok)
    {
        cout << -1;
        return 0;
    }
    if (s2.size() == 0)
    {
        cout << 0;
        return 0;
    }
    int p1, p2, num = 0;
    if (s2.size()%2 == 0)
    {
        FOR (i,0,s.size())
        if (s[i] != 'x')
        {
            num++;
            if (num == s2.size()/2)
            {
                p1 = i;
            }
            if (num == s2.size()/2+1)
            {
                p2 = i;
            }
        }
    }
    else
    {
        FOR (i,0,s.size())
        if (s[i] != 'x')
        {
            num++;
            if (num == s2.size()/2+1)
            {
                p1 = p2 = i;
            }
        }
    }
    //cout << p1<<" "<<p2<<endl;
    int ans = 0;
    while (p1 != -1 && p2 != (int)s.size())
    {
        if (s[p1] == s[p2]) p1--, p2++;
        else
        {
            ans++;
            if (s[p1] == 'x') p1--;
            if (s[p2] == 'x') p2++;
        }
    }
    //cout << p1<<" "<<p2<<endl;
    cout << ans + p1+1 + s.size()-p2;
}




Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP=pair<P, int>;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			if (mod <= ans * x) ans = ans * x % mod;
			else ans *= x;
		}
		if (mod <= x * x) x = x * x % mod;
		else x *= x;
		n >>= 1;
	}
	return ans;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
		fact_memo[i + 1] = ans;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

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

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

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

int n;
int a[100010], b[100010];
int ans;
signed main() {
	cin >> n;
	rep(i, n + 1) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
	}
	rep(i, n) {
		if (b[i] < a[i]) {
			ans += b[i];
			a[i] -= b[i];
			b[i] = 0;
		}
		else {
			ans += a[i];
			b[i] -= a[i];
			a[i] = 0;
			if (b[i] < a[i + 1]) {
				ans += b[i];
				a[i + 1] -= b[i];
				b[i] = 0;
				a[i + 1] -= b[i];

			}
			else {
				ans += a[i + 1];
				b[i] -= a[i + 1];
				a[i + 1] = 0;
				b[i] -= a[i + 1];
			}
		}
	}
	//rep(i, n) cout << b[i] << " ";
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#define REP(i, n) for(long long int i=0; i<(n); i++)
#define FOR(i, a, n) for(long long int i=(a); i<(n); i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;

int main(){
    int N;cin>>N;
    vi H(N);
    REP(i, N){
        cin >> H[i];
    }

    string ans = "Yes";
    int sa = 0;
    REP(i, N-1){
        if(H[i+1] - H[i] > 0) sa = 0;
        else if (H[i+1] - H[i] < 0) sa += H[i+1] - H[i];

        if(sa < -1){
            ans = "No";
            break;
        }
    }

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

Measured memory_bytes: 640
#include<iostream>
#include<set>
using namespace std;
int N;
set<int>S;
main()
{
  cin>>N;
  for(int i=0;i<N;i++)
  {
    int a;cin>>a;S.insert(a);
  }
  N=S.size();
  cout<<N-(N+1)%2<<endl;
}

Measured memory_bytes: 4992
n = int(input())
w = input().split()
flag = 0
for i in range(1,n):
    w.append(input())
    if w[i-1][-1] == w[i][0] and w[i] not in w[:i]:
        pass
    else:
        flag += 1
print('Yes' if flag == 0 else 'No')

Measured memory_bytes: 3060