akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvl = vector<vector<long>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

vector<vvl> dp(110,vvl(2,vl(4,-1)));
int K;

long rec(string &s, int k = 0,bool tight = true,int sum = 0){
    if(sum > K) return 0;

    if(k == s.size()){
        if(sum == K) return 1;
        else return 0;
    }
    int x = s.at(k) - '0';
    int r = tight ? x : 9;

    long &res = dp[k][tight][sum];

    if(~res) return res;

    res = 0;

    for(int i=0; i<=r ; i++){
        res += rec(s,k+1,tight && i==r,sum + (i!=0));
    }
    return res;
}

int main(){
    string s;
    
    cin >> s >> K;

    cout << rec(s) << endl;

}

Measured memory_bytes: 256
x,y,a,b,c=map(int,raw_input().split())
p=map(int,raw_input().split())
q=map(int,raw_input().split())
r=map(int,raw_input().split())

a=[]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

u=p[0:x]
v=q[0:y]
if len(r)<x+y:
    w=r
else:
    w=r[0:x+y]

A=u+v+w
A.sort(reverse=True)
print sum(A[0:x+y])


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

int main() {
	int q; scanf("%d", &q);
	rep(i, q) {
		int n; scanf("%d", &n);
		map<int, bool>mp;
		for (int cnt = 0;; cnt++) {
			if (n < 10) {
				printf("%d\n", cnt);
				break;
			}
			mp[n] = true;
			int Max = 0;
			string s = to_string(n);
			for (int i = 1; i < s.size(); i++) {
				string s1, s2;
				rep(j, i)s1 += s[j];
				for (int j = i; j < s.size(); j++)s2 += s[j];
				Max = max(Max, stoi(s1)*stoi(s2));
			}
			if (mp[Max]) {
				puts("-1");
				break;
			}
			n = Max;
		}
	}
}

Measured memory_bytes: 3340
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <complex>
#include <map>
#include <set>
#include <bitset>

#define forin(i, f, t) for(ll i = f; i < t; i++)

using namespace std;
using ll = long long;
using ULL = unsigned long long;
using Pair = pair<ll, ll>;

const int MAX = 300;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a[n];
    for (auto i = 0; i < n; i++) {
        a[i].resize(m);
        for (auto j = 0; j < m; j++)
            cin >> a[i][j];
    }
    
    int minS = 300;
    for (auto i = 0; i < m; i++) {
        vector<int> tops(m + 1, 0);
        for (auto j = 0; j < n; j++) {
            tops[a[j][0]]++;
        }
        auto maxI = max_element(tops.begin(), tops.end()) - tops.begin();
        auto maxS = tops[maxI];
        minS = min(minS, maxS);
        for (auto j = 0; j < n; j++) {
            a[j].erase(find(a[j].begin(), a[j].end(), maxI));
        }
    }
    
    cout << minS << endl;
}



Measured memory_bytes: 640
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {

  var input = chunk.split(" ");
  var output = "";
  var num = new Array();  
  for (var i = 0; i < input.length; i++ ) {
    num[i] = Number(input[i]);
  }

  var cnt = 0;
  for (var j = num[0]; j <= num[1]; j++) {
    if ((num[2] % j) === 0) {
      cnt ++;
    }
  }
  console.log(cnt);
});

