akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
    long long i,j,a[5][5],n,k,x,r[5]={0},c[5]={0},l,f=0,h=0,d=0;
    for(i=1;i<=3;i++)
    {
        for(j=1;j<=3;j++)
        {
            cin>>a[i][j];
        }
    }
    cin>>n;
    for(k=1;k<=n;k++)
    {
        cin>>x;
        for(i=1;i<=3;i++)
        {
            for(j=1;j<=3;j++)
            {
                if(a[i][j]==x)
                {
                    r[i]=r[i]+1;
                    c[j]=c[j]+1;
                    if(i==j)
                    {
                        h++;
                    }
                    if((i==1&&j==3)||(i==2&&j==2)||(i==3&&j==1))
                    {
                        d++;
                    }
                }
            }
        }
    }
    for(l=1;l<=3;l++)
    {
        if(r[l]==3||c[l]==3||h==3||d==3)
        {
            f++;
            cout<<"Yes"<<endl;
            break;
        }
    }
    if(f==0)
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3476
N = int(input())
A = list(map(int, input().split()))

ans = 0
tmp = float('inf')
cnt = 0
for a in A:
    if a >= 0:
        ans += a
        tmp = min(tmp, a)
    else:
        ans -= a
        tmp = min(tmp, -a)
        cnt += 1
        
if cnt % 2 == 1:
    print(ans - tmp*2)
else:
    print(ans)

Measured memory_bytes: 14332
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N;
string s;

int main () {
  cin >> N;
  cin >> s;

  int ans = 0;

  Rep(i, N) {
    if (s.substr(i, 3) == "ABC") {
      ++ans;
    }
  }

  cout << ans << "\n";
}

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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int64_t M = 1e9+7;

vector<int64_t> inv_tbl(2000000);

int64_t modpow(int64_t n, int64_t m) {
    if (m == 0) return 1;
    else if (m % 2 == 0) { 
        int64_t r = modpow(n, m / 2);
        return (r * r) % M;
    } else {
        int64_t r = modpow(n, m / 2);
        return ((n * r) % M * r) % M;
    }
}

int64_t inv(int n) {
    return inv_tbl[n];
}

void compute_inv() {
    for (size_t i = 0; i < inv_tbl.size(); ++i) {
        inv_tbl[i] = modpow(i, M - 2);
    }
}

int64_t comb(int n, int k) {
    int64_t c = 1;
    for (int i = 1; i <= k; ++i) {
        c = (((n - i + 1) * inv(i)) % M * c) % M;
    }
    return c;
}

int64_t f(int r, int c) {
    int64_t x = comb(r+1+c+1, c+1);
    return x - 1;
}

int main() {
    compute_inv();
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    cout << (f(r2, c2) + f(r1 - 1, c1 - 1)  - f(r1 - 1, c2) - f(r2, c1 - 1) + 5*M) % M << endl;
}

Measured memory_bytes: 15872
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++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 all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,M;
  cin>>N;
  int T[N];
  rep(i,N)
    cin>>T[i];
  cin>>M;
  int P[M],X[M];
  rep(i,M)
    cin>>P[i]>>X[i];
  int sum=0;
  rep(i,N)
    sum+=T[i];
  rep(i,M){
    cout<<sum-T[P[i]-1]+X[i]<<endl;
  }
}




Measured memory_bytes: 256
n_ = 2*10**5 + 10
mod = 10**9 + 7
fun = [1] * (n_ + 1)
for i in range(1, n_ + 1):
    fun[i] = fun[i - 1] * i % mod
rev = [1] * (n_ + 1)
rev[n_] = pow(fun[n_], mod - 2, mod)
for i in range(n_ - 1, 0, -1):
    rev[i] = rev[i + 1] * (i + 1) % mod


def nCr(n, r):
    if r > n:
        return 0
    return fun[n] * rev[r] % mod * rev[n - r] % mod

def modinv(x, mod):
    a, b = x, mod
    u, v = 1, 0
    while b:
        t = a // b
        a -= t * b; a, b = b, a
        u -= t * v; u, v = v, u
    return u % mod

n,a,b,c = map(int, input().split())
m100 = modinv(a+b, mod)
a = a * m100 % mod
b = b * m100 % mod
pa = [1]*(n+1)
pb = [1]*(n+1)
for i in range(n):
  pa[i+1] = pa[i] * a % mod
  pb[i+1] = pb[i] * b % mod
