akhauriyash/Code-Regression huggingface dataset:
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-18 17:59:52
*/

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

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    int bi, te;
    bi = te = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] % 4 == 0) {
            te++;
        } else if (a[i] % 2 == 0) {
            bi++;
        }
    }

    int ok = 0;
    if (n % 2 == 0 && te >= n/2) ok = 1;
    if (n % 2 > 0 && te >= (n-1)/2) ok = 1;

    if (2*te + bi - n >= 0) ok = 1;

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int n,m;
    cin >> n >> m;
    vector<map<ll,ll>> mana(n+1);
    vector<vector<ll>> data(n);
    vector<pair<ll,ll>> raw(m);
    rep(i,m){
        ll p,y;
        cin >> p >> y;
        mana[p][y] = 0;
        data[p-1].push_back(y);
        raw[i] = make_pair(p,y);
    }
    rep(i,n)sort(data[i].begin(),data[i].end());
    rep(i,n){
        rep(j,data[i].size()){
            mana[i+1][data[i][j]] = j+1;
        }
    }
    rep(i,m){
        string p = string(6 - (ll)to_string(raw[i].first).length(),'0') + to_string(raw[i].first);
        string y = string(6 - (ll)to_string(mana[raw[i].first][raw[i].second]).length(),'0') + to_string(mana[raw[i].first][raw[i].second]);
        cout << p << y << "\n";
    }
    return 0;
}

Measured memory_bytes: 21160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int i=0;
		
		for(i=1;i<=5;i++) {
			int n = sc.nextInt();
			if(n==0) {
				break;
			}
		}
		
		System.out.println(i);
	}
}


Measured memory_bytes: 35676
def main():
    n = int(list(input())[-1])
    if n in [2, 4, 5, 7, 9]:
        ans = 'hon'
    elif n in [0, 1, 6, 8]:
        ans = 'pon'
    else:
        ans = 'bon'
    print(ans)