Measured memory_bytes: 15672
#include<iostream>
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
using namespace std;
int main()
{
    fastio;
    long long n,i,sum=0,temp=0;
    cin>>n;
    long long a[3*n];
    for(i=0;i<3*n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+3*n);
    for(i=3*n-2; ;i=i-2)
    {
        if(temp==n)
        {
            break;
        }
        sum=sum+a[i];
        temp++;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 5924
#include <bits/stdc++.h>
//#define int long long
using namespace std;

signed main()
{
	//ios::sync_with_stdio(false);
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(a,b)<<" "<<max(0,a+b-n)<<endl;
	return 0;
}

Measured memory_bytes: 256
def dijkstra(s):
    global d
    color=[0]*n
    d=[float('inf')]*n
    d[s]=0
    while True:
        mincost=float('inf')
        for i in xrange(n):
            if color[i]!=2 and d[i]<mincost:
                mincost=d[i]
                u=i
        if mincost==float('inf'):
            break
        color[u]=2
        for v in xrange(n):
            if color[v]!=2 and m[u][v]!=0:
                if d[u]+m[u][v]<d[v]:
                    d[v]=d[u]+m[u][v]
                    color[v]=1

if __name__=='__main__':
    n=input()
    m=[[0]*n for i in xrange(n)]
    for i in xrange(n):
        en=map(int,raw_input().split())
        for j in xrange(2*en[1]):
            if j%2==0:
                enid=en[2+j]
            else:
                m[en[0]][enid]=en[2+j]
    dijkstra(0)
    for i in xrange(n):
        print i,d[i]

Measured memory_bytes: 6488
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

string s, t;
set<pair<char, ll>> ch;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s >> t;
    F0R(i, sz(s))
    {
        ch.insert({s[i], i + 1});
    }
    ll res = 0;
    F0R(i, sz(t))
    {
        char cur = t[i];
        ll idx = res%sz(s);
        auto itx = ch.upper_bound({cur, idx});
        if((*itx).f != cur) 
        {
            idx = 0;
            res -= res%sz(s);
            res += sz(s);
            itx = ch.upper_bound({cur, idx});
        }
        if((*itx).f != cur)
        {
            // cout << i << " " << cur << " " << (*itx).f;
            cout << -1;
            return 0;
        }
        if(idx > (*itx).s)
        {
            res -= res%(sz(s));
            res += sz(s) + (*itx).s;
        }
        else
        {
            res -= res%(sz(s));
            res += (*itx).s;
        }
    }
    cout << res;
    return 0;
}

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

int main(void){
  int N; cin >> N;
  int AC=0,WA=0,TLE=0,RE=0;
  string s;
  while(N--){
    cin >> s;
    if(s=="AC")
      ++AC;
    else if(s=="WA")
      ++WA;
    else if(s=="TLE")
      ++TLE;
    else if(s=="RE")
      ++RE;
  }
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
  
  return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int A, B, C, D;

  unused = scanf("%d %d %d %d", &A, &B, &C, &D);
  if(A*B >= C*D) printf("%d", A*B);
  else printf("%d", C*D);

  return 0;
}

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

int main() {

	int n;
	cin >> n;

	if (n % 4 == 0) {
		cout << "Yes";
	}
	else {
		for (int i = n; i > 0; i = i - 4) {
			if (i % 7 == 0) {
				cout << "Yes";
				i = 0;
			}
			if (i == 3 ||i==2 ||i==1) {
				cout << "No";
			}
		}

	}

return 0;
	}


Measured memory_bytes: 256
from collections import defaultdict

def foo():
    N = int(input())
    D = map(int, input().split())
    M = int(input())
    T = map(int, input().split())

    counter1 = defaultdict(int)
    counter2 = defaultdict(int)

    for d in D:
        counter1[d] += 1
    for t in T:
        counter2[t] += 1

    for t, cnt in counter2.items():
        if counter1[t] < cnt:
            print("NO")
            return

    print("YES")

foo()


Measured memory_bytes: 67800
// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;


// Code from Here -------------------------------------------------------------------------------


signed main() {
	tezz

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

	int n,m,k;
	cin >> n >> m >> k;
	vi c(n);
	int a[n][m];
	for(int i=0; i<n; i++){
		cin >> c[i];
		for(int j=0; j<m; j++)cin >> a[i][j];
	}
	int nax = 1<<n;
	int ans = LLONG_MAX;
	for(int i=0; i<nax; i++){
		bitset<16> b(i);
		int tmp = 0;
		vi sum(m, 0);
		for(int j=0; j<n; j++){
			if(b[j]==1){
				tmp+=c[j];
				for(int l=0; l<m; l++){
					sum[l]+=a[j][l];
				}
			}
		}
		bool f1=true;
		for(int j=0; j<m; j++){
			if(sum[j] < k){
				f1=false;
				break;
			}
		}
		if(f1)ans = min(ans, tmp);
	}
	if(ans == LLONG_MAX)ans = -1;
	cout << ans << endl;


	return 0;
}  

Measured memory_bytes: 3608
#include <cstdio>
#include <vector>
#define R second.second
using namespace std;
main(){
	int W,Q,d,w,i;
	char s[2];
	for(;scanf("%d%d",&W,&Q),W;puts("END")){ //some case Q==0
		vector<pair<int,pair<int,int> > >v;
		for(v.push_back(make_pair(-2,make_pair(0,0))),v.push_back(make_pair(-1,make_pair(W,0)));Q;Q--){
			if(scanf("%s",s),*s-'w'){
				for(scanf("%d%d",&d,&w),i=0;~v[i].first;i++)if(v[i+1].second.first-v[i].R>=w){v.insert(v.begin()+i+1,make_pair(d,make_pair(v[i].R,v[i].R+w)));printf("%d\n",v[i].R);break;}
				if(v[i].first==-1)puts("impossible");
			}else for(scanf("%d",&d),i=0;i<v.size();i++)if(v[i].first==d){v.erase(v.begin()+i);break;}
		}
	}
}

Measured memory_bytes: 1044
#include <array>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>

using namespace std::literals;

const auto tests = std::array<std::string, 7>{"SUN"s, "SAT"s, "FRI"s, "THU"s,
                                              "WED"s, "TUE"s, "MON"s};

int main() {
    auto s = ""s;
    std::cin >> s;

    auto dist = 1;
    for (; dist < 7; ++dist)
        if (tests[dist] == s)
            break;

    printf("%d", dist);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <tuple>
#include <algorithm>
#include <limits>
#include <map>
#include <cmath>

using namespace std;
using lli = long long int;

//int main(void) {
//	lli N,ans = 0;
//	cin >> N;
//
//	if (N == 1) {
//		cout << "0" << endl;
//		return 0;
//	}
//
//	for (lli i = 1; i <= sqrt(N); i++) {
//		lli m = (N - i) / i;
//
//		if (N % m == N / m) {
//			ans += m;
//		}
//
//	}
//
//	cout << ans << endl;
//
//	return 0;
//}
//
//int main(void) {
//
//	lli N,ans = 0;
//	cin >> N;
//
//	lli a = 0, b = 0;
//
//	for (int i = 0; i < N; i++) {
//		string str;
//		cin >> str;
//		if (str[0] == 'B') b++;
//		if (str[str.size() - 1] == 'A') a++;
//		for (int j = 0; j < str.size() - 1; j++) {
//			if (str[j] == 'A' && str[j + 1] == 'B') {
//				ans++;
//			}
//		}
//	}
//
//	cout << ans + min(a, b) << endl;
//
//	return 0;
//}

int main(void) {

	lli r, g, b, n, ans = 0;
	cin >> r >> g >> b >> n;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if ((n - r * i - g * j) >= 0 && (n - r * i - g * j) % b == 0) {
				ans++;
				//cout << r << " " << g << " " << (n - r * i - g * j) / b << endl;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int H,W;
    Scd2(H,W);
    char s[12][12];
    Rep(i,H) Scs(s[i]);

    int ans = 0;
    Rep(hi,H) {
        Rep(wi,W){
            if( s[hi][wi] == '#' ){
                ans++;
            }
        }
    }

    printf ("%s\n", ans==W+H-1?"Possible":"Impossible");

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, W, w[110], v[110];
long long dp[100010];
int main() {
	scanf("%d%d", &n, &W);
	for(int i=1; i<=100000; i++) dp[i] = 1e18;
	for(int i=1; i<=n; i++) {
		scanf("%d%d", w+i, v+i);
		for(int j=100000; j>=0; j--)
			if(j >= v[i]) dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
	}
	long long res = 0;
	for(int i=0; i<=100000; i++)
		if(dp[i] <= W) res = i;
	printf("%lld", res);
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include <string>
#include <iostream>
#include <cmath>
using namespace  std;
int main( )
{
    string i, j;
    int d;
    cin >> i >>  j;
    sscanf((i + j).c_str(), "%d", &d);
    int r = sqrt(d);
    printf("%s\n", r * r == d ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
xyz=[]
for i in range(N):
    x,y,z=map(int,input().split())
    xyz.append([x,y,z])
ans=0
for k in range(8):
    A=[k>>2 &1,k>>1 &1,k>>0 &1]
    l=[]
    for i in range(N):
        t=0
        for j in range(3):
            if A[j]==0:
                t+=xyz[i][j]
            else:
                t-=xyz[i][j]
        l.append(t)
    l.sort(reverse=True)
    ans=max(ans,sum(l[:M]))
print(ans)


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

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

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,cnt=0;
	cin>>n;
	vector<ll>v(n);
	for(int i=0;i<n;i++) cin>>v[i];
	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n-1;j++){
			for(int k=j+1;k<n;k++){
				if(v[i]==v[j]||v[i]==v[k]||v[j]==v[k]) continue;
				if(v[i]+v[j]>v[k]&&v[j]+v[k]>v[i]&&v[k]+v[i]>v[j]) cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3624
use std::error::Error;
use std::io;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed.");
    }
}

fn run() -> Result<(), Box<dyn Error>> {
    let mut input = String::new();
    io::stdin().read_line(&mut input)?;
    let nums: Vec<i64> = input
        .trim()
        .split_whitespace()
        .map(|s| s.parse::<i64>().unwrap())
        .collect();
    input.clear();

    for (index, &n) in nums.iter().enumerate() {
        if n == 0 {
            println!("{}", index + 1);
            break;
        }
    }

    Ok(())
}


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


void solve(long long N, long long K, std::vector<long long> h){
    long long temp=10000000000;
    sort(h.begin(),h.end());
    for(int i=0;i<N-K+1;i++){
        if(h[i+K-1]-h[i]<temp){temp=h[i+K-1]-h[i];}
        }
    printf("%lld\n",temp);
}


int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, K, std::move(h));
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int cnt,a[5];
int main()
{

    cin>>a[0]>>a[1]>>a[2]>>a[3];
    sort(a,a+4);
    if(a[0]==1 && a[1]==4 && a[2]==7 && a[3]==9) cout<<"YES";
    else cout<<"NO";

    return 0;
}


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

using namespace std;

static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
        int n;
        scanf("%d", &n);
        vector<vector<int>> f(n, vector<int> (10));
        for (int i = 0; i < n; i ++) {
                for (int j = 0; j < 10; j ++) scanf("%d", &f[i][j]);
        }
        vector<vector<int>> p(n, vector<int> (11));
        for (int i = 0; i < n; i ++) {
                for (int j = 0; j <= 10; j ++) scanf("%d", &p[i][j]);
        }
        long long ans = -INFL;
        for (int use = 1; use < (1 << 10); use ++) {
                long long res = 0;
                for (int i = 0; i < n; i ++) {
                        int cnt = 0;
                        for (int j = 0; j < 10; j ++) {
                                if (f[i][j] == 1 && use & (1 << j)) {
                                        cnt ++;
                                }
                        }
                        res += p[i][cnt];
                }                   
                ans = max(ans, res);
        }
        printf("%lld\n", ans);
        return 0;
}


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

using i64 = long long;

const i64 MOD = 1000000007;
const int N = 5000 + 7;

int n;
std::vector<int> e[N];
int fa[N], siz[N];
i64 f[N][N], g[N];
i64 dfac[N];

void dfs(int s) {
	for (auto t : e[s]) if (t != fa[s]) fa[t] = s, dfs(t);
	f[s][siz[s] = 1] = 1;
	for (auto t : e[s]) {
		if (t == fa[s]) continue;
		for (int j = 0; j <= siz[s]; ++j)
			for (int k = 0; k <= siz[t]; ++k)
				( g[j + k] += f[s][j] * f[t][k] ) %= MOD;
		siz[s] += siz[t];
		std::copy(g, g + siz[s] + 1, f[s]);
		std::fill(g, g + siz[s] + 1, 0);
	}
	for (int i = 1; i <= siz[s]; ++i)
		( f[s][0] -= f[s][i] * (i & 1 ? 0 : dfac[i - 1]) ) %= MOD;
}

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d", &n);
	for (int i = 1, u, v; i < n; ++i)
		scanf("%d%d", &u, &v), e[u].push_back(v), e[v].push_back(u);
	dfac[0] = dfac[1] = 1;
	for (int i = 2; i <= n; ++i) dfac[i] = dfac[i - 2] * i % MOD;
	dfs(1);
	printf("%lld", (MOD - f[1][0]) % MOD);
	return 0;
}

Measured memory_bytes: 195200
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
using namespace std;
int n, k, a[100], dp[100001];
int calc(int s) {
	if (s == 0) return 0;
	if (dp[s] != -1) return dp[s];
	int res = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] > s) break;
		res = max(res, 1 - calc(s - a[i]));
	}
	return dp[s] = res;
}
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	memset(dp, -1, sizeof(dp));
	if (calc(k) == 1) puts("First");
	else puts("Second");
	return 0;
}