ans = 0
for i in range(n, 2*n):
  ans += i * nCr(i-1, n-1)*((pa[n]*pb[i-n] + pb[n]*pa[i-n]) % mod) % mod

print(ans * 100 * modinv(100-c, mod) % mod)

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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class ADuplexPrinting {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      cout << (n+1)/2 << endl;

    }
};

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

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {
  ll n;
  	ci(n);
  ll ans=0;
  ll countA=0;
  ll countB=0;
  ll countC=0;
  vst A(n);
  vpll B(n);
  
  FOR(i,0,n){
    ci(A[i])
    ll S=A[i].sz;
    
      FOR(j,1,S){
      if(A[i].at(j-1)=='A'&&A[i].at(j)=='B'){
        B[i].fi++;
      }
      }
    
      if(A[i].at(S-1)=='A'){
		B[i].se+=1;
      }
      if(A[i].at(0)=='B'){
        B[i].se+=2;
      }   
	ans+=B[i].fi;
}
    
    FOR(i,0,n){
      if(B[i].se==1){
        countA++;
      }
      else if(B[i].se==2){
        countB++;
      }
      else if(B[i].se==3){
        countC++;
      }
    }
  if(countC>=2){
    ans+=(countC-1);
  }
  
  if(countC>=1){
    if(countA>=1&&countB>=1){
    ans+=2;
    countA--;
    countB--;
  }
    else if(countA>=1){
      ans++;
      countA--;
    }
    else if(countB>=1){
      ans++;
      countB--;
    }
  }
    ans+=min(countA,countB);
    co(ans);
}     

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string a, b, s;
    cin>>a;
    cin>>b;
    int lena = a.size();
    int lenb = b.size();
    int len = max(lena, lenb);
    for(int i = 0; i < len; i++){
        if(i < lena)s+=a[i];
        if(i < lenb)s+=b[i];
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int I, O, T, J; cin >> I >> O >> T >> J;
	int L, S, Z; cin >> L >> S >> Z;
	int K = O;
	int k = 0;
	for (int x = 0; x < 1000; x++) {
		if (x > min({ I, L, J }))continue;
		int t = ((I - x) / 2) * 2 + ((J - x) / 2) * 2 + ((L - x) / 2) * 2 + x * 3;
		dump(t);
		chmax(k, t);
	}
	K += k;
	cout << K << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits> 
#include <time.h>

int main(void){
    long N;
    std::cin >> N;
    N = N-(N/10)*10;
    if(N==3){
        std::cout << "bon" << std::endl;
    }else if(N== 1 || N==0 || N==6 || N==8){
        std::cout << "pon" << std::endl;
    }else{
        std::cout << "hon" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3624
//
// Created by moono on 2018/10/27.
//

#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;



int main() {
    //
    int N, K;
    cin >> N;
    cin >> K;

    //
    int x, cost = 0;
    for (int i = 0; i < N; ++i) {
        cin >> x;
        cost += min(x, abs(K-x)) * 2;

    }

    cout << cost << endl;

    return 0;
}

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

int main() {
	int ch[26];
	for(int i = 0; i < 26; i++) 
		ch[i] = 0;
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		ch[s[i] - 'a']++;
	}
	bool fool = true;
	for(int i = 0; i < s.size(); i++){
		if(ch[s[i] - 'a'] % 2 != 0) {
			fool = false;
			break;
		}
	}
	if(fool)
		printf("Yes\n");
	else printf("No\n");

}

Measured memory_bytes: 3612
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
    int n, m;
    cin>>n>>m;
    vector<pair<int, p_ii>> p(m);

    for (int i = 0; i < m; i++) {
        int pre, year;
        cin>>pre>>year;
        p[i].first=year;
        p[i].second.first=pre;//県番号
        p[i].second.second=i;//市番号
    }

    sort(p.begin(),p.end());

    vector<p_ii> res(m+1);
    vector<int> num(n+1, 1);
    for (int i = 0; i < m; i++) {
        res[p[i].second.second].first=p[i].second.first;
        res[p[i].second.second].second=num[p[i].second.first];
        num[p[i].second.first]++;
    }

    for (int i = 0; i < m; i++) {
        string f = to_string(res[i].first);
        string s = to_string(res[i].second);
        while(f.size()<6){
            f='0'+f;
        }
        while(s.size()<6){
            s='0'+s;
        }

        cout<<f+s<<endl;
    }

    return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S; cin>>S;
    reverse(S.begin(),S.end());
    string T[4]={"dream","dreamer","erase","eraser"};
    for(int i=0;i<4;i++){
        reverse(T[i].begin(),T[i].end());
    }
    bool can= true;
    for(int i=0;i<S.size();){
        bool can2=false;
        for(int j=0;j<4;j++){
            if(S.substr(i,T[j].size())==T[j]){
                i=i+T[j].size();
                can2=true;
            }
        }
        if(can2==false){
            can=false;
            break;
        }

    }


    if(can){
          cout<<"YES";
    }
    else{
        cout<<"NO";
    }
    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

const int MAX_N = 100005; // 要素数の最大

int par[MAX_N]; // 親
int rk[MAX_N];  // 木の深さ(rank)

// n要素で初期化
void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        par[i] = i;
        rk[i] = 0;
    }
}