if __name__ == "__main__":
    main()


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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    string n; cin >> n;
    ll ans = 0;
    rep(i, n.size()){
        int ia = n[i] - '0';
        ans += ia;
        ans %= 9;
    }
    if (ans % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3724
#include<stdio.h>
int main()
{
    int a,b,c,i,n=1;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    if(1<=a&&1<=b&&1<=c&&a<=100&&b<=100&&c<=100)
    {
        if(a!=b&&b!=c&&a!=c)
        {
            n=3;
        }
        else if((a!=b&&b!=c&&a==c)||(a==b&&b!=c&&a!=c)||(a!=b&&b==c&&a!=c))
            n=2;
    }
    printf("%d",n);
    return 0;
}



Measured memory_bytes: 128
/*
ID:yaoxinw1
TASK:xxxx
LANG:C++
*/
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<=n;i+=4){
		if((n-i)%7==0){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
import math
import collections
from sys import exit
from itertools import product

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

a,b,x = mi()

if a%x != 0:
    A = x*(a//x + 1)
else:
    A = a
B = b - b%x
print((B-A)//x+1)

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

using namespace std;

int min(vector<int> A, int b, int e)
{
    int num = e - b;
    int min = 1000000000;

    for (int i = 0; i < num; ++i)
    {
        if (min > A[i + b])
        {
            min = A[i + b];
        }
    }
    return min;
}

int max(vector<int> A, int b, int e)
{
    int num = e - b;
    int max = -1000000000;

    for (int i = 0; i < num; ++i)
    {
        if (max < A[i + b])
        {
            max = A[i + b];
        }
    }
    return max;
}

int main()
{
    int n, q, com, b, e;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> A[i];
    }
    cin >> q;
    for (int i = 0; i < q; ++i)
    {
        cin >> com;
        switch (com)
        {
        case 0:
            cin >> b >> e;
            cout << min(A, b, e) << endl;
            break;
        case 1:
            cin >> b >> e;
            cout << max(A, b, e) << endl;
            break;
        }
    }
}


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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  std::cin >> n;
  std::vector<int> as(n);
  std::vector<int> bs(n);
  int i = 0;
  for (; i < n; i++) {
    int a, b;
    std::cin >> a >> b;
    as[i] = a;
    bs[i] = b;
  }
  int64_t ret = 0;
  i--;
  for (; i >= 0; i--) {
    auto const a = as[i];
    auto const b = bs[i];
    ret += (b - (a + ret) % b) % b;
  }
  std::cout << ret << std::endl;
  return 0;
}

Measured memory_bytes: 1024
n =int(input())
a = list(map(int,input().split()))
a.sort()
l,r=0,n
while l != r - 1:
  t = (l + r) // 2
  s = sum(a[:t])
  for m in a[t:]:
    if s * 2 < m:
      l = t
      break
    s += m
  else:
    r = t
print(n - l)

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

int n, m, q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int> p){
	if((int)p.size() == n + 1) {
		int temp = 0;
		for(int i = 0; i < q; i++) {
			if(p[b[i]] - p[a[i]] == c[i]) temp += d[i];
		}
		ans = max(ans, temp);
		return;
	}
	p.push_back(p.back());
	while(p.back() <= m) {
		dfs(p);
		p.back()++;
	}
}

int main(){
	scanf("%d%d%d", &n, &m, &q);
	a = b = c = d = vector<int>(q);
	for(int i = 0; i < q; i++)
		scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
	dfs(vector<int> (1, 1));
	printf("%d\n", ans);
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
//万合以致，向阳而生——背叛时代，忠于时间//
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long long ll;
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(register int i=0; i<n; i++)
#define Forn(i, n) for(register int i=1; i<=n; i++)
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define mid l+r>>1
#define lid id<<1|1
#define rid (id<<1)+2
#define lson lid, l, mid
#define rson rid, mid, r
 
inline int in()
{
    char c=getchar();
    int neg=1, x=0;
    while(!isdigit(c)) (c=='-')?neg=-1, c=getchar():c=getchar();
    while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48), c=getchar();
    return neg*x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

int N, M, l, r, cnt;
struct dat
{
	int l, r;
	dat() {}
	void read() { l=in(), r=in(); }
	bool operator<(const dat &A){ return l<A.l; }
}a[200005];
priority_queue<int, vi, greater<int> > Q;
vi tmp;
 
int main()
{
    N=in(), M=in();
	Forn(i, N) a[i].read();
	
	sort(a+1,a+N+1);
	l=1;
	Forn(i, N)
    {
		Q.push(a[i].r);
		if(l<=M&&a[i].l>=l) l++;
		else
        {
			tmp.pb(Q.top());
			Q.pop();
		}
	}
	sort(tmp.begin(), tmp.end());
	r=M, cnt=0;
	Foreach(it, tmp)
    {
		if(r>=l&&*it<=r) r--;
        else cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

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

int main(){
  int n,m,a,SUM=0;
  cin >> n >> m ;
  for(int i=0;i<m;i++){
    cin >> a;
    SUM+=a;
  }
  if(n-SUM>=0){
    cout << n-SUM <<endl;
  } else {
    cout << -1<<endl;
  }
}


Measured memory_bytes: 3552
#include <iostream>
#include <cstring>	// require memset
//#include <fstream>	// require freopen

using namespace std;

int num[100007];

int main()
{
//	cut here before submit 
//	freopen ("testcase.longeststep", "r", stdin );
	int n, k;

	while (cin >> n >> k && n && k ){
		memset (num, 0, sizeof (num ) );
		bool sc = false;
		int max_n = 0;
		int i, j;
		for (i = 0; i < k; ++i){
			int m;
			cin >> m;
			max_n = max ( max_n, m );
			if (m == 0 ){
				sc = true;
			}else{
				num[m] = 1;
			} // end if
		} // end for
		
		for (i = 1; i <= n; ++i ){
			if (num[i] != 0 ){
				num[i] += num[i-1];
			} // end if
		} // end for
		int res = 0;

		for (i = 1; i <= n; ++i){
			res = max (res, num[i] );
		} // end for


		if (sc ){
			for (i = 1; i <= n; ++i){
				if (i == 1 && num[i] == 0 && num[i+1] != 0 ){
					for (j = i + 1 ; num[j] != 0 ; ++j){
						;
					} // end for
					--j;
					res = max (res, num[j] + 1 );
				}else 
				if (i == n && num[i] == 0 && num[i-1] != 0 ){
					res = max (res, num[i-1] + 1 );
				}else 
				if (num[i-1] != 0 && num[i] == 0 && num[i+1] != 0 ){
					for (j = i + 1 ; num[j] != 0 ; ++j){
						;
					} // end for
					--j;
					res = max (res, (num[i-1] + num[j] + 1) );
				} // end if
			} // end for
		} // end if

		if (res > k ){
			res = k;
		} // end if

		cout << res << endl;

	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
def ang(n) Array.new(n){gsmi} end
def debug(k,v) puts "#{k}: #{v}" end
def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

$stdin = File.open('input.txt') if File.exist?('input.txt')
n = gi
abcs = ang n

dp = Array.new(n){Array.new(3)}
dp[0] = abcs[0]
(1...n).each do |i|
  3.times do |j|
    dp[i][j] = abcs[i][j] + dp[i-1].map.with_index { |m,i| i==j ? 0 : m }.max
  end
end

puts dp[-1].max


Measured memory_bytes: 30192
N = int(input())
nums = []
for _ in range(N):
    nums.append(int(input()))
temp = nums[:]
temp.sort(reverse=True)
ma = temp[0]
ma2 = temp[1]
# print(nums)
for i in nums:
    if i == ma:
        print(ma2)
    else:
        print(ma)


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

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

  int a, b;
  vector<int> ans(N, 0);
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    ans.at(a-1)++;
    ans.at(b-1)++;
  }

  for (int i = 0; i < N; i++) {
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 256
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	static class State implements Comparable<State>{
		int tid, ttime, tans;
		State(int tid, int ttime,int tans){
			this.tid=tid;
			this.ttime=ttime;
			this.tans=tans;
		}
		public int compareTo(State e) {
			if(this.tans==e.tans) {
				if(this.ttime==e.ttime) {
					return this.tid-e.tid;
				}
				else {
					return this.ttime-e.ttime;
				}
			}
			else {
				return e.tans-this.tans;
			}
		}
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int T=sc.nextInt();//チーム数
				int P=sc.nextInt();//問題数
				int R=sc.nextInt();//レコード数
				if(T==0) break;
				PriorityQueue<State> pq=new PriorityQueue<State>();
				int[] c=new int[T+1];//正解数
				int[] t=new int[T+1];//経過時間
				int[][] w=new int[T+1][P+1];//チームと問題に対するWA数
				
				for(int i=0; i<R; i++) {
					int team=sc.nextInt();
					int prob=sc.nextInt();
					int time=sc.nextInt();
					String m=sc.next();
					if(m.equals("WRONG")) {
						w[team][prob]++;
					}
					if(m.equals("CORRECT")) {
						c[team]++;
						t[team]+=time+w[team][prob]*1200;
					}
				}
				for(int i=1; i<=T; i++) {
					pq.add(new State(i, t[i], c[i]));
				}
				for(int i=1; i<=T; i++) {
					State p=pq.remove();
					System.out.println(p.tid+" "+p.tans+" "+p.ttime);
				}
				
			}


		}
	}
}


Measured memory_bytes: 71116
function parseInt(x) parse(Int, x) end
parseMap(x::Array{SubString{String}, 1}) = map(parseInt, x)

function isPrime(x)
	if x <= 1
		return(0)
	elseif x == 2
		return(1)
	elseif x%2 == 0
		return(0)
	else
		i = 3
		flg = 0
		while i <= floor(sqrt(x))
			if x%i == 0
				return(0)
				flg = 1
				break
			else
				i += 2
			end
		end
		if flg == 0
			return(1)
		end
	end
end

function isBPrime(x)
  if isPrime(x) == 1 && isPrime(div(x+1,2)) == 1
    return(1)
  else
    return(0)
  end
end

function main()
  x = Array{Int}(100000)
  x[1] = 0
  for i in 2:100000
  	x[i] = x[i-1]+isBPrime(i)
  end
  q = parseInt(readline())
  for i in 1:q
    l, r = parseMap(split(readline()))
    if l == 1
    	println(x[r])
    else
	    println(x[r]-x[l-1])
	end
  end
end

main()

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;



int main() {
    int k; cin >> k;
    cout << (k / 2) * ((k + 1) / 2) << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		a[i] = nextInt()
	}

	cnt := 0
	for i := 1; i <= n; i++ {
		if a[i] == 0 {
			continue
		}
		if a[a[i]] == i {
			cnt++
			a[a[i]] = 0
		}
	}

	fmt.Println(cnt)

}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 3352
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<int,int> P;
typedef pair<ll,P> PP;
//typedef vector<vector<int> > Graph;
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; }
const ll INF = 1e18;

ll N,W;

int main(){
    cin >> N >> W;
    vector<vector<ll> >weight(4);
    vector<P>vec(N);
    rep(i,N){
        ll w,v;
        cin >> w >> v;
        vec[i]={w,v};
    }
    sort(vec.begin(),vec.end());
    ll w0 = vec[0].first;
    rep(i,N){
        ll w = vec[i].first-w0;
        ll v = vec[i].second;
        weight[w].push_back(v);
    }
    rep(i,4){
        if(weight[i].size()==0)continue;
        sort(weight[i].rbegin(),weight[i].rend());
        rep(j,weight[i].size()-1){
            weight[i][j+1]+=weight[i][j];
        }
    }
    ll ans = 0;
    rep(i,weight[0].size()+1){
        rep(j,weight[1].size()+1){
            rep(k,weight[2].size()+1){
                rep(l,weight[3].size()+1){
                    if(w0*(i+j+k+l)+j+2*k+3*l>W)continue;
                    ll now=0;
                    if(i>0)now+=weight[0][i-1];
                    if(j>0)now+=weight[1][j-1];
                    if(k>0)now+=weight[2][k-1];
                    if(l>0)now+=weight[3][l-1];
                    chmax(ans,now);
                }
            }
        }
    }
    cout << ans << endl;


    return 0;
}


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

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define F first
#define S second
#define MSET(m,v) memset((m),(v),sizeof(m))
#define UB(c,v) (upper_bound((c).begin(),(c).end(),(v)))
#define LB(c,v) (lower_bound((c).begin(),(c).end(),(v)))
#define INREP int TC;cin>>TC;while(TC--)
#define CPPIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);
}
#else
#define trace(...)
#endif