Measured memory_bytes: 5376
from collections import defaultdict

N=input()

L=defaultdict(lambda: 0) 
for i in range(1,N+1):
    i=str(i)
    begin=int(str(i)[0])
    end=int(str(i)[-1])
    L[(begin,end)]+=1


ans=0
for begin in range(1,10):
    for end in range(1,10):
        ans+=L[(begin,end)]*L[(end,begin)]

print ans

Measured memory_bytes: 32668
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<ii> vii;

#define deb(x) cout << #x": " << (x) << endl;

const int N = 1505;
const lli INF = 1e18;
const lli MOD = 1e9+7;

vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	vi m(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}


lli SUM(lli a, lli b, lli mod=MOD){
	return (a+b+mod)%mod;
}

lli PROD(lli a, lli b, lli mod=MOD){
	a%=mod; b%=mod;
	return a*b % mod;
}

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

vvi graph(int n, int m){
	vv(int,v,n+1,0);
	fore(i,0,m){
		int a,b; cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	return v;
}

// ---- コーディングはここから！ ('-')7

void solve(){
	lli n; cin>>n;
	lli res = (powm(10,n)-PROD(2,powm(9,n))+powm(8,n)+MOD)%MOD;
	cout<<res<<ENDL;

}


int main(){_
	//int t; cin>>t; while(t--)
	// freopen("travel.in", "r", stdin);
	// freopen("travel.out", "w", stdout);
	solve();
}


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

int main() {
    string S,T;
    string subS;

    int cnt = 0;
    int min = 1000;

    cin >> S;
    cin >> T;

    for (int i=0; i<=S.size()-T.size();i++){
        subS = S.substr(i,T.size());
    //    cout << subS << endl;

        for (int j=0; j<T.size(); j++){
            if (subS.at(j) != T.at(j)){
                cnt++;
            }
        }
        
        if (cnt < min){
            min = cnt;
        }
        cnt = 0;
    }


    cout << min << endl;

}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)