// 木の根を求める
int find(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を併合
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y)
    {
        return;
    }

    if (rk[x] < rk[y])
    {
        par[x] = y;
    }
    else
    {
        par[y] = x;
        if (rk[x] == rk[y])
        {
            rk[x]++;
        }
    }
}

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

int main()
{
    int n, q;
    cin >> n >> q;
    init(n);
    for (int i = 0; i < q; i++)
    {
        int mode, x, y;
        cin >> mode >> x >> y;
        if (mode == 1)
        {
            cout << int(same(x, y)) << endl;
        }
        else
        {
            unite(x, y);
        }
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3160
#include <cstdio>
#include <algorithm>
using namespace std;
int a,b,c,d;
int main(){
	scanf("%d%d%d%d",&a,&b,&c,&d);
	printf("%lld\n",max(max(1ll*a*c,1ll*b*d),max(1ll*a*d,1ll*b*c)));
	return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
main(){
  int a,b;
  cin>>a>>b;
  if(a%2==0 || b%2==0){
    cout<<"Even"<<endl;
  }
  if(a%2==1  && b%2==1){
    cout<< "Odd"<<endl;
  }
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n, x, y;
	scanf("%d%d%d", &n, &x, &y);
	vector<int> ans(n + 1);
	vector<char> vis;
	for(int s = 1; s <= n; ++s){
		queue<int> q;
		q.push(s);
		q.push(-1);
		vis.assign(n + 1, 0);
		auto add = [&](int v){
			if(v > 0 && v <= n && !vis[v]){
				vis[v] = 1;
				q.push(v);
			}
		};
		int dist = 0;
		while(q.size() > 1){
			int u = q.front();
			q.pop();
			if(u < 0){
				q.push(-1);
				++dist;
			}
			else{
				if(u > s){ ++ans[dist]; }
				add(u - 1);
				add(u + 1);
				if(u == x){ add(y); }
				if(u == y){ add(x); }
			}
		}
	}
	for(int i = 1; i < n; ++i){
		printf("%d\n", ans[i]);
	}
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 256
from collections import defaultdict

def main():
    while True:
        n,m,a = map(int,input().split())
        if not n and not m and not a:
            return
        hlines = [tuple(map(int,input().split())) for _ in range(m)]
        hlines = sorted(hlines, key=lambda x: x[0], reverse=True)

        for h in range(hlines[0][0], -1, -1):
            for hline in hlines:
                if hline[0] == h:
                    if hline[1] == a:
                        a = hline[2]
                    elif hline[2] == a:
                        a = hline[1]

        print(a)

if __name__ == '__main__':
    main()



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

namespace ABC117B
{
    class MainClass
    {

        static int[] s;
        static int[] n;

        public static void Main(string[] args)
        {

            n = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse);
            s = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse);


            Array.Sort(s);
            int sum = 0;
            for(int i = 0; i < n[0]-1;i++)
            {
                sum += s[i];
            }
            if (s[n[0] - 1] < sum)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");

            }


            return;


        }
    }
}


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

int main() {
    int a, b, c, x;
    int ans = 0;
    cin >> a >> b >> c >> x;
    rep(i, a + 1) {
        rep(j, b + 1) {
            rep(k, c + 1) {
                if (i * 500 + j * 100 + k * 50 == x) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
signed main(){
	int n;
	cin>>n;
	vi a(n),b(n);
	int x=0;
	rep(i,n){
		int c;cin>>c;
		x^=c;
		a[i]=c;
	}
	a.pb(x);
	x=0;
	rep(i,n){
		int c;cin>>c;
		x^=c;
		b[i]=c;
	}
	b.pb(x);
	
	{
		vi c=a,d=b;
		sort(all(c));
		sort(all(d));
		bool h=true;
		rep(i,n+1)if(c[i]-d[i])h=false;
		if(!h){
			cout<<-1<<endl;
			return 0;
		}
	}
	map<int,int>ma;
	int t=1;
	rep(i,a.size())if(!ma[a[i]])ma[a[i]]=t++;
	rep(i,b.size())if(!ma[b[i]])ma[b[i]]=t++;

	int out=-1;
	UnionFind uf(t);
	rep(i,n)if(a[i]-b[i]){
		out++;
		uf.unionSet(ma[a[i]],ma[b[i]]);
	}
	rep(i,t)if(uf.root(i)==i&&uf.size(i)>1)out++;
	if(uf.size(ma[a[n]])==1)out++;
	if(out<0)out=0;
	cout<<out<<endl;
}








Measured memory_bytes: 8900
#include <iostream>
using namespace std;
int x[100000][3];
int a[100001][3], mx=0;
int calc(int pos, int u)
{
	if(pos==-1) return 0;
	if(a[pos][u]==-1)
	{
		//if(pos==0) a[pos][u]=mx(x[pos][(u+1)%3],x[pos][(u+2)%3]);
		a[pos][u]=max(calc(pos-1, (u+1)%3)+x[pos][(u+1)%3],calc(pos-1, (u+2)%3)+x[pos][(u+2)%3]);
	}
	return a[pos][u];
}

int main() {
	int n;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		for(int u=0; u<3; u++)
		{
			cin>>x[i][u];
		}
	}
	for(int i=0; i<=n; i++)
	{
		for(int u=0; u<3; u++)
		{
			a[i][u]=-1;
		}
	}
	for(int i=0; i<3; i++)
	{
		if(mx<calc(n, i) ) mx=calc(n-1, i);
	}
	cout<<mx;
	return 0;
}

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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    string s;
    cin>>s;
    int ans=0;
    int cnt=0;
    rep(i,3){
        if(s[i]=='R'){
            cnt++;
        }
        else{ 
            ans=max(ans,cnt);
            cnt=0;
        }
    }
    ans=max(ans,cnt);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
N = int(input())
b = []
for i in range(N):
    string = input()
    b.append(string)
r = []
M = int(input())
for i in range(M):
    r.append(input())

bd = {}
for a in b:
    if a not in bd:
        bd[a] = 0
    bd[a] += 1
rd = {}
for a in r:
    if a not in rd:
        rd[a] = 0
    rd[a] += 1

counter = []
keys = set(bd) | set(rd)
for key in keys:
    tmp = 0
    if key in bd:
        tmp += bd[key]
    if key in rd:
        tmp -= rd[key]
    counter.append(tmp)
foo = max(counter)
if foo > 0:
    print(foo)
else:
    print(0)

Measured memory_bytes: 3064
n = gets.chomp.to_i
persons = n.times.map do
  gets.chomp
end

grouped_p = persons.group_by{|p| p[0]}
  .map{|k,v| [k.to_sym, v.size]}.to_h

cnt_hash = {M: 0, A: 0, R: 0, C: 0, H: 0}
cnt_hash.merge! grouped_p

ans = "MARCH".chars.combination(3).inject(0) do |sum, attr|
  sum + cnt_hash[attr[0].to_sym] * cnt_hash[attr[1].to_sym] * cnt_hash[attr[2].to_sym]
end

puts ans


Measured memory_bytes: 10784
#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);
  }
  
  bool judge = true;
  for (int i=0; i<N; i++){
    if (A.at(i) % 2 == 0){
      if (A.at(i) % 3 != 0 && A.at(i) % 5 != 0){
        judge = false;
      }
    }
  }
  if (judge){
    cout << "APPROVED" << endl;
  }
  else{
    cout << "DENIED" << endl;
  }
}

Measured memory_bytes: 256
a = list(map(int, input().split()))
while a[0] > 0 and a[2] > 0:
    a[2] = a[2] - a[1]
    if a[2] > 0:
        a[0] = a[0] - a[3]
if a[0] <= a[2]:
    print("No")
else:
    print('Yes')

Measured memory_bytes: 9064
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,d,x,y,z;
string s,t;
//

signed main() {
  RAPID;
  IN2(x,y);
  if(x>=y) OUT(x-y);
  else OUT(0);
}

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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	int n;
	string s;
	cin >> n >>s;
	int maxt=0;
	int x=0;
	int i=0;
	while(i <n){
		if(s[i]=='D') {
			x--;

		}
		if(s[i]=='I'){
			x++;
			maxt=max(x,maxt);
		}
		i++;
	}
	cout << maxt;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 998244353
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

vector<ll> factmemo, factmemoInv;
ll factmemoMod = -1;

ll factorial(int n, int M){
  if(n <= 1) return 1;
  if(factmemoMod == M) return factmemo[n];

  ll res = 1;
  for(int i=1; i<=n; i++) res = res * i % M;
  return res;
}

ll power(int k, int n, int M){
  if(n == 0) return 1;
  if(n == 1) return (ll)k;

  ll res = power(k, n/2, M);

  res = res * res % M;
  return n%2 == 1 ? res * k % M : res;
}

void initFactorial(int n, int M){
  factmemo.assign(n+1, 0);
  factmemoInv.assign(n+1, 0);
  factmemoMod = M;
  factmemo[0] = 1;
  for(int i=1;i<=n;i++) factmemo[i] = factmemo[i-1] * i % M;
  factmemoInv[n] = power(factmemo[n], M-2, M);
  for(int i=n;i>0;i--) factmemoInv[i-1] = factmemoInv[i] * i % M;
}

//nCm nPm nHm (mod M)

/*Combination*/
ll C(int n, int m, int M){
  if(n < m) return 0;
  if(m == 0 || n == m) return 1;

  debug(n);

  if(factmemoMod == M)
    return factmemo[n] * factmemoInv[m] % M * factmemoInv[n-m] % M;

  ll numer = factorial(n, M);
  ll denom = factorial(m, M) * factorial(n-m, M) % M;

  denom = power((int)denom, M-2, M);

  return numer * denom % M;
}
/*Permutation*/
ll P(int n, int m, int M){
  if(n < m) return 0;
  if(m == 0) return 1;

  if(factmemoMod == M)
    return factmemo[n] * factmemoInv[n-m] % M;

  ll numer = factorial(n, M);
  ll denom = factorial(n-m, M);

  denom = power((int)denom, M-2, M);

  return numer * denom % M;
}
/*Combination with Repetitions*/
ll H(int n, int m, int M){
  if(n == 0 && m == 0) return 1;
  return C(n+m-1, m, M);
}



int main(){
  int N, M;

  cin >> N >> M;

  ll all = 0;
  ll minus = 0;

  initFactorial(N*2 + M*2 + 1, mod);

  for(int i=0; i<=N; i++) {
    if (M%2 != i%2 || i > M) continue;

    int P = i; // 1
    int Q = (M - i)/2; // 1+1
    int R = M; // 2

    // P, Q + R

    int S = Q + R;

    debug(S);

    all += C(N, P, mod) * C(N-1+S, N-1, mod) % mod;
    minus += C(N, P, mod) * C(P, 1, mod) % mod * C((N-1)+(S-M), N-1, mod) % mod;
    minus += C(N, P, mod) * C(N-P, 1, mod) % mod * C((N-1)+(S-(M+1)), N-1, mod) % mod;
  }

  all %= mod;
  minus %= mod;

  cout << (all + mod - minus) % mod << endl;

  return 0;
}


Measured memory_bytes: 47104
import itertools, sys

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

exists = [[True] * n for _ in range(n)]
for k, i, j in itertools.product(range(n), repeat=3):
    if a[i][k] + a[k][j] == a[i][j] and i != k and k != j:
        exists[i][j] = False
    elif a[i][k] + a[k][j] < a[i][j]:
        print(-1)
        sys.exit()

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        if exists[i][j]:
            ans += a[i][j]
print(ans)

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll n, p;
  cin >> n >> p;
  map<ll, int> prime;
  for(ll i = 2; i*i <= p; ++i) {
    while(p%i==0) {
      ++prime[i];
      p/=i;
    }
  }
  if(p!=1) ++prime[p];
  ll ans = 1;
  for(auto x : prime) ans *= (ll)pow(x.first, x.second/n);
  cout << ans << endl;
}


Measured memory_bytes: 4036
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <unordered_set>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define amax 26

string s;

bool trymake(string t, int baselen)
{
    bool b[amax];
    rep(i, amax)
    {
        b[i] = false;
    }

    rep(i, baselen)
    {
        b[t[i] - 'a'] = true;
    }

    char lim = 0;
    if (t.length() > baselen)
        lim = t[baselen] - 'a' + 1;

    for (char i = lim; i < amax; i++)
    {
        if (!b[i])
        {
            char c = i + 'a';
            cout << t.substr(0, baselen) << c << endl;
            return true;
        }
    }

    return false;
}

int main(void)
{
    cin >> s;

    for (int i = s.length(); i >= 0; i--)
    {
        if (trymake(s, i))
            return 0;
    }

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
class segment_():
    def __init__(self,n,ide_ele,segfunc):
        self.ide_ele = ide_ele
        self.num = 1 << n.bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        self.segfunc = segfunc

    def update1(self, k):
        k += self.num
        self.seg[k] += 1
        while k:
            k >>= 1
            self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1])

    def query(self, p, q):
        if q < p:
            return self.ide_ele
        p += self.num;
        q += self.num
        res = self.ide_ele
        while p < q:
            if p & 1 == 1:
                res = self.segfunc(res, self.seg[p])
                p += 1
            if q & 1 == 1:
                q -= 1
                res = self.segfunc(res, self.seg[q])
            p >>= 1;
            q >>= 1
        return res