typedef long long ll;
typedef long double ld;
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;

// SOLUTION

int main () {
	CPPIO;
    int n, m, x;
    cin >> n >> m >> x;
    int arr[n + 1];
    MSET (arr, 0);
    for (int i = 0; i < m; i++) {
        int tmp;
        cin >> tmp;
        arr[tmp] = 1;
    }
    int a = 0, b = 0;
    for (int i = x; i <= n; i++) a += arr[i];
    for (int i = x; i >= 0; i--) b += arr[i];    
    cout << min (a, b);
	return 0;
}


Measured memory_bytes: 256
def DFS(Current_Node,Visited_Node):
    if len(Visited_Node) == N - 1:
        return 1
    ans = 0

    for a,b in AB:
        if a == Current_Node and b not in Visited_Node:
            vns = Visited_Node.copy()
            vns.add(a)
            ans += DFS(b, vns)

        if b == Current_Node and a not in Visited_Node:
            vns = Visited_Node.copy()
            vns.add(b)
            ans += DFS(a,vns)
    return ans



N,M = map(int,input().split())
AB = []

for i in range(M):
    a,b = map(int,input().split())
    AB.append((a,b))

ans = DFS(1,set())
print(ans)


Measured memory_bytes: 3064
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N,K = map(int,input().split())
    H = list(map(int,input().split()))

    if N <= K:
        print(0)
        sys.exit()
    else:
        H.sort()
        temp = H[:N-K]
        res = sum(temp)

    print(res)