int main() {
	string s;
  char t='_';
	in(s);
	rep(i,0,s.size()){
    if(t==s[i]){
      outn("Bad");
      return 0;
    }
    t=s[i];
  }
  outn("Good");
	return 0;

}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

const int MAX = 1e4+10;
const string YES = "Yes";
const string NO = "No";

int N;
ll A[MAX], B[MAX];

string solve() {
    ll sum_a = 0, sum_b = 0;
    REP (i, N) {
        sum_a += A[i];
        sum_b += B[i];
    }
    ll k = sum_b - sum_a, count_a = 0, count_b = 0;
    REP (i, N) {
        if (A[i] > B[i]) count_a += A[i] - B[i];
        else if (A[i] < B[i]) count_b += (B[i] - A[i] + 1) / 2;
    }
    if (count_a <= k && count_b <= k) return YES;
    else return NO;
}

int main() {
    cin >> N;
    REP (i, N) cin >> A[i];
    REP (i, N) cin >> B[i];
    cout << solve() << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
typedef pair<ll, bool> Pb;

const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
//↓,→,↑,←


#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= mod; b >>= 1;}(x *= a) %= mod; b--;} return x;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}
ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod;
}
*/
struct Timer {
    int64_t start;
    const int64_t CYCLES_PER_SEC = 2800000000;
    Timer() { reset(); }
    void reset() { start = getCycle(); }
    inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
    inline int64_t getCycle() {
        uint32_t low, high;
        __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
        return ((int64_t)low) | ((int64_t)high << 32);
    }
};