def main():
  import sys
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  readlines = sys.stdin.buffer.readlines
  from operator import itemgetter

  N,M,Q = map(int,readline().split())
  S = segment_(N,0,lambda a, b: a+b)
  chk = []
  for i in range(M):
    L,R = map(int,readline().split())
    chk.append((1,L,R,i))
  for i in range(Q):
    l,r = map(int,readline().split())
    chk.append((2,l,r,i))

  chk.sort(key=itemgetter(2))
  ans = [0]*Q
  for a,l,r,i in chk:
    if a == 1:
      S.update1(l)
    else:
      ans[i] = S.query(l,r+1)

  print(*ans,sep='\n')
if __name__ == '__main__':
    main()

Measured memory_bytes: 54736
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long int
ll slow_gcd(ll c, ll d) {
  for(int i = d; i < c*d; i++) {
    if(i%c==0 && i%d==0) return i;
  }
  return c*d;
}

ll gcd(ll c, ll d) {
  if(c == 0) return d;
  if(d == 0) return c;
  if(c < d) return gcd(c, d%c);
  else return gcd(c%d, d);
}

ll nondiv(ll k, int c, int d) {
  ll ans;
  ans = (k/c) + (k/d) - (k/(c/gcd(c,d)*d));
  return k-ans;
}
int main() {
  ll a, b, c, d;
  std::cin >> a >> b >> c >> d;
  std::cout << nondiv(b, c, d) - nondiv(a-1, c, d) << std::endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {// Main
    public static void main(String[] args){
Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] h = new int[n+1];
		HashMap<Integer, HashSet<Integer>> map = new HashMap<>();

		for (int i = 0; i < n; i++) {
			h[i+1] = sc.nextInt();
			map.put(i+1, new HashSet<>());
		}
		for (int i = 0; i < m; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			map.get(x).add(y);
			map.get(y).add(x);
		}
		
		int ans = 0 ;
		for(int i = 1 ; i <= n; i++ ) {
			boolean ch  =true;
			for(int key : map.get(i)) {
				if(h[key] >= h[i]) {
					ch = false;
				}
			}
			if(ch)
				ans++;
		}
		System.out.println(ans);       
}
}


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