main()


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


void solve(std::string S){
    int cnt = 0;
    int N = S.size();
    for(int i = 0; i < N/2; ++i){
        //cout << S[i] << " " << S[N-1-i] << endl;
        if(S[i] != S[N-1-i]) cnt++;
    }
    cout << cnt << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3640
A, B= map(int, input().split())

if A - B == 0:
    print("Draw")
elif A == 1 or B == 1:
    if A - B < 0:
        print("Alice")
    else:
        print("Bob")
else:
    if A - B < 0:
        print("Bob")
    else:
        print("Alice")


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

int main(){
	vector<int> mts(10);
	for( int i=0; i<10; i++ ){
		cin >> mts[i];
	}
	sort( mts.rbegin(), mts.rend() );
	for( int i=0; i<3; i++ ){
		cout << mts[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashSet;

fn divisors(N: i64) -> HashSet<i64> {
  let mut ds = vec![];
  let mut d = 1;
  while d * d <= N {
    if N % d == 0 {
      ds.push(d);
      ds.push(N / d);
    }
    d += 1;
  }
  let uniq: HashSet<i64> = ds.into_iter().collect();
  uniq
}

fn main() {
  let n = read::<i64>();
  let yakusuu = divisors(n);
  let mut y_vec = vec![];

  let mut ans = 100000000000;

  for i in yakusuu.iter() {
    y_vec.push(i);
  }
  y_vec.sort();
  let harf = y_vec.len() / 2;
  for i in 0..harf {
    let a = y_vec[i as usize];
    let b = y_vec[i as usize + harf];

    let a_len = a.to_string().len();
    let b_len = b.to_string().len();

    ans = min(ans, max(b_len, a_len));
  }
  if n == 1 {
    println!("{}", 1);
  } else {
    println!("{}", ans);
  }

}



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

int main() {
  int N,a,b,sum=0;
  cin >> N;
  a=N;
  
  while(a>9){
  	b = a % 10;
    sum += b;
    a = (a-b)/10;
  }
  sum += a;
  
  if(!(N%sum)){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;

int main(){
    
    int n,q;
    cin>>n;
    ll S[n];
    int count=0;
    for(int i=0;i!=n;++i){
        cin>>S[i];
    }
    cin>>q;
    ll T[q];
    for(int i=0;i!=q;++i){
        cin>>T[i];
    }
    
    
    for(int i=0;i!=q;++i){
        for(int j=0;j!=n;++j){
            if(S[j]==T[i]){
                ++count;
                break;
            }
        }
    }
    
    cout<<count<<endl;
               
               
    
}



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

#define rep(i,n) for(signed i=0;i<n;++i)
//#define int long long
#define str string
#define debg(a) cout<<#a<<":"<<a<<endl;
#define vint vector<signed>
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define yn(a) cout<<((a)?"Yes":"No")<<endl;
#define YN(a) cout<<((a)?"YES":"NO")<<endl;
int cnt[1000001];
vint insu[1000001];
signed main(){
  int n;
  cin>>n;
  int a[n];
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  int gcd=a[0];
  rep(i,n){
    int p=a[i];
    int r=gcd;
    while(true){
      if(p<r)swap(p,r);
      if(!r)break;
      if(p==r)break;
      p%=r;
    }
    gcd=p;
  }
  cout<<gcd;
  
  return 0;
}


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

//#include <conio.h>
using namespace std;


struct P
{
    //string r;
    int x;
    long long y,z;

   /* bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
              return y>a.y;
    }*/
};


vector<P> v[5];
//bitset<4001000> b;
int a,c,i,b,k,n,d,m;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[55];

int o[255];
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,-1,1,-1,1},dz[10]={0,0,0,0,1,-1};

int e[55];

long long x,y,mod=1000000007;
long long z;
int j[200][555];
P u[110000];
//stack<int> s;
//queue<long long> q;
priority_queue<int> q;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//list<int> l;
string r;

//deque<int> de;

bool as(P a,P b)
{
    return max(a.y,-a.y)<max(b.y,-b.y);
}


int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;j[t][o[t]]=1,t++)
        scanf("%d",&o[t]);
    for(int t=1;t<=a;t++)
    {
        scanf("%d",&l[t]);
        if(o[t]!=l[t]&&l[t]*2>=o[t])
        {
            puts("-1");
            return 0;
        }
    }
    for(int t=1;t<=50;e[t]=1,t++);

    for(int i=50;i>0;i--)
    {
        e[i]=0;
        memset(j,0,sizeof(j));
        for(int t=0;t<=50;j[t][t]=1,t++)
            for(int w=1;w<=50;w++)
            if(e[w]) j[t][t%w]=1;
        for(int t=0;t<=50;t++)
            for(int w=0;w<=50;w++)
            for(int h=0;h<=50;h++)
            if(j[w][t]&&j[t][h]) j[w][h]=1;
        for(int t=1;t<=a;t++)
            if(!j[o[t]][l[t]])
        {
            e[i]=1;
            break;
        }
    }
    for(int t=1;t<=50;t++)
        if(e[t]) x+=(long long )1<<t;
    printf("%lld",x);

}



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

using namespace std;

int const maxn = 2005;
char c[2 * maxn];
int a[2 * maxn], W[maxn], B[maxn];
int dp[2 * maxn][maxn], sum_W[2 * maxn][maxn], sum_B[2 * maxn][maxn];
int inf = 1e9;

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= 2 * n; ++i) cin >> c[i] >> a[i];
    for (int i = 0; i <= 2 * n; ++i) for (int j = 0; j <= n; ++j) dp[i][j] = inf;
    for (int i = 2 * n; i >= 1; --i) {
        for (int j = 1; j <= n; ++j) sum_W[i][j] = sum_W[i + 1][j], sum_B[i][j] = sum_B[i + 1][j];
        if (c[i] == 'B') for (int j = a[i]; j <= n; ++j) sum_B[i][j]++;
        else for (int j = a[i]; j <= n; ++j) sum_W[i][j]++;
    }
    for (int i = 1; i <= 2 * n; ++i) {
        if (c[i] == 'B') B[a[i]] = i;
        else W[a[i]] = i;
    }
    dp[0][0] = 0;
    for (int i = 1; i <= 2 * n; ++i) {
        for (int w = 0; w <= min(n, i); ++w) {
            int b = i - w;
            if (b > n) continue;
            if (w > 0) {
                int pos = W[w] + sum_W[W[w] + 1][w] + sum_B[W[w] + 1][b];
                /*for (int j = pos + 1; j <= 2 * n; ++j) {
                    if (c[j] == 'W' && a[j] <= w) pos++;
                    else if (c[j] == 'B' && a[j] <= b) pos++;
                }*/
                dp[i][w] = min(dp[i][w], dp[i - 1][w - 1] + pos - i);
            }
            if(b > 0) {
                int pos = B[b] + sum_W[B[b] + 1][w] + sum_B[B[b] + 1][b];
                /*for (int j = pos + 1; j <= 2 * n; ++j) {
                    if (c[j] == 'W' && a[j] <= w) pos++;
                    else if (c[j] == 'B' && a[j] <= b) pos++;
                }*/
                dp[i][w] = min(dp[i][w], dp[i - 1][w] + pos - i);
            }
        }
    }
    cout << dp[2 * n][n] << '\n';
    return 0;
}


Measured memory_bytes: 94464
#include <iostream>

using namespace std;

int main()
{
	long long a, b, x;
	
	cin >> a >> b >> x;

	if (a == 0)
	{
		cout << b / x - a / x + 1 << endl;
	}
	else
	{
		cout << b / x  - (a - 1) / x << endl;
	}

	return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  
  for (int i = 1; i <= 3; ++i) {
    if (a * b * i % 2 == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
using namespace std;

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

int main() {
    int M, D;
    cin >> M >> D;
    if (D < 22) {
        cout << 0 << endl;
        return 0;
    }
    int cnt = 0;
    for(int i = 1; i <= M; i++) {
        for(int j = 22; j <= D; j++) {
            int tmp = j;
            int d1 = tmp % 10;
            if(d1 < 2) continue;
            int d2 = tmp / 10;
            if(d2 < 2) continue;
            // cout << "d1: " << d1 << "d2: " << d2 << endl;
            if(i == d1*d2) {
                // cout << "i: " << i << " d1: " << d1 << " d2: " << d2 << endl;
                cnt++;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void trace(int A[], int n) {

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

int bubbleSort(int A[], int n) {

	bool flag = 1;
	int i = 0;
	int sw = 0;

	while(flag) {

		flag = 0;

		for(int j = n - 1; j >= i + 1; j--) {

			if(A[j] < A[j-1]) {
				int temp = A[j];
				A[j] = A[j-1];
				A[j-1] = temp;

				flag = 1;
				sw++;
			}
		}
		i++;
	}
	return sw;
}

int main(void) {

	int A[100], n, sw;

    cin >> n;

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

    sw = bubbleSort(A, n);

    trace(A, n);
    cout << sw << endl;

    return 0;
}

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

//少数を考えるときはdouble!!!intだけ使うと引っかかるぞ！！

int main(){
  int n,zou,gen,res=0,counter=0,pre_res=0;
  cin >> n;
  int a[n];
  for(int i= 0;i<n;i++){
    cin >> a[i];
  }
  bool monotone = true;
  while(true){
    pre_res=res;
    //単調非減少]
    //cout << "更新res" << res << endl;
    for(int i=res+1;i<=n;i++){
      if(a[i-1]>a[i]){
        gen=i;//減少の場所
        break;
      }
      gen =i;
    }
    //単調非増加
    for(int i=res+1;i<=n;i++){
      if(a[i-1]<a[i]){
        zou=i;//増加の場所
        break;
      }
      zou=i;
    }
    //cout << "減少位置：" << gen << endl
    //<< "増加位置：" << zou << endl;
    res=max(gen,zou);
    counter++;
    if(res==pre_res)break;
  }
  cout << counter-1 <<endl;
}


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

using namespace std;

int func(int a, int b, int c, int d){
	for(int i=0;;++i){
		int current = a + i * d;
		if(current/c >= b)return i;
	}
}

int main(){
	int a, b, c, d;
	while(true){
		cin >> a >> b >> c >> d;
		if(!(a+b+c+d))break;
		cout << func(a, b, c, d) << endl;
	}

	return 0;
}



Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
    int n;
    cin >> n;
    int cnt[26];
    rep(i, 26) cnt[i] = 1e8;
    rep(i, n) {
        string tmp_s;
        cin >> tmp_s;
        vector<int> tmp_cnt(26, 0);
        rep(i, tmp_s.length()) {
            ++tmp_cnt[tmp_s[i] - 'a'];
        }
        rep(i, 26) {
            cnt[i] = min(cnt[i], tmp_cnt[i]);
        }
    }
    vector<char> ans;
    rep(i, 26) {
        int tmp_cnt = cnt[i];
        rep(j, tmp_cnt) ans.push_back(char(i+'a'));
    }
    if ( ans.size() == 0 ) {
        cout << " " << endl;
    }
    else {
        sort(ans.begin(), ans.end());
        for ( auto tmp_ans : ans ) {
            cout << tmp_ans;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
top = 0
s = [0]*1000

def push(x):
    global top
    top += 1
    s[top] = x
    
def pop():
    global top
    top -= 1
    return s[top+1]

a = list(input().split())

for x in a:
    if x == "+":
        b = pop()
        c = pop()
        push(b+c)
    elif x == "-":
        b = pop()
        c = pop()
        push(c-b)
    elif x == "*":
        b = pop()
        c = pop()
        push(b*c)
    else:
        push(int(x))

print(pop())


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

struct Point
{
    long long x, y, distance{1000000000000};
    std::vector<std::pair<int, long long>> edge;
};

using pli = std::pair<long long, int>;

int main()
{
    int n;
    Point points[100000];

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%lld%lld", &points[i].x, &points[i].y);
    {
        int sort_p[100000];
        for (int i = 0; i < n; i++)
            sort_p[i] = i;
        std::sort(sort_p, sort_p + n, [&](const int &a, const int &b) { return points[a].x < points[b].x; });
        for (int i = 0; i < n - 1; i++)
            points[sort_p[i]].edge.push_back({sort_p[i + 1], points[sort_p[i + 1]].x - points[sort_p[i]].x});
        for (int i = 1; i < n; i++)
            points[sort_p[i]].edge.push_back({sort_p[i - 1], points[sort_p[i]].x - points[sort_p[i - 1]].x});

        std::sort(sort_p, sort_p + n, [&](const int &a, const int &b) { return points[a].y < points[b].y; });
        for (int i = 0; i < n - 1; i++)
            points[sort_p[i]].edge.push_back({sort_p[i + 1], points[sort_p[i + 1]].y - points[sort_p[i]].y});
        for (int i = 1; i < n; i++)
            points[sort_p[i]].edge.push_back({sort_p[i - 1], points[sort_p[i]].y - points[sort_p[i - 1]].y});
    }

    bool connected[100000]{};
    long long sum{};
    int rest{n - 1};
    std::priority_queue<pli, std::vector<pli>, std::greater<pli>> pq;
    connected[0] = true;
    for (auto &e : points[0].edge)
    {
        points[e.first].distance = e.second;
        pq.push({e.second, e.first});
    }
    while (rest)
    {
        auto next = pq.top();
        pq.pop();
        if (connected[next.second]) continue;
        rest--;
        connected[next.second] = true;
        sum += next.first;
        for (auto &e : points[next.second].edge)
        {
            if (e.second >= points[e.first].distance) continue;
            points[e.first].distance = e.second;
            pq.push({e.second, e.first});
        }
    }

    printf("%lld\n", sum);

    return 0;
}

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

using namespace std;

typedef unsigned long long ull;

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

bool isIn(int x, int y, int n, int m){
     return 0 <= x && x <= n && 0 <= y && y <= m;
}

int main(){
    int n;
    cin >> n;
    for(int q=0; q < n; q++){
        int gx, gy;
        cin >> gx >> gy;
        int m;
        cin >> m;
        bool passable[20][20][20][20];
        rep(i, 20)rep(j, 20)rep(k, 20)rep(l, 20) passable[i][j][k][l] = true;
        rep(i, m){
            int a, b, c, d;
            cin >> a >> b >> c >> d;
            passable[a][b][c][d] = false; passable[c][d][a][b] = false;
        }
        int dp[20][20];
        rep(i, 20)rep(j, 20) dp[i][j] = 0;
        dp[0][0] = 1;
        for(int i = 0; i <= gy; i++){
            for(int j = 0; j <= gx; j++){
                if(isIn(j, i-1, gx, gy) && passable[j][i-1][j][i]) dp[i][j] += dp[i-1][j];
                if(isIn(j-1, i, gx, gy) && passable[j-1][i][j][i]) dp[i][j] += dp[i][j-1];
            }
        }
        if(dp[gy][gx] == 0) cout << "Miserable Hokusai!" << endl;
        else cout << dp[gy][gx] << endl;
    }
}

Measured memory_bytes: 1320
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin >> s;
  int counter = 0;
  if(s[0] == '1') ++counter;
  if(s[1] == '1') ++counter;
  if(s[2] == '1') ++counter;
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i, n) for( int i=0 ; i<n ; i++ )
#define f(i, a, b) for( int i=a ; i<b ; i++ )
#define vi vector<int>
#define pb push_back
#define MOD 1000000007
int main()
{
    int n;
    cin>>n;
    int arr[n];
    //map<int,int>mp;
    map<int , pair<int ,int > > mp;
    // will store the values and their first and last indices
    fi(i,n)
    {
        cin>>arr[i];
        if(mp.find(arr[i]) == mp.end())
        {
            mp[arr[i]].first = i + 1;
            mp[arr[i]].second = i + 1;
        }
        else
        {
            mp[arr[i]].second = i + 1;
        }
    }
	/*
    for(auto it = mp.begin();it!=mp.end();it++)
    {
        cout<<it->first<<" "<<it->second.first<<" "<<it->second.second<<endl;
    }
    */
    int count =0;
    int prev_index = 0;
    int dis = 1;
    for(auto it = mp.begin();it!=mp.end();it++)
    {
    	int fir = it->second.first;
    	int las = it->second.second;
    	if(it->first != dis)
    	{
    		break;
    	}
    	else if(las<prev_index)
    	{
    		break;
    	}
    	else 
    	{
    		if(fir>prev_index)
    		{
    			prev_index = fir;
    			count++;
    		}
    		else if(las>prev_index)
    		{
    			prev_index = las;
    			count++;
    		}
    	}
    	dis++;
    }
    if(count==0)
    	cout<<"-1";
    else 
    	cout<<n - count;



}


Measured memory_bytes: 16908
#include <stdio.h>
int main (void)
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
     
    if(a<=b && b<=c && a<=c)
    {
        printf("%d %d %d\n",a,b,c);
    }
    else if(a<=c && c<=b && a<=b)
    {
        printf("%d %d %d\n",a,c,b);
    }
    else if(b<=c && c<=a && b<=a)
    {
        printf("%d %d %d\n",b,c,a);
    }
     else if(b<=a && a<=c && b<=c)
    {
        printf("%d %d %d\n",b,a,c);
    }
    else if( c<=a && a<=b && c<=b)
    {
        printf("%d %d %d\n",c,a,b);
    }
    else if(c<=b && b<=a && c<=a)
    {
        printf("%d %d %d\n",c,b,a);
    }
    return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
  int n; char s[7];
  int digits;
  int ans;
  
  scanf("%s",s);
  n = atoi(s);
  digits = strlen(s);
  
  switch(digits) {
    case 1: ans = n; break;
    case 2: ans = 9; break;
    case 3: ans = 9 + (n - 99); break;
    case 4: ans = 909; break;
    case 5: ans = 909 + (n - 9999); break;
    case 6: ans = 90909; break;
  }
  
  printf("%d",ans);
  
  return 0;
}

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

int main(){
int N, ma, now, sum;
ma = 0;
sum = 0;  
  cin >> N;
  
  for(int i = 0;i < N;i++){
  cin >> now;
  ma = max(ma, now);  
  sum += now;  
  }

  sum -= ma / 2;
  cout << sum << endl;
  
  return 0;
  
}

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

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

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

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

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct Edge{
	int src,dst,cap,cost;
	Edge(){}
	Edge(int s,int d,int ca,int co):src(s),dst(d),cap(ca),cost(co){}
};
typedef vector<vector<Edge> > Graph;

int MinCostFlow(const Graph& _g,int begin,int end,int flow)
{
	int size=_g.size();
	Graph g(size);
	vvi rev(size);
	rep(i,size) for(auto e:_g[i]){
		g[i].push_back(e);
		g[e.dst].push_back(Edge(e.dst,e.src,0,-e.cost));
		rev[i].push_back(g[e.dst].size()-1);
		rev[e.dst].push_back(g[i].size()-1);
	}
	
	int res=0;
	vi pots(size);
	while(flow){
		vi dist(size,INF);
		vector<pii> prev(size,mp(-1,-1));
		priority_queue<pii,vector<pii>,greater<pii> > pq;
		pq.push(mp(0,begin));
		dist[begin]=0;
		while(!pq.empty()){
			int curd=pq.top().first,curv=pq.top().second; pq.pop();
			if(dist[curv]<curd)
				continue;
			rep(i,g[curv].size()){
				Edge e=g[curv][i];
				if(e.cap==0)
					continue;
				int newdist=dist[e.src]+e.cost+pots[e.src]-pots[e.dst];
				if(dist[e.dst]>newdist){
					dist[e.dst]=newdist;
					prev[e.dst]=mp(e.src,i);
					pq.push(mp(newdist,e.dst));
				}
			}
		}
		
		if(prev[end].first==-1)
			return -1;
		rep(i,size)
			pots[i]+=dist[i];
		
		int f=flow;
		for(int v=end;v!=begin;v=prev[v].first){
			Edge e=g[prev[v].first][prev[v].second];
			f=min(f,e.cap);
		}
		for(int v=end;v!=begin;v=prev[v].first){
			int i=prev[v].first,j=prev[v].second;
			g[i][j].cap-=f;
			g[g[i][j].dst][rev[i][j]].cap+=f;
		}
		flow-=f;
		res+=f*pots[end];
	}
	
	return res;
}

int main()
{
	for(int n;cin>>n && n;){
		vi as(n),bs(n);
		rep(i,n) cin>>as[i]>>bs[i];
		map<int,int> f;
		rep(i,n) f.insert(mp(as[i],f.size()));
		rep(i,n) f.insert(mp(bs[i],f.size()));
		int m=f.size();
		Graph g(n+m+2);
		int tap=n+m,sink=tap+1;
		rep(i,n){
			g[tap].emplace_back(tap,i,1,0);
			g[i].emplace_back(i,n+f[as[i]],1,-bs[i]);
			g[i].emplace_back(i,n+f[bs[i]],1,-as[i]);
			g[i].emplace_back(i,sink,1,0);
		}
		rep(i,m)
			g[n+i].emplace_back(n+i,sink,1,0);
		cout<<-MinCostFlow(g,tap,sink,n)<<endl;
	}
}

Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e18;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<=(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)

int main()
{
    ll N,ans = 0;
    cin >> N;
    repi(i,N,1){
        if((1<= i && i <= 9) || (100 <= i && i <= 999) || (10000 <= i && i <= 99999)){
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string s,t;
  cin >> s >> t;
  int N,M;
  N = s.size();
  M = t.size();
  int m = min(N,M);
  int count = 0;
  bool ans = false;
  if(N<M)
  {
    rep(i,N)
    {
      if(s[i]==t[i])
      {
        count ++;
        if(count == N)
        {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  sort(ALL(s));
  sort(RALL(t));
  if(s[0]<t[0])
  {
    cout << "Yes" << endl;
    return 0;
  }
  else if(s[0]>t[0])
  {
    cout << "No" << endl;
  }
  rep(i,m)
  {
    if(s[i]==t[i])
    {
      continue;
    }
    else if(s[i]<t[i])
    {
      ans = true;
      break;
    }
    else
    {
      ans = false;
      break;
    }
    
  }
  if(ans == true)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
  return 0;
}


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

int main() {
    int n, x, m, sel, sum, ans;
    cin >> n >> x;
    
    ans = n;
    sum = 0;
    sel = INT_MAX;
    for ( int i = 0; i < n; i++ ) {
        cin >> m;
        sum += m;
        sel = min(sel, m);
    }
    
    ans += (x - sum) / sel;
    cout << ans << endl;
    
    return (0);
}

Measured memory_bytes: 3508
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,K;cin>>N>>K;
  vll V(N);
  for(ll i=0;i<N;i++){
    cin>>V[i];
  }
  ll ans = 0;
  for(ll j=0;j<=min(N,K);j++){
    //debug(j);
    multiset<ll> S;
    ll sum=0;
    ll r;
    for(r=N-1;r>N-1-j;r--){
      S.insert(V[r]);
      sum += V[r];
    }
    for(ll l=0;l<=j;l++){
      //debug(l);
      //debug(sum);
      ll a=sum;
      ll k=0;
      for(ll s:S)if(++k<=min(j,K-j)&&s<0){
        a -= s;
      }
      //debug(a);
      ans = max(ans,a);
      if(l<j){
        S.erase(V[++r]);
        sum -= V[r];
        S.insert(V[l]);
        sum += V[l];
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
a_s = [int(x) for x in input().split()]

average = sum(a_s)
average /= len(a_s) * 1.0

ans = -1
for target in range(int(average), int(average) + 2):
    c = sum(map(lambda x: (x - target) * (x - target), a_s))
    if ans < 0:
        ans = c
    else:
        ans = min(ans, c)

print(ans)


Measured memory_bytes: 3060
def rec(m,i,j)
  m[i][j]=0
  rec(m,i,j+1) if j<11 and m[i][j+1]==1
  rec(m,i,j-1) if j>0 and m[i][j-1]==1
  rec(m,i+1,j) if i<11 and m[i+1][j]==1
  rec(m,i-1,j) if i>0 and m[i-1][j]==1
  return m
end
loop do
  m,c,t=[],0,12
  t.times{m<<gets.split("").map(&:to_i)}
  t.times{|i|
    t.times{|j|
      if m[i][j]==1
        m=rec(m,i,j)
        c+=1
      end
    }
  }
  p c
  break if !gets
end

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

void solve(){
    int n;
    cin >> n;
    int cnt = 0;
    int ans = 0;
    for(int i=0;i<n;++i) {
        int a,b;cin  >> a >> b;
        if(a == b)
            cnt ++ ;
        else
            cnt = 0;
        if(cnt >= 3)
            ans = 1;
    }
    cout << (ans ? "Yes" : "No") << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t =1;
    while(t--)
        solve();
    return 0;
}



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

int main(){
  int n;
  long long a[100100];
  long long res;
  cin >> n;
  res=1;
  for (int i=0; i<n; i++){
    cin >> a[i];
    if (a[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i=0; i<n; i++){
    //cout << a[i] << endl;
    if (a[i] > 1000000000000000000/res){
      cout << -1 << endl;
      return 0;
    } else {
      res *= a[i];
      //cout << res << -1 << endl;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4288
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
using namespace std;

int main()
{
    const long long int one = 1LL;
    const long long int two = 2LL;
    const long long int six = 6LL;
    const long long int five = 5LL;
    const long long int eleven = six + five;

    long long int x;
    if (scanf("%lld", &x) < 1) return 0;

    if (x <= six) printf("%lld\n", one);
    else if (six < x && x <= eleven) printf("%lld\n", two);
    else if (six < x % eleven) printf("%lld\n", two * (x / eleven + one));
    else if (!(x % eleven)) printf("%lld\n", two * (x / eleven));
    else printf("%lld\n", two * (x / eleven) + one);

    return 0;
}


Measured memory_bytes: 128