bool multicase = false;

ll n, m, k, w, a, b, c, d, e, h, q, ans, sum, l;

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

void solve() {
    string s, t;
    cin >> s >> t;
    n = s.size(), m = t.size();
    ll ans = INF;
    for(int i=0;i<n-m+1;i++){
        int offset = i;
        ll cnt = 0;
        for(int j=0;j<m;j++){
            if (s[j+offset] != t[j]) cnt ++;
        }
        ans = min(ans, cnt);
    }
    p(ans);
    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}



Measured memory_bytes: 3656
from itertools import product
import bisect
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
# b = list(map(lambda x: math.ceil(x/10)*10, a))


S = input()
for p in product(range(2), repeat=len(S)-1):
    tmp = ''
    for i in range(len(S)-1):
        if p[i] == 1:
            tmp += S[i]+'+'
        else:
            tmp += S[i]+'-'
    if eval(tmp+S[-1]) == 7:
        print(tmp+S[-1]+'=7')
        break


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc;

  void run() {
    for ( ;; ) {
      int N = ni();
      int M = ni();

      if ( ( N | M ) == 0 ) {
        break;
      }

      int[][] imos = new int[M + 1][1261];
      int r = ni();
      for ( int i = 0; i < r; ++i ) {
        int t = ni();
        int n = ni();
        int m = ni();
        int s = ni();

        // テ・ツ青古」ツ?蕨テ」ツ?ァテ・ツ青古ヲツ卍づ・ツ按サテ」ツ?ォテ」ツつ「テ」ツつッテ」ツつサテ」ツつケテ」ツ?凖」ツつ凝」ツ?禿」ツ?ィテ」ツ?ッテ」ツ?ェテ」ツ??」ツ?妥」ツ?ゥテ」ツ??
        // テゥツ?陛」ツ??テ」ツ?ェテ」ツつ嘉」ツ?づ」ツつ甘」ツ?暗」ツつ凝」ツ?づ」ツ?ェテ」ツ?ョテ」ツ?ァ"+="テ」ツ?ォテ」ツ?凖」ツつ凝・ツソツ?ィツヲツ?」ツ?古」ツ?づ」ツつ凝」ツ??
        // テ」ツ?敕」ツつづ」ツ?敕」ツつづィツォツ姪」ツ?ィテ」ツ?療」ツ?ヲテ」ツ?（mosテ」ツ?凖」ツつ凝」ツ?ェテ」ツつ?+="テ」ツ?療」ツつ暗」ツ??」ツ??
        imos[ m ][ t ] += s * 2 - 1;
      }

      int q = ni();
      for ( int i = 0; i < q; ++i ) {
        int ts = ni();
        int te = ni();
        int m = ni();

        int sum = 0;
        int v = 0;
        for ( int t = 540; t <= 1260; ++t ) {
          v += imos[ m ][ t ];
          if ( v > 0 && ts <= t && t < te ) {
            ++sum;
          }
        }

        System.out.println( sum );
      }
    }
  }

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }
}