using namespace std;

const int size = 3005;
int arr[size];
long long int dp[2][size][size];

long long int check(int l, int r, int c){
	if(l == r){
		if(c == 0)
		return arr[l];
		else return -arr[l];
	}
	if(dp[c][l][r] != -1) return dp[c][l][r];

	if(c == 0) dp[c][l][r] = max(arr[l] + check(l+1,r, 1), arr[r] + check(l, r-1, 1));
	else dp[1][l][r] = min(check(l+1, r, 0) - arr[l], check(l,r-1,0) - arr[r]);

	// cout<<c<<" "<<l<<" "<<r<<" "<<dp[c][l][r]<<"\n";

	return dp[c][l][r];
}

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

	for(int x=0;x<n;x++) cin>>arr[x];
	int l=0, r = n-1;
	for(int x=0;x<n;x++) for (int i=0;i<n;i++) dp[0][i][x] = dp[1][i][x] = -1;
	cout<<check(l, r, 0);
	return 0;
}

Measured memory_bytes: 141440
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

#define all(x) begin(x),end(x)

using namespace std;
using ll = long long;

int main()
{
    string s;
    cin >> s;
    int mid;
    if (s.size() % 2 == 1) {
      mid = s.size() / 2;
    } else {
      mid = s.size() / 2 - 1;
    }

    int res = 0;
    int base = s.size() / 2;
    int c = 0;
    for (int i = s.size() - 1; i > mid; --i, c++) {
        if (s[i] != s[(c)]) {
            res++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
from collections import deque

s = input()
ans = 0
now = deque()
for i in range(len(s)):
    if not now:
        now.append(s[i])
        continue
    else:
        if now[-1] != s[i]:
            ans +=2
            now.pop()
        else:
            now.append(s[i])
print(ans)

Measured memory_bytes: 4596
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
int n, k;
LL dp[31];
int num[31];


int main() {
//    freopen("test.txt", "r", stdin);
    scanf("%d%d", &n, &k);
    int a, b;
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &a, &b);
        if (a <= k) {
            for (int j = 30; j >= 0; j--) {
                int tmp1 = a >> (j+1);
                int tmp2 = k >> (j+1);
                if ((tmp1|tmp2)<= tmp2 && ((1<<j)&a) == 0) {
                    dp[j] += b;
                    num[j] |= a;
                }
            }
        }
    }
    LL ret = 0;
    for (int i = 0; i < 31; i++) {
        if (num[i] <= k) ret = max(ret, dp[i]);
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define DEBUG(x) std::cout << '>' << #x << ':' << x << '\n';
#define PRINTVEC(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i] << ' '; std::cout << '\n';
#define PRINTPAIR(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i].first << ' ' << x[i].second << '\n'; std::cout << '\n';
#define PRINTSET(x) for (auto it = x.begin(); it != x.end(); it++) { std::cout << *it << ' '; } std::cout << '\n';
#define io std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);   
const int INF = 1<<29;
typedef long long ll;
using namespace std;


int main()
{
	io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);  
    #endif

    int s,w;
    cin >> s >> w;
    cout << (w >= s ? "unsafe" : "safe");

    #ifndef ONLINE_JUDGE   
    std::cout << '\n' << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    #endif
    return 0;
}


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

#define REP(i, a) for(int i=0; i<(int)(a); i++)
#define REP1(i, a, b) for(int i=(int)(a); i<=(int)(b); i++)
typedef long long LL;

const int MAX_N = 105, MAX_V = 100005, MAX_W = 1e9+7;
int n, W;
int v[MAX_N], w[MAX_N];
LL dp[MAX_V];
void input() {
    scanf("%d %d", &n, &W);
    REP(i, n) {
        scanf("%d %d", &w[i], &v[i]);
    }
}

void solve() {
    REP(i, MAX_V) dp[i] = MAX_W;
    dp[0] = 0;
    REP(i, n) {
        for(int j=MAX_V; j>=v[i]; j--) {
            dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
        }
    }

    for(int i = MAX_V-1; i >= 0; i--) {
        if(dp[i] <= W) {
            printf("%d\n", i);
            break;
        } 
    }
}

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

Measured memory_bytes: 1024
def main():
    n = list(map(int, list(input())))

    seqCount = 0
    for i in range(3):
        if seqCount == 2:
            break
        if n[i] == n[i+1]:
            seqCount += 1
        else:
            seqCount = 0

    if seqCount >= 2:
        ans = 'Yes'
    else:
        ans = 'No'

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define turbo(){	\
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL); \
}
using namespace std;
typedef long long ll;
int main()
{
	turbo();
	int i,n,x=0,mx=0;
	string s;
	cin>>n;
	cin>>s;
	for(i=0;i<n;i++){
		if(s[i]=='I'){
			x++;
		}
		else{
			x--;
		}
		mx=max(x,mx);
	}
	cout<<mx<<endl;
	return 0;	
}


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

using namespace std;

int main() {
  int n, q;
  string str;
  cin >> n >> q >> str;
  vector<int> vec(n, 0);
  for (int i = 1; i < n; ++i)
    vec[i] = vec[i-1] + (str[i-1] == 'A' && str[i] == 'C');
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << vec[r-1] - vec[l-1] << endl;
  }
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	ll k,tom;
	cin >> k;
	pdqueue pq;
	for (ll i = 1; i <= 9; i++)
	{
		pq.push(i);
	}
	while(k--)
	{
		tom = pq.top();
		pq.pop();
		if(pq.size() > 100000)
		{
			continue;
		}
		string x = to_string(tom);

		int n = x.size();

		if (x[n-1]-'0' == 9)
		{
			pq.push(stoll(x + "8"));
			pq.push(stoll(x + "9"));
		}
		else if (x[n-1]-'0' == 0)
		{
			pq.push(stoll(x + "1"));
			pq.push(stoll(x + "0"));
		}
		else 
		{
			int value = x[n-1]-'0';
			pq.push(stoll(x + to_string(value-1)));
			pq.push(stoll(x + to_string(value)));
			pq.push(stoll(x + to_string(value+1)));
		}
	}
	cout << tom << endl;
	return 0;
}


