akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        String s = sc.next();
        String t = sc.next();
        int n = s.length(); int m = t.length();
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i <= n - m; i++) {
            int ct = 0;
            for (int j = i; j <= i + m - 1; j++) {
                if (s.charAt(j) != t.charAt(j - i)) ct++;
            }
            ans = Math.min(ans, ct);
        }
        out.println(ans);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 32952
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin>>n;
    ll ans = 0;
    for(ll i=1;i<=n;i++)
    {
        if(i%3 && i%5)
            ans += i;
    }
    cout<<ans;
}


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

using namespace std;
#define INFS (1LL<<28)
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
#define double long double



int a[200];

int min(int a,int b){
	if(a>b)return b;
	return a;
}

signed main(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int ans=0;
	lp(i,n){
		if(i!=0){
			if(s[i]=='L'&&s[i-1]=='L')ans++;
		}		
		if(i!=n-1){
			if(s[i]=='R'&&s[i+1]=='R')ans++;
		}
	}
	int act=0;
	char c=s[0];
	int rei=-1;
	if(s[0]!=s[n-1]){
		for(int i=n-1;i>0;i--){
			if(s[i]!=s[i-1]){
				rei=i;
				break;
			}
		}
	}
	lp(i,n){
		if(i==0)continue;
		if(s[i]!=c&&s[i-1]==c){
			if(i==rei)ans--;
			ans+=2;
			k--;
		}
		if(k==0)break;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int tmp = N;
  int sum = 0;
  while (true)
  {
    sum = sum + N % 10;
    N = N / 10;
    if(N==0){
      break;
    }
  }

  if (tmp % sum == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

using State = string::const_iterator;

const int n = 11;
int val[n];

bool equation(State &itr);
int formula(State &itr);
int factor(State &itr);
int variable(State &itr);

void next_char(State &itr, char expected){
    if(*itr == expected){
        itr++;
    }
    else{
        cout << "Error: expected " << expected << " but " << *itr << endl;
        while(*itr){
            cout << *itr;
            itr++;
        }
        cout << endl;
    }
}

bool equation(State &itr){
    int lhs, rhs;
    lhs = formula(itr);
    next_char(itr, '=');
    rhs = formula(itr);
    return lhs == rhs;
}

int formula(State &itr){
    if(isalpha(*itr)){
        return variable(itr);
    }else if(*itr == '-'){
        next_char(itr, '-');
        return !formula(itr);
    }else{
        next_char(itr, '(');
        int x = formula(itr);
        if(*itr == '*'){
            next_char(itr,'*');
            x &= formula(itr);
        }else if(*itr == '+'){
            next_char(itr,'+');
             x |= formula(itr);
        }else if(*itr == '-'){
            next_char(itr,'-');
            next_char(itr,'>');
            x = (!x | (x & formula(itr)));
        }else{
            // error
            return -1;
        }
        next_char(itr, ')');
        return x;
    }
}

int variable(State &itr){
    int res = -1;
    if(isalpha(*itr)){
        if(*itr == 'T') res = 1;
        else if(*itr == 'F') res = 0;
        else res = val[*itr-'a'];
    }else{
        // error
    }
    itr++;
    return res;
}

int solve(){
    string s;
    getline(cin, s);
    if(s == "#") return 1;
    bool ok = true;
    for(int S=0;S<1<<n;S++){
        for(int i=0;i<n;i++){
            val[i] = (S>>i)&1;
        }
        State begin = s.begin();
        ok &= equation(begin);
        if(!ok)break;
    }
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}

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



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(ll i=0;i<n;i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define vec_input(A) for(auto &a : A) cin >> a;
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;


void run_case(){
	// ll i , j , k , ans , x , y ,z , l , m , n;
	ll ans,current = 0;
	ans = 0;
	vector<char> A(3);
	vec_input(A);

	for(auto a : A){
		if(a == 'R') current++;
		else current=0;
		if(current  > ans ) ans = current;

	}
	cout << ans;
	
}


int main() {

	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	#ifndef ONLINE_JUDGE
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
    freopen("error", "w", stderr);
	#endif

	
	

	int t = 1;
	// cin >> t;
	while(t--) 
	{
		run_case();



	}

	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define all(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  int a, b, c ;
  char s, t ;
  cin >> a >> s >> b >> t >> c ;
  if(b<=4){
    cout <<"Heisei"<<endl ;
  }
  else{
    cout <<"TBD"<<endl ;
  }
    return 0 ;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  string s; cin >> s;
  string ans = "";
  for (char c : s) {
    if (c == 'B') {
      if (!ans.empty()) ans.pop_back();
    } else {
      ans += c;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int p = Integer.parseInt(str[1]);
    System.out.println((a*3+p)/2);
  }
}

Measured memory_bytes: 21204
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	int n,k,t,p;
	cin>>n>>k;
	ll s=0;
	for0(i,n){
		cin>>p;
		int t = abs(k-p);
		s += min(p,t);
		}
		
	cout<<2*s<<nw;
	
	return 0;
}

Measured memory_bytes: 256
# ABC138E - Strings of Impurity
import sys
input = sys.stdin.readline

from bisect import bisect_left as bs
from collections import defaultdict


def main():
    S = input().rstrip()
    T = input().rstrip()
    # idx[c] := indices at which character c appears in S
    idx, ls = defaultdict(list), len(S)
    for i, s in enumerate(S):
        idx[s] += [i]
    roop, cur = 0, -1
    for t in T:  # binary search to find t's index > cur
        tgt = idx[t]  # sorted list of indices of t
        if tgt == []:  # t not in S
            print(-1)
            return
        x = bs(tgt, cur + 1)
        if x < len(tgt):  # find in current roop
            cur = tgt[x]
        else:  # move to next roop and pick up the first one
            cur = tgt[0]
            roop += 1
    print(roop * ls + cur + 1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 8052
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
#include <array>
#include <string>
#include <map>
using namespace std;

#define DB(x)

/*
int getIntSp(){
    string str;
    getline(cin,str,' ');
    return stoi(str);
}

int getIntLF(){
    string str;
    getline(cin,str);
    return stoi(str);
}
 */


int main() {
    string S;
    cin >> S;
    
    int count = 0;
    for( int i = 0; i < S.size() / 2; ++i )
    {
        if( S[i] != S[S.size()-i-1] ){
            count++;
        }
    }
    cout << count << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int cmap[10][10] = {0};

int main()
{
    int h, w, k;
    cin >> h >> w >> k;

    rep(i, h){
        string t; cin >> t;
        rep(j, w){
            if (t[j] == '#') cmap[i][j] = 1;
        }
    }

    // rep(i, h){
    //     rep(j, w){
    //         cout<< cmap[i][j];
    //     }
    //     cout << endl;
    // }

    int bit = h+w;
    //2^12
    int ans = 0;
    rep(i, (1<<bit)){
        set<int> hr, wr;
        for (int j = 0; j < bit; j++)
        {
            if ((i>>j)&1){
                if (j < h){
                    hr.insert(j);
                } else {
                    wr.insert(j-h);
                }
            }
        }
        int tmp = 0;
        rep(ih, h)rep(iw, w){
            if (cmap[ih][iw] == 1){
                if (hr.find(ih) == hr.end() && wr.find(iw) == wr.end()){
                    //cout << ih << iw << endl;
                    tmp++;                    
                }
            }
        }
        if (tmp == k) {
           // cout << i << endl;
            ans++;
        }
    }

    cout << ans << endl;


}



Measured memory_bytes: 3648
#include <iostream>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <cstdio>
#include <math.h>
#include <map>
#include <algorithm>
#include <deque>
#include <stack>
#include<set>
//#include <bits/stdc++.h>
#define lson l,mid,rt<<1

#define rson mid+1,r,rt<<1|1

const int N=1e5+100;
using namespace std;

typedef long long ll;
const int inf=0x3f3f3f3f;
ll dp[150000];
//ll a[200];
int main()
{
    int n,W;scanf("%d%d",&n,&W);
    memset(dp,0x3f,sizeof dp);
    ll w,v;
    dp[0]=0;
    ll ans=0;
    for(int i=1;i<=n;i++){
            scanf("%lld%lld",&w,&v);
        for(int j=1e5;j>=v;j--){
         dp[j]=min(dp[j],dp[j-v]+w);
         if(dp[j]<=W)
            ans=max(ans,1ll*j);
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1408
import java.util.*;
public class Main {
    static Node[] set;
    static public class Node{
        int id;
        int parent;
        public Node(int n){
            id = n;
            parent = n;
        }
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int q = scan.nextInt();
        set = new Node[n];
        for(int i = 0; i < n; i++){
            set[i] = new Node(i);
        }
        // 0 = unite 1 = same
        for(int i = 0; i < q; i++){
            int func = scan.nextInt();
            int n1 = scan.nextInt();
            int n2 = scan.nextInt();
            if(func == 0){
                int newP = set[n1].parent;
                int changeP = set[n2].parent;
                update(newP, changeP);
            }
            else{
               if(set[n1].parent == set[n2].parent){
                   System.out.println(1);
               }
               else{
                   System.out.println(0);
               }
            }
        }

    }
   static public void update(int np, int op){
        for (int i = 0; i < set.length;i++){
            if(set[i].parent == op){
                set[i].parent = np;
            }
        }
    }
}


Measured memory_bytes: 70092
# Code for C - Skill Up
# Use input() to fetch data from STDIN
from itertools import chain, combinations

def powerset(iterable):
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

[n, m, X] = map(int, input().split())
c = [0 for x in range(n)]
a = [[0 for x in range(m)] for y in range(n)]

for i in range(n):
    row = list(map(int, input().split()))
    c[i] = row[0]
    a[i] = row[1:]

costs = []
for s in powerset(range(n)):
    cost = 0
    t = [0 for x in range(m)]
    for x in s:
        cost += c[x]
        for y in range(m):
            t[y] += a[x][y]
    if all(map(lambda x: x >= X, t)):
        costs.append(cost)

if (len(costs) == 0):
    print(-1)
else:
    print(min(costs))


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

char mcxi[4] = { 'i','x','c','m' };

int decode(string s);
string encode(int n);

int main() {
	int sum, n; cin >> n;
	while (n--) {
		string s1, s2; cin >> s1 >> s2;
		sum = decode(s1) + decode(s2);
		cout << encode(sum) << endl;
	}
	return 0;
}

int decode(string s) {
	int sum = 0;
	rep(i, (int)s.size()) {
		int coe = 1;
		if (1 < s[i] - '0'&&s[i] - '0' <= 9) coe = s[i++] - '0';
		rep(j, 4) {
			if (s[i] == mcxi[j]) {
				sum += coe*(int)pow(10.0, j);
				break;
			}
		}
	}
	return sum;
}

string encode(int n) {
	string s;
	int tmp;
	for (int i = 3; i >= 0; i--) {
		tmp = (int)(n / pow(10.0, i));
		if (tmp > 1) {
			s.push_back(tmp + '0');
			s.push_back(mcxi[i]);
			n -= (int)(tmp*(pow(10.0, i)));
		}
		else if (tmp == 1) {
			s.push_back(mcxi[i]);
			n -= (int)(pow(10.0, i));
		}
	}
	return s;
}

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

int main() {
  int H, N, sum = 0;

  cin >> H >> N;

  vector<int> vec(N);

  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }

  if (sum >= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 640
n = int(input())
kouho = []
alphabet = []
for i in range(26):
    alphabet.append(chr(ord("a") + i))
ans = []
while n > 0:
    p = (n) % 26
    q = n // 26
    if p == 0:
        p += 26
        q -= 1
    ans.append(alphabet[p - 1])
    n = q

print(*ans[::-1], sep="")


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

int main(){
    int h, w, i, j, k;
    for(i = 0; ;i++){
        scanf("%d %d", &h, &w);
        if(h == 0 && w == 0) break;
        for(j = 0;j < h;j++){
            for(k = 0;k < w;k++) cout << "#";
            cout<<endl;
        }
        cout << endl;
    }
}


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

#define INF 1000000007

int main(){
    int n, limit;
    std::cin >> n >> limit;

    std::vector<int> value(n), weight(n);
    for(int i = 0; i < n; ++i){
        std::cin >> value.at(i) >> weight.at(i);
    }

    std::vector<std::vector<int>> dp(n + 1, std::vector<int>(limit + 1, 0));
    for(int i = 0; i < n; ++i){
        for(int w = 0; w <= limit; ++w){
            if(weight.at(i) <= w){
                dp.at(i + 1).at(w) += std::max(dp.at(i).at(w - weight.at(i)) + value.at(i), dp.at(i).at(w));
            }else{
                dp.at(i + 1).at(w) = dp.at(i).at(w);
            }
        }
    }

    std::cout << dp.at(n).at(limit) << std::endl;

    return 0;
}


Measured memory_bytes: 6772
#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>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
#define FOR(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

int p[1000010];

int main(){
	p[0]=p[1]=1;
	rep(i,1000000){
		if(p[i]==0)
			for(int j=2*i;j<1000000;j+=i)
				p[j]=1;
	}
	int n;
	for(;cin>>n;){
	int r=0;
	rep(i,n+1)
	if(p[i]==0)r++;
	cout<<r<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7,dp[1000][1000];
int h,w;
char c[1001][1001];
int main(){
    cin >> h >> w;
    for(int i = 0;i < h;i ++){
        for(int j = 0;j < w;j ++){
            cin >> c[i][j];
        }
    }
    int i=0,j=0;
    while(c[i][0]=='.'){dp[i][0]=1;i++;}
    while(c[0][j]=='.'){dp[0][j]=1;j++;}
    for(i = 1;i < h;i ++){
        for(j = 1;j < w;j ++){
            if(c[i-1][j]=='.')dp[i][j] += dp[i-1][j];
            if(c[i][j-1]=='.')dp[i][j] += dp[i][j-1];
            dp[i][j] = dp[i][j]%mod;
        }
    }
    cout << dp[h-1][w-1] << endl;
    return 0;
}

Measured memory_bytes: 9088
#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 int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    string s;
    cin >> s;
    string a[] = {"Sunny","Cloudy", "Rainy"};
    rep(i, 3) {
        if(a[i] == s) {
            cout << a[(i+1)%3] << '\n';
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
      int N, T, A, min_i=1;
	  cin >> N >> T >> A;
  	  
      int H[N];
  	  for(int i=0;i<N;i++){
        cin >> H[i];
      }
  

      int min = abs(A*1000-T*1000+H[0]*6);

	  for(int i=0; i<N; i++){
        if(min > abs(A*1000-T*1000+H[i]*6)){
          min = abs(A*1000-T*1000+H[i]*6);
          min_i = i+1;
        }
      }
     
  	  cout << min_i <<endl;

    }
        

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use std::cmp::*;
use std::collections::*;
use std::fs::File;
use std::io::prelude::*;
use std::io::*;
use std::vec;

const INF: i64 = 1223372036854775807;
const MEM_SIZE: usize = 202020;
const MOD: i64 = 1000000007;
use std::cmp::*;
use std::collections::*;
use std::io::stdin;
use std::io::stdout;
use std::io::Write;
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(dead_code)]
fn readii() -> (i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}
#[allow(dead_code)]
fn readuu() -> (usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

#[allow(dead_code)]
fn readuuu() -> (usize, usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn solve() {
    let (n, k) = readuu();
    let m = (n) * (n - 1) / 2 - (n - 1);
    if (k > m) {
        println!("-1");
        return;
    }
    println!("{:?}", n - 1 + m - k);
    for i in 0..n - 1 {
        println!("{} {}", 1, i + 2);
    }
    let mut data: Vec<(usize, usize)> = vec![(0, 0); 0];
    for i in 1..n {
        for j in i + 1..n {
            data.push((i + 1, j + 1));
        }
    }
    data.sort();
    for i in 0..(m - k) {
        println!("{} {} ", data[i].0, data[i].1);
    }

    return;
}
fn main() {
    solve()
}


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

int main(){
    int n,ans=1;
    cin >> n;
    for(int i=1;i<=n;i++){
        if(i*(i+1)/2>=n){
            ans=i;
            break;
        }
    }
    cout << ans << endl;
    n-=ans;
    for(int i=ans-1;i>0;i--){
        if(n==0){break;}
        if(n>=i){
            cout << i << endl;
            n-=i;
        }
    }
}

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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;
const int INF = 1e9 + 5;

signed main() {
    FAST_IO;

    int n, k;
    cin >> n >> k;
    vector<int> stones(n);
    for (int i = 0; i < n; i++) cin >> stones[i];

    vector<int> dp(n, INF); // dp[i] : Minimum cost to reach stone i.
    dp[0] = 0; // Base case, we start on the first stone so cost to reach it is 0.

    for (int i = 0; i < n; i++) { // i represents the stone the frog is currently at.
        for (int j = i + 1; j <= i + k; j++) { // j represents a potential stone for the frog to jump to.
            if (j < n)
                // Storing the total minimum cost to reach stone j from stone i.
                dp[j] = min(dp[j], dp[i] + abs(stones[j] - stones[i]));
        }
    }
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 3996
#include <bits/stdc++.h>
//#include <cmath>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
//#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define bs(yup,x) binary_search(yup.begin(),yup.end(),x) //it will return bollean value
#define lb(yup,x) lower_bound(yup.begin(),yup.end(),x)  //it will return the adress of the number which is equal to or just greater than x ,and if it is equal to yup.end() than their in no such number exist
#define ub(yup,x) upper_bound(yup.begin(),yup.end(),x)
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
using namespace std;
const long long N=200005, INF=2000000000000000000;
const long double EPS= 0.000000000001;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
vi prime;
bool isprime[N];
void pre()
{
    for(int i=2;i<N;i++)
    {
        if(isprime[i])
        {
            for(int j=i*i;j<N;j+=i)
            isprime[j]=false;
            prime.pb(i);
        }
    }
    return;
}
 
 
class yup 
{ 
 public : int gcd(int a, int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 }  
  int lcm(int a, int b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
} ;
int minCoins(int coins[], int m, int V) 
{ 
   // base case 
   if (V == 0) return 0; 
  
   // Initialize result 
   int res = INT_MAX; 
  
   // Try every coin that has smaller value than V 
   for (int i=0; i<m; i++) 
   { 
     if (coins[i] <= V) 
     { 
         int sub_res = minCoins(coins, m, V-coins[i]); 
  
         // Check for INT_MAX to avoid overflow and see if 
         // result can minimized 
         if (sub_res != INT_MAX && sub_res + 1 < res) 
            res = sub_res + 1; 
     } 
   } 
   return res; 
} 
bool com(int a,int b)
{
    return a>b;
 
}
int ans=0;
class gfg 
{ 
  
public: 
unsigned int getFirstSetBitPos(int n) 
{ 
    return log2(n & -n) + 1; 
} 
}; 
    
int32_t main()
{
    
    IOS;
    //fill(isprime, true);
    //pre();
    int t=1;
    //cin>>t;
    while(t--)
    {
        int d,t,s;
        cin>>d>>t>>s;
        if(s*t>=d)
        {
            cout<<"Yes\n";
        }
        else cout<<"No\n";
    }
 
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n,k,c;
const int Maxn=2e5+5;
char s[Maxn];
bool B[Maxn];
vector<int>v;
int main(){
	scanf("%d%d%d%s",&n,&k,&c,s+1);
	int p=1;
	while(p<=n){
		while(s[p]=='x')p++;
		v.push_back(p);p+=c+1;
	}
	if(SZ(v)>k)return 0;
	zero(B);
	rep(i,SZ(v))B[v[i]]=true;
	v.clear();
	p=n;
	rep(t,k){
		while(s[p]=='x')p--;
		v.push_back(p);p-=c+1;
	}
	reverse(all(v));
	rep(i,SZ(v)){
		if(B[v[i]]){
			printf("%d\n",v[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 2804
#include <stdio.h>
int main(void)
{
  int a,s,d,f,z,x,c,v,i,j;
  scanf("%d %d %d %d",&a,&s,&d,&f);
  scanf("%d %d %d %d",&z,&x,&c,&v);
  i=a+s+d+f;
  j=z+x+c+v;
  printf("%d\n",(i>j)?i:j);
  return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

const ll MOD = 1000000007;
int n,k;
vector<int> to[100100];
ll ans=1;

void input(){
    cin >> n >> k;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
}
void dfs(int x,int pa, int num){
    ans *= num % MOD;
    ans %= MOD;
    num = k-1;
    if(pa!=-1) num--;
    for(auto u:to[x]){
        if(u!=pa){
            dfs(u,x,num);
            num--;
        }
    }
}
int main(){
    input();
    dfs(0,-1,k);
    cout << ans;
}







Measured memory_bytes: 9216
import itertools
from operator import add

n, m, x = map(int, input().split())
C = [[]] * (n + 1)
ans = -1

for i in range(1, n + 1):
    C[i] = list(map(int, input().split()))
for i in range(1, n + 1):
    pares = list(itertools.combinations(range(1, n + 1), i))
    for pare in pares:
        A = [0] * (m + 1)
        for el in pare:
            A = list(map(add, A, C[el]))
        flag = True
        for a in A[1:]:
            if not a >= x:
                flag = False
                break
        if flag:
            if A[0] < ans or ans == -1:
                ans = A[0]
print(ans)


Measured memory_bytes: 68640
#include <stdio.h>

int main() {
	int i, j;
	char c[4][4];

	for (i = 0; i < 3; i++) {
		scanf("%s", &c[i][0]);
	}

	printf("%c%c%c\n", c[0][0], c[1][1], c[2][2]);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int R,C,N;
struct node{
    int u;
    int v;
    int flag;
}no[200005];
bool cmp(node a,node b)
{
    return a.u < b.u;
}
int Change(int x, int y)
{
    if (x == 0)
        return y;
    else if (y == C)
        return C + x;
    else if (x == R)
        return R + C + C - y;
    else if (y == 0)
        return R+R+C+C-x;
    else
        return -1;
}
int main()
{
    int cnt=0;
    scanf("%d%d%d",&R,&C,&N);
    for(int i=0;i<N;i++)
    {
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        int flag1=Change(a,b);
        int flag2=Change(c,d);
        if(flag1 == -1 || flag2 == -1)
            continue;
        if(flag1 > flag2)
            swap(flag1,flag2);
        no[cnt].flag=1;
        no[cnt].u=flag1;
        no[cnt++].v=flag2;
        no[cnt].flag=2;
        no[cnt].u=flag2;
        no[cnt++].v=flag1;
    }
    stack<int>S;
    sort(no,no+cnt,cmp);
    for(int i=0;i<cnt;i++)
    {
        if(no[i].flag==1)
            S.push(no[i].v);
        else if(S.top()==no[i].u)
            S.pop();
        else
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}

Measured memory_bytes: 2816
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X = int(input())
ans = 0

ans += X // 500 * 1000
ans += (X % 500) // 5 * 5
print(ans)

Measured memory_bytes: 5456
def solve():
    size = int(input())
    array = list(map(int, input().split()))
    SelectionSort(array, size)


def SelectionSort(array, size):
    swap_count = 0
    for i in range(0, size, 1):
        minj = i
        for j in range(i, size, 1):
            if array[j] < array[minj]:
                minj = j
        if array[i] is not array[minj]:
            array[i], array[minj] = array[minj], array[i]
            swap_count += 1
    print(' '.join(map(str, array)))
    print(swap_count)


if __name__ == '__main__':
    solve()



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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100001

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

    ll n;
    cin>>n;
    pll job[n];
    loop(i,0,n){
        cin>>job[i].se>>job[i].fi;
    }
    sort(job, job+n);
    bool b=1;
    ll t = 0;
    for(ll i=0; i<n; i++){
        t = t+job[i].se;
        if(t > job[i].fi){
            b = 0;
            break;
        }
    }
    if(b==1) print("Yes");
    else print("No");
        
   
}



Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
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; }

ll dp[100010];

int main() {

    double W, H;
    double x, y;
    cin >> W >> H >> x >> y;

    double a = min((W-x)*H, x*H);
    double b = min((H-y)*W, y*W);

    double c = max(a,b);

    if(a == 0 && b == 0) {
        c = W*H / 2;
        
        printf("%.15f", c);
        printf(" ");
        printf("0");
        return 0;
    }
    if(c < W*H / 2) {
        c = W*H / 2;
        
        printf("%.15f", c);
        printf(" ");
        printf("0");
        return 0;
    }
    

    if(a == b)
        {printf("%.15f", c);
        printf(" ");
        printf("1");}

    else
        {printf("%.15f", c);
        printf(" ");
        printf("0");
        }


    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <cassert>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

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

bool dividable(P a, P b){
	int d = b.first*b.first + b.second*b.second;
	int x = a.first*b.first + a.second*b.second;
	int y = -a.first*b.second + a.second*b.first;
	if (!d || x%d || y%d) return false;

	return true;
}

int main(){
	vector<P> ginkgo;
	for (int i = -150; i <= 150; ++i){
		for (int j = -150; j <= 150; ++j){
			if (i*i + j*j < 20000) ginkgo.push_back(MP(i, j));
		}
	}

	int n;
	cin >> n;
	while (n--){
		int m, n;
		cin >> m >> n;
		P mn = MP(m, n);
		int cnt = 0;
		for (auto p : ginkgo){
			cnt += dividable(mn, p);
		}
		cout << (cnt == 8 ? 'P' : 'C') << endl;
	}

	return 0;
}

Measured memory_bytes: 1692
from sys import stdin
import numpy as np
from numba import njit, i8
n, k = map(int, stdin.readline().split())
a = np.array(stdin.readline().split(), dtype = np.int64)

@njit(cache=True)
def c(x, a):
    res = 0
    for i in range(n):
        res += 0 - - a[i] // x - 1
    return res <= k

ng = 0
ok = 10 ** 9 + 1
while ok - ng > 1:
    mid = (ok + ng) >> 1
    if c(mid, a):
        ok = mid
    else:
        ng = mid
print(ok)


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

int main(){

  int n;
  while(cin >> n, n){
    int w, h, x, y, s, t;
    cin >> w >> h;
    bool a[101][101] = {false};
    for(int i = 0; i < n; i++){
      cin >> x >> y;
      a[y-1][x-1] = true;
    }
    cin >> s >> t;
    int sum = 0;
    for(int i = 0; i < h-t+1; i++){
      for(int j = 0; j < w-s+1; j++){
        int tmp = 0;
        for(int l = 0; l < t; l++){
          for(int k = 0; k < s; k++){
            if(a[i+l][j+k]) tmp++;
          }
        }
        sum = max(tmp, sum);
      }
    }
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(auto i=(a);i<(b);i++)
#define per(i,a,b) for(auto i=(a);i>=(b);i--)
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x)&(-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eps 1e-8
#define all(v) (v.begin(),v.end())
#define db double
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const double pi=acos(-1.0);
const double inf = 1e100;
template<class T>
inline T read()
{
	T x=0,f=1;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-')f=-1;s=getchar();};
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();};
	return x*f;
}
template<typename T>
inline void wri(T x)
{
	if(x<0){x=-x;putchar('-');};
	if(x/10) wri(x/10);
	putchar(x%10+48);
}
template<typename T>
inline void print(T x,char s)
{
	wri(x);
	putchar(s);
}
template<typename T>
T gcd(T a,T b)
{
	return b==0?a:gcd(b,a%b);
}
//关闭流同步就不能手写读入优化啦
int a[200010];
int n;
bool cmp(int a,int b){
	return a>b;
} 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n;
    rep(i,1,n+1) cin>>a[i];
    sort(a+1,a+1+n,cmp);
   ll ans=0;
    int cnt=n-1;
    if(cnt){
    	ans+=a[1];
	    cnt--;
		int pos=2;
		while(cnt){
			ans+=a[pos];
			cnt--;
			if(!cnt) break;
			ans+=a[pos];
			cnt--;
			pos++;
		}
	}
	cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
int main(){
	while(1){
		int n; string s; cin >> n; if(n==0) return 0; cin >> s;
		int dp[(1<<10)+5]={};
		int cur = 0;
		for(int i=0;i<n;i++){
			if(s[i] == 'u'){
				cur = 0;
			}
			else{
				dp[cur] |= (1<<(s[i]-'0')); //cout << cur << " " << (1<<(s[i]-'0'));
				cur |= (1<<(s[i]-'0'));
			}
		}
		int dp2[(1<<10)+5]={};
		for(int i=0;i<(1<<10);i++){
		        dp2[i] = dp[i];
		        //if(i<8) cout << i <<" " << dp[i] <<  endl;
		}
		for(int R=0;R<9;R++){
			for(int i=0;i<(1<<10);i++){
				for(int j=0;j<(1<<10);j++){
					if( (i&j) != j ) continue;
					if(!dp2[i-j] || !dp[j]) continue;
					dp2[i] |= dp2[i-j];
					dp2[i] |= dp[j];
				}
			}
		}
		for(int i=0;i<(1<<10);i++){
			if( dp2[i] != 0 && (dp2[i]&i) == dp2[i] ){
			    //if(n==8) cout << i << " " << dp2[i] << endl;
				puts("UNSAFE"); goto ok;
			}
		}
		puts("SAFE"); ok:;
	}
}

Measured memory_bytes: 3144
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,s,a[MAXN],b[MAXN];
map<int,int> mpa,mpb;
map<int,int> mp;
vector<int> G[MAXN];
int dfn[MAXN],low[MAXN],st[MAXN];
int vis[MAXN];
int cmp[MAXN],cnt,tot,t,V;
void add_vertex(int v)
{
    if(!mp[v])mp[v]=++V;
}
void add_edge(int u,int v)
{
    G[mp[u]].push_back(mp[v]);
    G[mp[v]].push_back(mp[u]);
}
void dfs(int v)
{
    dfn[v]=low[v]=++tot;
    vis[v]=1;
    st[t++]=v;
    for(auto to:G[v])
    {
        if(!vis[to])
        {
            dfs(to);
            low[v]=min(low[v],low[to]);
        }
        else if(vis[to]==1) low[v]=min(low[v],dfn[to]);
    }
    if(dfn[v]==low[v])
    {
        int u;
        do
        {
            u=st[t-1]; t--;
            cmp[u]=cnt;
            vis[u]=2;
        }while(u!=v);
        cnt++;
    }
}
int tarjan()
{
    t=tot=cnt=0;
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=V;i++) if(!dfn[i]) dfs(i);
    return cnt;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        s^=a[i];mpa[a[i]]++;
    }
    mpa[s]++;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
        mpb[b[i]]++;
    }
    int id=-1;
    for(auto p:mpb)
    {
        if(mpa[p.F]<mpb[p.F])
        {
            puts("-1");
            return 0;
        }
    }
    for(auto p:mpa) if(mpa[p.F]>mpb[p.F]) id=p.F;
    int cnt=0;
    for(int i=1;i<=n;i++) if(a[i]!=b[i]) cnt++;
    if(cnt==0) {puts("0"); return 0;} 
    else 
    {
        add_vertex(s);add_vertex(id);
        for(int i=1;i<=n;i++)
        {
            if(a[i]!=b[i])
            {
                add_vertex(a[i]);add_vertex(b[i]);
                add_edge(a[i],b[i]);
            }
        }
        printf("%d\n",tarjan()+cnt-1);
    }
    return 0;
}



Measured memory_bytes: 27136
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter

# import numpy as np
# import scipy as scp

# 入力の受け取り
h,w = map(int,input().split())

if h==1 or w == 1:
    ans = 1
elif h%2 == 0:
    ans = h//2 * w
# elif w%2 ==0:
    # ans = w//2 * h
else:
    w1 = w//2
    w2 = w-w1
    ans = ((h//2)*w1) + (((h+1)//2)*(w2))
    
print(ans)
# print("{:.10f}".format(ans))


Measured memory_bytes: 3060
n = int(input())
location = [list(map(int, input().split())) for _ in range(n)]

from itertools import permutations
import math
distance = []
for route in list(permutations(range(1,n+1))):
  route = list(route)

  dis = 0
  for i in range(0,n-1):
    d = math.sqrt(pow(location[route[i]-1][0]-location[route[i+1]-1][0],2) + pow(location[route[i]-1][1]-location[route[i+1]-1][1],2))
    dis = dis + d
  distance.append(dis)
  
ans = sum(distance)/len(list(permutations(range(1,n+1))))
print(ans)

Measured memory_bytes: 9252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	int n;
	cin>>n;
	string s;
	cin>>s;
	string t =s;
	ll cnt=0;
	for(int i=0;i<n;i++){
		char c= s[i];
		if(c=='('){
			cnt++;
		}
		else{
			cnt--;
		}
		if(cnt<0){
			t='('+t;
			cnt++;
		}
	}
	while(cnt>0){
		t=t+')';
		cnt--;
	}
	cout <<t;
}

Measured memory_bytes: 256
import math

count = 0

def calculate(y):
    i = 3
    if y==2:
        return y
    elif y<2 or y%2==0:
        return False
    while i<= math.sqrt(y):
        if y % i == 0:
            return False
        i += 2
    return y

x = int(input())
y = [int(input()) for _ in range(x)] #入力は縦だが、リストに格納される優れもの。

for l in y:
    if calculate(l)!=False:
        count += 1
print(count)


Measured memory_bytes: 6008
#include <iostream>

using namespace std;
 
int judge(int);
 
int main()
{
    int n, age;
 
    while (cin >> n, n) {
	int cnt[7] = {0};
	for (int i = 0; i < n; i++) {
	    cin >> age;
	    cnt[judge(age)]++;
	}
	for (int i = 0; i < 7; i++) {
	    cout << cnt[i] << endl;
	}
    }
    return 0;
}
 
int judge(int age)
{
    return min(age/10, 6);
}

Measured memory_bytes: 3000
import math as m1
n, h = map(int, input().split())
a, b = [], []
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)
b = list(reversed(sorted(b)))
m = max(a)
ans = 0
for i in b:
    if i > m:
        if h - i <= 0:
            print(ans + 1)
            exit()
        h -= i
        ans += 1
print(ans + m1.ceil(h / m))

Measured memory_bytes: 12572
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 998244353;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  ll K;
  cin >> S >> K;
  int N = S.size();
  int cnt = 0;
  vector<int> C;
  rep(i, N) {
    if(S[i] == '1') cnt++;
    else {
      C.push_back(cnt);
      cnt = 0;
    }
  }
  C.push_back(cnt);
  reverse(all(C));
  int n = C.size();
  int m = accumulate(all(C), 0);
  vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(m+1, vector<ll>(m+1)));
  dp[0][0][0] = 1;
  rep(i, n) { // i番目の区間
    rep(j, m+1) { // 取り出した回数
      if(j > K) continue;
      rep(k, m+1) { // 挿入した回数
        int rem = j-k;
        if(rem < 0) continue;
        rep(l, rem+1) { // ここで挿入する回数
          (dp[i+1][j][k+l] += dp[i][j][k]) %= mod;
        }
        rep(l, C[i]+1) { // ここで取り出す回数
          if(j+l > m) continue;
          if(l == 0) continue;
          (dp[i+1][j+l][k] += dp[i][j][k]) %= mod;
        }
      }
    }
  }
  ll ans = 0;
  rep(i, min(K+1, (ll)m+1)) (ans += dp[n][i][i]) %= mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 35620
import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

class Main {
	static final String YES = "YES";
	static final String NO = "NO";

	public static void main(String[] args) {
		Scanner sc = null;
		try {
			sc = new Scanner(System.in);
			int countDataset = sc.nextInt();
			int[] ballNums = new int[10];

			for (int i = 0; i < countDataset; i++) {
				for (int j = 0; j < 10; j++) {
					ballNums[j] = sc.nextInt();
				}

				System.out.println(push(ballNums) ? YES : NO);
			}
		} finally {
			sc.close();
		}
	}

	public static boolean push(int[] nums) {
		Deque<Integer> list1 = new LinkedList<Integer>();
		Deque<Integer> list2 = new LinkedList<Integer>();
		list1.add(0);
		list2.add(0);
		for (int number : nums) {
			if (list1.peek() < number) {
				list1.push(number);
			} else if (list2.peek() < number) {
				list2.push(number);
			} else {
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 26304
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main()
{
	int n;cin>>n;
	string s;cin>>s;
	int t=0;
	for(int i=0;i<n;)
	{
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
		{
			t++;
			i+=3;
		}
		else i++;
	}
	printf("%d\n",t);
}

Measured memory_bytes: 3728