Measured memory_bytes: 212412
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	sample
# CreatedDate:  2020-09-27 14:00:12 +0900
# LastModified: 2020-09-27 14:35:21 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    v_even = [v[i] for i in range(0, len(v), 2)]
    v_odd = [v[i] for i in range(1, len(v), 2)]
    even_cnt = sorted(map(list, Counter(v_even).items()), key=lambda x: x[1], reverse=True)
    odd_cnt = sorted(map(list, Counter(v_odd).items()), key=lambda x: x[1], reverse=True)
    odd_impo = 0
    even_impo = 0
    if len(even_cnt) == 1 and len(odd_cnt) == 1:
        if even_cnt[0][0] == odd_cnt[0][0]:
            if even_cnt[0][1] < odd_cnt[0][1]:
                print(even_cnt[0][1])
                return

            else:
                print(even_cnt[0][1])
                return

    if even_cnt[0][0] == odd_cnt[0][0]:
        if even_cnt[0][1] == odd_cnt[0][1]:
            if even_cnt[1][1] < odd_cnt[1][1]:
                odd_impo = 1
                even_impo = 0

            elif even_cnt[1][1] > odd_cnt[1][1]:
                odd_impo = 0
                even_impo = 1

            else:
                odd_impo = 1
                even_impo = 0

        elif even_cnt[0][1] < odd_cnt[0][1]:
            odd_impo = 0
            even_impo = 1

        else:
            odd_impo = 1
            even_impo = 0

    ans = len(v_even) - even_cnt[even_impo][1] + len(v_odd) - odd_cnt[odd_impo][1]

    print(ans)



if __name__ == "__main__":
    main()


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

#define println(msg) cout << msg << endl
#define yes_or_no(flag) if (flag) { println("Yes"); } else { println("No"); }
#define sort_vec(vec) sort(vec.begin(), vec.end())
#define rsort_vec(vec) sort(vec.rbegin(), vec.rend()) // greater<int>()

int main() {
  // 入力
  int N;
  cin >> N;

  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  
  int M;
  cin >> M;

  vector<string> t(M);
  for (int i = 0; i < M; i++) {
    cin >> t.at(i);
  }
  
  // 計算
  map<string, int> ag;
  for (auto x : s) {
    if (ag.count(x)) {
      ag[x]++;
    } else {
      ag[x] = 1;
    }
  }
  
  for (auto x : t) {
    if (ag.count(x)) {
      ag[x]--;
    } else {
      ag[x] = -1;
    }
  }
  
  int m = INT_MIN;
  for (auto p : ag) {
    if (m < p.second) {
      m = p.second;
    }
  }
  
  // 出力
  println(max(0, m));
}

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

#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int> ())
#define FOR(k, n) for(int k=0; k<n; k++)
#define pb push_back


using namespace std;
using namespace std::chrono;