Measured memory_bytes: 1400
'''
C[n-k+1,i]*C[k-1,i-1](=F(i)とおく)
F(1)=n-k+1
また
C[n,r+1]/C[n,r]=(n-r)/(r+1)
より
F(i+1)/F(i)=(k-i)*(n-k+1-i)/i(i+1)
'''
N, K = [int(_) for _ in input().split()]
mod = 10**9 + 7
a = N - K + 1
print(a % mod)
for i in range(1, K):
    a = a * (K - i) * (N - K + 1 - i) // i // (i + 1)
    print(a % mod)


Measured memory_bytes: 3316
/*
 Shahadat Hossain
 I.C.T Department
 Comilla University
 Session: 2013-2014
 */

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define UNIQUE(x)       x.erase(unique(all(x)), x.end())

#define fs              first
#define sc              second
#define pb              push_back

#define sz(x)           (int)x.size()
#define all(v)          v.begin(),v.end()
#define D(x)            cerr << #x " = " << x << '\n'
#define ms(a,b)         memset(a, b, sizeof(a))
#define valid(x,y,n, m)      x>=0 && y>=0 && x<n && y<m

#define input           freopen("/Users/shahadat/Desktop/input.txt", "r", stdin)
#define output          freopen("/Users/shahadat/Desktop/output.txt", "w", stdout)