char nums[10] = { '0','1','2','3','4','5','6','7','8','9' };
char alphsl[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
const ll MOD = 1000000007;
char alphs[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };



void solve() {

    int n;
    cin>>n;
    string s;
    cin>>s;
    int cntr=0;
    for(int i=0; i<n; i++){
        if(s[i]=='R') cntr++;
    }
    int ans=0;
    for(int i=0; i<cntr; i++){
        if(s[i]=='W') ans++;
    }
    cout<<ans<<endl;
}


int main() {

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

        
        solve();


    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <map>

using namespace std;

int main(int argc, const char* argv[])
{
	int C[3];
	for (auto&& c : C) cin >> c;
	map<int, int> m;
	for (auto&& c : C) m[c]++;
	int n = m.size();
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int s, w;
    cin >> s >> w;
    if(w >= s)  cout << "unsafe\n";
    else    cout << "safe\n";
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef unsigned long long ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
 
int main(){

    double l;
    cin >> l;

    double x = l * l /27 * l;

    cout << fixed << setprecision(6) << x;

   
    return 0;
 
}

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

public class Main
{

  public static void main
  (
    String[] args
  )
  {
    BufferedReader in_stream;
    String         in_str;
    String[]       in_str_split;

    int in_X;
    int in_Y;

    long cnt;
    long ans;

    try
    {
      in_stream = new BufferedReader(new InputStreamReader(System.in));

      in_str       = new String(in_stream.readLine());
      in_str_split = in_str.split(" ");

      in_X = Integer.parseInt(in_str_split[0]);
      in_Y = Integer.parseInt(in_str_split[1]);


      if(0 == (in_X % in_Y))
      {
        ans = -1;
      }
      else
      {
        ans = -1;
        for(cnt = (in_X*2); cnt<1000000000000000000L; cnt+=in_X)
        {
          if(0 != (cnt % in_Y))
          {
            ans = cnt;
            break;
          }
        }
      }


      UtilLog.ans_ln("" + ans);
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
}

class UtilLog
{
  private static boolean is_debug_mode = false;



  public static void ans_ln
  (
    String i_message
  )
  {
    System.out.println(i_message);
  }



  public static void ans_f
  (
    String i_message
  )
  {
    System.out.printf(i_message);
  }



  public static void inf_ln
  (
    String i_message
  )
  {
    StackTraceElement[] stack;


    if(is_debug_mode)
    {
    stack = new Throwable().getStackTrace();

    System.out.println
      (
        String.format
          (
            "[inf][%s:%s():%5d]",
            stack[1].getClassName(),
            stack[1].getMethodName(),
            stack[1].getLineNumber(),
            i_message
          )
      );
    }
  }
}


Measured memory_bytes: 21204
// AOJ DPL_2_C Bitonic Traveling Salesman Problem
// 2018.5.9 bal4u

#include <stdio.h>
#include <string.h>
#include <math.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in()
{
	int n = 0, c = gc();
	if (c == '-') { c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define INF    1e12
#define MAX_N  1002

int N;
int x[MAX_N], y[MAX_N];
double d[MAX_N][MAX_N];
double dd[MAX_N][MAX_N];

double dist(x1, y1, x2, y2) {
	int dx = x1-x2, dy = y1-y2;
	return sqrt(dx*dx + dy*dy);
}

double bitonic_tsp()
{
	int i, j, k, n1;
	double t, ans;

	for (j = 1; j < N; j++) {
		for (i = 0; i < j; i++) {
			if (i == 0 && j == 1) d[i][j] = dd[i][j];
			else if (i < j - 1) d[i][j] = d[i][j-1] + dd[j-1][j];
			else {
				d[i][j] = INF;
				for (k = 0; k < i; k++) {
					t = d[k][i] + dd[k][j];
					if (t < d[i][j]) d[i][j] = t;
				}
			}
		}
	}

	ans = INF, n1 = N-1;
	for (i = N-2; i >= 0; i--) {
		t = d[i][n1] + dd[i][n1];
		if (t < ans) ans = t;
	}
	return ans;
}

int main()
{
	int i, j;

	N = in();
	for (i = 0; i < N; i++) x[i] = in(), y[i] = in();
	for (i = 0; i < N; i++) for (j = i+1; j < N; j++) {
		dd[i][j] = dd[j][i] = dist(x[i], y[i], x[j], y[j]);
	}

	printf("%.10lf\n", bitonic_tsp());
	return 0;
}


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

use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a
fn main() {
    input! {
        x: usize,
    }
    let mut amount: f64 = 100.0;
    for i in 0..3760 {
        amount = (amount * 1.01).trunc();
        if amount >= x as f64 {
            println!("{}", i + 1);
            break;
        }
    }
}


Measured memory_bytes: 2644
// tested by Hightail: https://github.com/dj3500/hightail
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

int main () {
   vi v;
   wez(n);
   FOR(i,2*n) {
      wez(x);
      v.pb(x);
   }
   sort(ALL(v));
   int res = 0;
   FOR(i,n) res += v[2*i];
   pisz(res);
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

struct union_find{
    vector<int> par;
    vector<int> depth;
    vector<int> siz;

    union_find(int n) : par(n) , depth(n,0) , siz(n,1){
        rep(i,n) par[i]=i;
    }

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

    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        siz[x] +=siz[y];
        siz[y] =siz[x];
        if(depth[x]<depth[y]) par[x]=par[y];
        else{
            par[y]=par[x];
            if(depth[x]==depth[y]) depth[x] ++;
        }
    }

    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return siz[find(x)];
    }
};
//union findが必要
//無向グラフ
using T=tuple<int,int,int>;
vector<T> graph(0);//{cost,辺1,辺2}
int kruskal(int n){//頂点数
    union_find uf(n);
    sort(all(graph));
    int ret=0;
    for(auto x:graph){
        int s,t,cost;
        tie(cost,s,t)=x;
        if(!uf.same(s,t)){
            uf.unite(s,t);
            ret +=cost;
        }
    }
    return ret;
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int v,e;
    cin>>v>>e;
    int s,t,w;
    rep(i,e){
        cin>>s>>t>>w;
        graph.emplace_back(w,s,t);
    }
    int ans=kruskal(v);
    cout<<ans<<endl;
}


Measured memory_bytes: 4592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

int n;
string s;
const int maxn = 2005;
vector<int> g[maxn];

ll sumh[maxn];
int cnt[maxn];
void pre(int u, int prev = -1) {
  sumh[u] = 0;
  cnt[u] = s[u] == '1';
  for (int v : g[u]) {
    if (v == prev) {
      continue;
    }
    pre(v, u);
    sumh[u] += sumh[v] + cnt[v];
    cnt[u] += cnt[v];
  }
}

ll dfs(int u, int prev = -1) {
  ll vmax = 0;
  for (int v : g[u]) {
    if (v == prev) {
      continue;
    }
    vmax = max(vmax, sumh[v] + cnt[v]);
  }
  if (vmax * 2 <= sumh[u]) {
    return sumh[u] / 2 * 2;
  }
  ll vup = 0;
  for (int v : g[u]) {
    if (v == prev) {
      continue;
    }
    if (sumh[v] + cnt[v] == vmax) {
      vup = dfs(v, u);
    }
  }
  ll s = sumh[u] - vup;
  ll mx = vmax - vup;
  if (mx * 2 <= s) {
    return sumh[u] / 2 * 2;
  } else {
    return vup + (s - mx) * 2;
  }
}

signed main() {
#ifdef LOCAL
  assert(freopen("e.in", "r", stdin));
#endif
  cin >> n >> s;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  ll res = 1e18;
  for (int i = 0; i < n; ++i) {
    pre(i);
    ll up = dfs(i);
    if (up == sumh[i]) {
      assert(sumh[i] % 2 == 0);
      res = min(res, sumh[i] / 2);
    }
  }
  cout << (res >= 1e18 ? -1 : res) << '\n';
}


Measured memory_bytes: 512
from collections import deque

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

route = [[] for _ in range(N)]
used = [False] * N
used[0] = True

for _ in range(M):
    a, b = map(int, input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)

queue= deque([(route[0],0)])
# print(queue)

def bfs(queue):
    while queue:
        next,before = queue.popleft()
        for i in next:
            if used[i] != False:
                continue
            used[i] = before+1
            queue.append((route[i], i))

bfs(queue)

for i, v in enumerate(used):
    if i == 0:
        print("Yes")
    else:
        print(v)

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

#define NAME "A - Frog 1"
#define show(x) cout << (#x) << " is " << (x) << endl
#define ll long long
#define ms(arr,val) memset(arr,val,sizeof(arr))
#define len length()

const int maxn = 2e5;

int main(){
    //ifstream cin(NAME".inp");
    //ofstream cout(NAME".out");
    int n,k;
    cin>>n>>k;
    //show(n);
    vector<int> h(n);
    vector<int> dp(n,INT_MAX);
    dp[0]=0;
    for(int i=0;i<n;i++){
        cin>>h[i];
        for(int j=1;j<=k;j++)
            if(i-j<0)
                break;
            else if (dp[i-j] + abs(h[i]-h[i-j]) < dp[i] )
                dp[i] = dp[i-j] + abs(h[i]-h[i-j]);

    }
    cout<<dp[n-1];

}


Measured memory_bytes: 3996
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
int main(void){
    int n,m;cin>>n>>m;
    if(n==m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

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

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

    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    ll ans = A[0];
    for (int i = 0; i < N; i++)
    {
        ans = gcd(ans, A[i]);
    }
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 640
n = int(input())

l = len(str(n))
top = n // (10**(l-1))

s = 0
for i in range(l):
	s += int(str(n)[i])

if top == 1:
	print(max(9 * (l - 1), s))
else:
	print(max(top - 1 + 9 * (l - 1), s))

Measured memory_bytes: 3060