#define endl            '\n'
#define eps             1e-5
#define yes             printf("YES\n")
#define no              printf("NO\n")

#define int             long long

inline void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
inline int Set(int n,int pos) { return n = n | (1 << pos); }
inline int Reset(int n,int pos) { return n = n & ~(1 << pos); }
inline bool Check(int n,int pos) { return (bool)(n & (1 << pos)); }
inline int Count(ll n) { return __builtin_popcountll(n); }

typedef pair<int,int> pint;
int const N = 2e3 + 10;
int const MOD = 1e9 + 7;

int cas = 1;
pint dp[20][2];
int cnt[2][20];

void solve(){
    string s, t;
    cin >> s >> t;
    
    vector<int> store[26];
    for(int i = 0; i < s.size(); i++){
        int idx = s[i] - 'a';
        store[idx].pb(i);
    }
    
    int res = 0;
    int last = -1;
    for(auto c: t){
        int idx = c - 'a';
        if(store[idx].size() == 0){
            cout << -1 << endl;
            return;
        }
        int pos = upper_bound(all(store[idx]), last) - store[idx].begin();
        if(pos == store[idx].size()){
            res += s.size();
            last = store[idx].front();
        }
        else{
            last = store[idx][pos];
        }
    }
    res += last + 1;
    cout << res << endl;
}


int32_t main(){
    solve();
}

Measured memory_bytes: 1724