akhauriyash/Code-Regression huggingface dataset:
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main() 
{
    //int t; cin >> t; while(t--) 
    {
        int n;
    	cin >> n;
    	vector<pair<int, int>> a(n);
    	for (int i = 0; i < n; i++) {
    		cin >> a[i].first;
    		a[i].second = i;
    	}
    	sort(a.begin(), a.end());
        
        int dp[n][n] = {};
        for (int i = 0; i < n; i++)
            dp[i][i] = a[0].first * abs(a[0].second - i);
            
        for (int k = 1; k < n; k++) {
        	for (int i = 0; i + k < n; i++) {
                int j = i + k;
                dp[i][j] = max(dp[i + 1][j] + abs(i - a[k].second) * a[k].first, 
                                dp[i][j - 1] + abs(j - a[k].second) * a[k].first);
            }
        }

        cout << dp[0][n - 1] << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 34884
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
 
int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    if(K>A)
    {
        cout << 0 << " " << max(0LL, B-(K - A));
    }
    else
    {
        cout <<A-K<< " " << B;
    }
 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[100],b[100],c[200];
int main(){
	cin>>a;
	cin>>b;
	int lena=strlen(a);
	int lenb=strlen(b);
	for(int i=0;i<lenb;i++)
		cout<<a[i]<<b[i];
	if(lena>lenb)
		cout<<a[lena-1];
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,k;
	cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++)cin>>h[i];
	
	int dp[n];fill(dp, dp+n, INT_MAX);
	dp[0]=0;
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<=min(i,k);j++)
		dp[i]=min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
		
	}
	
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
a=list()
b=list()

for i in range(n):
    a.append(list(map(int, input().split())))

for j in range(m):
    b.append(int(input()))

for k in range(n):
    ans=0
    for l in range(m):
        ans += a[k][l]*b[l]
    print(ans)


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

using namespace std;
typedef long long LL;
static long long INF = (1LL<<62);

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N, X, M;
	cin >> N >> X >> M;

	vector<LL> v;
	map<LL, int> m;
	LL a = X;
	v.push_back(a);
	m[a] = 1;
	LL c = 1;
	int loop = 0;
	LL base = -1;
	for(LL c=1; c<N; c++){
		a = (a*a)%M;
		if(a == 0) break;
		if(m.count(a) == 0){
			m[a] = 1;
			v.push_back(a);
		}
		else{
			base = a;
			loop = 1;
			break;
		}
	}
	LL ans = 0;
	if(loop == 0){
		for(auto itr = m.begin(); itr != m.end(); itr++){
			LL k = itr->first;
			ans += k;
		}
		printf("%lld\n", ans);
		return 0;
	}

	LL lpos = -1;
	for(int i=0; i<v.size(); i++){
		if(v[i] == base){
			lpos = i;
			break;
		}
		else{
			ans += v[i];
		}
	}
	N -= lpos;
	LL loopsum= 0;
	for(int i=lpos; i<v.size(); i++){
		loopsum += v[i];
	}
	LL s = v.size() - lpos;
	LL q = N / s;
	LL r = N % s;
	ans += q*loopsum;
	for(int i=lpos; i<lpos+r; i++){
		ans += v[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6808
n,m=map(int,input().split())
cnt=1
if abs(n-m)>1:print(0);exit()
elif (n+m)%2==1:
    for i in range(n):
        cnt *=(i+1)
        if cnt>=10**9+7:cnt %=10**9+7
    for j in range(m):
        cnt *=(j+1)
        if cnt >= 10 ** 9 + 7: cnt %= 10 ** 9 + 7
    print(cnt)
else:
    cnt *=(n+m)
    n -=1
    for i in range(n):
        cnt *=(i+1)
        if cnt >= 10 ** 9 + 7: cnt %= 10 ** 9 + 7
    for j in range(m):
        cnt *=(j+1)
        if cnt >= 10 ** 9 + 7: cnt %= 10 ** 9 + 7
    print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if((a+k>=b) and (a+k>=c) and (a+k>=d) and (a+k>=e)){
    cout<<"Yay!";
  }else{
    cout<<":(";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int p[40];
bool bf() {
	for (int i = 2; i < 10; i++)if (p[i] != p[1])return 0;
	for (int i = 10; i <= 19; i += 3)if (p[i] != p[i + 1] || p[i] != p[i + 2])return 0;
	for (int i = 23; i <= 30; i++)if (p[i] != p[22])return 0;
	return 1;
}
void f2() {
	swap(p[1], p[28]);
	swap(p[2], p[29]);
	swap(p[3], p[30]);
	swap(p[15], p[16]);
	swap(p[19], p[21]);
	return;
}
void f4() {
	swap(p[1], p[24]);
	swap(p[4], p[27]);
	swap(p[7], p[30]);
	swap(p[10], p[21]);
	swap(p[16], p[18]);
	return;
}
void f6() {
	swap(p[3], p[22]);
	swap(p[6], p[25]);
	swap(p[9], p[28]);
	swap(p[12], p[19]);
	swap(p[13], p[15]);
	return;
}
void f8() {
	swap(p[7], p[22]);
	swap(p[8], p[23]);
	swap(p[9], p[24]);
	swap(p[13], p[18]);
	swap(p[10], p[12]);
	return;
}
int solve(int b, int d) {
	if (d > 8)return 100;
	if (bf())return d;
	int r = 100;
	for (int i = 0; i <= 3; i++) {
		if (i != b) {
			if (i == 0)f2();
			if (i == 1)f4();
			if (i == 2)f6();
			if (i == 3)f8();
			r = min(r, solve(i, d + 1));
			if (i == 0)f2();
			if (i == 1)f4();
			if (i == 2)f6();
			if (i == 3)f8();
		}
	}
	return r;
}
signed main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		for (int i = 1; i <= 30; i++)cin >> p[i];
		cout << solve(4, 0) << endl;
	}
}


Measured memory_bytes: 3092
# -*- coding: utf-8 -*-

import sys
import os
import re

def is_win(A, B, C, sign):
    if A[0] == A[1] == A[2] == sign or B[0] == B[1] == B[2] == sign or C[0] == C[1] == C[2] == sign:
        return True
    elif A[0] == B[0] == C[0] == sign or A[1] == B[1] == C[1] == sign or A[2] == B[2] == C[2] == sign:
        return True
    elif A[0] == B[1] == C[2] == sign or A[2] == B[1] == C[0] == sign:
        return True
    else:
        return False

for s in sys.stdin:
    s = s.strip()
    A = s[0:3]
    B = s[3:6]
    C = s[6:9]

    if is_win(A, B, C, 'o'):
        print('o')
    elif is_win(A, B, C, 'x'):
        print('x')
    else:
        print('d')

Measured memory_bytes: 7548
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
// using namespace boost::multiprecision;

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
// using int128 = __int128;
// using cint = cpp_int;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define input(a) scanf("%lld", &(a))
#define output(a) printf("%lld\n", (a))
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC optimization_level 3
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll N, S;
vector<vector<ll>> A;

signed main() {
    cin >> N;
    ll P = sqrt(2 * N);
    if ((2 * N % P != 0) || ((2 * N) / P - P != 1)) {
        cout << "No" << endl;
        return 0;
    } else {
        cout << "Yes" << endl;
    }
    rep(i, P + 1) A.push_back({});
    rep(i, P + 1) {
        inc(j, i + 1, P) {
            A[i].push_back(S);
            A[j].push_back(S);
            S++;
        }
    }
    cout << P + 1 << endl;
    rep(i, P + 1) {
        cout << P;
        rep(j, P) cout << ' ' << A[i][j] + 1;
        cout << endl;
    }
}

// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++17


Measured memory_bytes: 3200
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	String[] input = scan.nextLine().split(" ");
	int[] elements = new int[n];
	for (int i = 0; i < n; i++) {
	    elements[i] = Integer.parseInt(input[i]);
	}
	int cnt = 0;
	boolean flag = true;
	while (flag) {
	    flag = false;
	    for (int i = n-1; i > 0; i--) {
		if (elements[i] < elements[i-1]) {
		    int tmp = elements[i];
		    elements[i] = elements[i-1];
		    elements[i-1] = tmp;
		    cnt++;
		    flag = true;
		}
	    }
	}
        for (int i = 0; i < n-1; i++){
	    System.out.print(elements[i] + " ");
	}
	System.out.println(elements[n-1]);
	System.out.println(cnt);
    }
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


ll mpow(ll m, ll p){
  ll power = m;
  ll res = 1;
  while(p>0){
    if(p&1)
      res = res*power%MOD;
    power = (power*power)%MOD;
    p /= 2;
  }

  return res;
}

ll mod_inv(ll m){
  return mpow(m, MOD-2);
}

struct COM{
  vll fact, fact_inv;
  COM(ll n): fact(n+1,1), fact_inv(n+1,1){
    for(ll i=1; i<=n; i++)
      fact[i] = fact[i-1]*i%MOD;

    fact_inv[n] = mod_inv(fact[n]);
    for(ll i=n; i>=1; i--)
      fact_inv[i-1] = fact_inv[i]*i%MOD;
  }

  ll calc(ll n, ll k){
    if(k<0 || n<k)
      return 0;
    ll res = fact[n]*fact_inv[n-k]%MOD*fact_inv[k]%MOD;
    return res;
  }
};

const ll MAX_N=2*1e5+1;
COM com(MAX_N);

struct DP{
  ll num;
  ll pattern;
  DP(ll num=0, ll pattern=1):num(num),pattern(pattern){
  }
  DP addRoot() const{
    DP res(*this);
    res.num++;
    return res;
  }

  DP& operator+=(const DP& obj){
    num+=obj.num;
    pattern=pattern*com.calc(num,obj.num)%MOD;
    pattern=pattern*obj.pattern%MOD;
    return *this;
  }

  DP operator-(const DP& obj) const{
    DP res(*this);
    res.pattern=res.pattern*mod_inv(com.calc(res.num,obj.num))%MOD;
    res.pattern=res.pattern*mod_inv(obj.pattern)%MOD;
    res.num-=obj.num;
    return res;
  }
};



DP dp[MAX_N];
vvll edge(MAX_N);

void dfs(ll st, ll par){
  DP res;
  for(auto e:edge[st]){
    if(e==par)
      continue;
    dfs(e,st);
    res+=dp[e].addRoot();
  }

  dp[st]=res;
}

void dfsRev(ll st, ll par){
  for(auto e:edge[st]){
    if(e==par)
      continue;
    DP d=dp[st]-dp[e].addRoot();
    dp[e]+=d.addRoot();
    dfsRev(e,st);
  }
}

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

  ll n;
  cin>>n;
  REP(i,n-1){
    ll a,b;
    cin>>a>>b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  dfs(0,-1);
  dfsRev(0,-1);
  REP(i,n)cout<<dp[i].addRoot().pattern<<endl;



}



Measured memory_bytes: 20976
#include<cstdio>
#include<algorithm>
#define N 600010
using namespace std;

int n;
int a[N],b[N];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	int l=300000-1,r=300000;
	for(int i=1;i<=n;i++){
		if(i&1){
			b[r]=a[i];
			r++;
		}else{
			b[l]=a[i];
			l--;
		}
	}
	if(n&1){
		reverse(b+l,b+r+1);
	}
	for(int i=l+1;i<=r-1;i++){
		printf("%d ",b[i]);
	}
	return 0;
}

Measured memory_bytes: 4864
def list_maker(num):
    num_list = []
    for i in range(1, num + 1):
        num_list.append(i)
    return num_list


a, b, c = map(int, input().split())

num_list = list_maker(c)
divisor_list = []

for i in num_list:
    if c % i == 0:
        if i >= a and i <= b:
            divisor_list.append(i)

print(len(divisor_list))


Measured memory_bytes: 5716
using System;
class Program
{
    static void Main()
    {
        int n;
        n = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(' ');
        int[] l = new int[n];
        for(int i=0;i<n;i++){
            l[i] = int.Parse(s[i]);
        }
        Array.Sort(l);
        int sum = 0;
        for(int i=0;i<n-1;i++)
        {
            sum += l[i];
        }
        if(l[n-1] < sum)
        {
            Console.Write("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
#coding: utf-8

N, X = (int(x) for x in input().split())
A = [int(x) for x in input().split()]

diffs = []
for i in range(N-1):
    diffs.append(A[i]+A[i+1] - X)

ret = 0
for i in range(N-1):
    tmp = min(diffs[i], A[i+1])
    ret += tmp
    diffs[i]   -= tmp
    if i+1 < len(diffs):
        diffs[i+1] -= min(tmp, diffs[i+1]) 
    ret += diffs[i]

print(max(0, ret))



Measured memory_bytes: 20048
#include <bits/stdc++.h>
using namespace std;
int dp1 [10000007];
int dp2 [10000007];

int frog ( int i , int n)
{
if ( i == n)return 0;
if (dp1 [i] != -1)return dp1 [i];
int s;
s = abs (dp2 [i] - dp2 [i + 1]) + frog (i + 1 , n);
if (i + 2 <= n)
{
s = min (s , abs (dp2 [i] - dp2 [i + 2]) + frog (i + 2 ,n));

}
return dp1 [i] = s;
}
int main ()
{
//int i;
int n;
cin >> n;
for (int i = 1;i<= n;i++)
{
cin >> dp2 [i];
}
for (int j = 0;j < 10000007;j++)
{
dp1 [j] = -1 ;
}
cout << frog (1 , n)<<'\n';




}

Measured memory_bytes: 49228
#include <stdio.h>

int interest(int debt);

int main(void){
	int n, i, debt = 100000;
	scanf("%d", &n);

	for(i = 0;i < n;i++){
		debt = interest(debt);
	}

	printf("%d\n", debt);

	return 0;
}

int interest(int debt){
	debt *= 1.05;
	if(debt % 1000 != 0){
		debt += 1000;
	}
	debt = debt / 1000 * 1000;

	return debt;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define endl "\n"
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define ss second
#define ff first
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
 
int main() {
    io;

    int n;
    cin>>n;
    vector<int> arr1(n),arr2(n),temp;
    rep(i,0,n) cin>>arr1[i];
    rep(i,0,n) cin>>arr2[i];

    temp = arr1;
    sort(temp.begin(),temp.end());
    int a=0;
    do{
        if(temp==arr1){
            break;
        } 
        a++;
    }while(next_permutation(temp.begin(),temp.end()));

    sort(temp.begin(),temp.end());
    int b=0;
do{
        if(temp==arr2){
            break;
        } 
        b++;
    }while(next_permutation(temp.begin(),temp.end()));

    cout<<abs(a-b)<<endl;

 
 
 
    
 
    return 0;
}

Measured memory_bytes: 256
n=int(input())
cnt=0
while 2**cnt-1<n:
  cnt+=1
cnt-=1
graph=[]
for i in range(cnt):
  graph.append((1+i,2+i,2**i))
  graph.append((1+i,2+i,0))
existmax=2**cnt-1
for i in range(1,cnt+1)[::-1]:
    if 2**(i-1)-1+existmax+1<=n-1:
        graph.append((i,cnt+1,existmax+1))
        existmax=existmax+1+2**(i-1)-1
L=len(graph)
print(cnt+1,L)
for i in graph:
  print(*i)


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

using namespace std;
using ll = long long;

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

int f(int k) {
  int cnt = 0;
  while (k > 0) {
    k %= __builtin_popcount(k);
    ++cnt;
  }
  return cnt;
}

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

  vector<int> x(n);
  rep(i, n) x[i] = s[i] - '0';

  int pc = 0;
  rep(i, n) pc += x[i];

  vector<int> ans(n);
  rep(b, 2) {
    int npc = pc + (b == 0 ? 1 : -1);
    if (npc <= 0) continue;
    int r0 = 0;
    rep(i, n) {
      r0 = r0 * 2 % npc;
      r0 += x[i];
    }
    int k = 1;
    for (int i = n - 1; i >= 0; --i) {
      if (x[i] == b) {
        int r = r0;
        if (b == 0)
          r = (r + k) % npc;
        else
          r = (r - k + npc) % npc;
        ans[i] = f(r) + 1;
      }
      k = k * 2 % npc;
    }
  }

  rep(i, n) cout << ans[i] << endl;

  return 0;
}


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

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

const ll mod =  1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

vector<int> g[8];
bool visited[8];
int ans = 0;
int n;

void dfs(int now){
    visited[now] = true;
    bool ok = true;
    for(int i = 0; i < n; i++){
        if(!visited[i]) ok = false;
    }
    if(ok) ans++;
    for(auto next : g[now]){
        if(!visited[next]){
            visited[next] = true;
            dfs(next);
            visited[next] = false;
        }
    }
}


int main()
{
    int m;
    cin >> n >> m;
    
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i,8) visited[i] = false;
    dfs(0);
    cout << ans;
}


Measured memory_bytes: 256
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = myconv(next(),4);
  var H = one[0];
  var W = one[1];
  var queue = new Array(1000000);
  var qIndex = 0;
  var masu = new Array(H);
  var dy = [-1,0,1,0];
  var dx = [0,-1,0,1];
  for(var i = 0; i < H; i++){
    masu[i] = myconv(next(),6);
  }
  for(var i = 0; i < H; i++){
    for(var j = 0; j < W; j++){
      if(masu[i][j] == "#"){
        for(var k = 0; k < 4; k++){
          var nextY = i + dy[k];
          var nextX = j + dx[k];
          if(nextY >= 0 && nextY < H && nextX >= 0 && nextX < W){
            if(masu[nextY][nextX] == "."){
              queue[qIndex] = [i,j];
              masu[i][j] = 0;
              qIndex++;
            }
          }
        }
      }
    }
  }
  var output = 0;
  var index = 0;
  
  while(queue[index] != null){
    var tmpQ = queue[index];
    index++;
    var y = tmpQ[0];
    var x = tmpQ[1];
    output = Math.max(output, masu[y][x]);
    for(var i = 0; i < 4; i++){
      var nextY = y + dy[i];
      var nextX = x + dx[i];
      if(nextY >= 0 && nextY < H && nextX >= 0 && nextX < W){
        if(masu[nextY][nextX] == "."){
          queue[qIndex] = [nextY,nextX];
          masu[nextY][nextX] = masu[y][x] + 1;
          qIndex++;
        }
      }
    }
  }
  myout(output);
}


Measured memory_bytes: 164024
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

ll w[110][110];
ll d[110], f[110];
int color[110];
ll n, tt;
int White = 0, Gray = 1, Black = 2;

void dfs_visit(int u){
    int v;
    color[u] = Gray;
    d[u] = ++tt;
    Rep(v, 1, n){
        if(w[u][v] == 0) continue;
        if(color[v] == White){
            dfs_visit(v);
        }
    }
    color[u] = Black;
    f[u] = ++tt;
}

void dfs(){
    Rep(i, 1, n) color[i] = White; // 0:未訪問 1:訪問途中 2:訪問済
    
    tt = 0;
    Rep(u, 1, n){
        if(color[u] == White) dfs_visit(u);
    }

    Rep(i, 1, n){
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

}

void solve() {
    cin >> n;
    Rep(i, 1, n) Rep(j, 1, n) w[i][j] = 0;
    Rep(i, 1, n){
        ll u, k; cin >> u >> k;
        rep(i, 0, k){
            ll v; cin >> v;
            w[u][v] = 1;
        }
    }

    dfs();

    return;
}

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

    solve();
    return 0;
}



Measured memory_bytes: 3236
import qualified Data.ByteString.Char8 as BS
import qualified Data.Maybe as MA

main = do
    (x, _) <- MA.fromJust . BS.readInt <$> BS.getLine
    let a = x `div` 500 * 1000
    let b = x `mod` 500 `div` 5 * 5
    putStrLn . show $ a + b


Measured memory_bytes: 380
using System;

class Program
{
	static void Main(string[] args)
	{
		string[] strInput = Console.ReadLine().Split(' ');
		Int64 a = Int64.Parse(strInput[0]);
		Int64 v = Int64.Parse(strInput[1]);
		strInput = Console.ReadLine().Split(' ');
		Int64 b = Int64.Parse(strInput[0]);
		Int64 w = Int64.Parse(strInput[1]);
		Int64 t = Int64.Parse(Console.ReadLine());

		Int64 vel_diff = v - w;
		Int64 distance = Math.Abs(a - b);
		if (vel_diff <= 0)
		{
			Console.WriteLine("NO");
			return;
		}
		else
		{
			if(distance <= t * vel_diff)
			{
				Console.WriteLine("YES");
				return;
			}
		}

		Console.WriteLine("NO");
		return;
	}
}

Measured memory_bytes: 27496
n,x=map(int,input().split())
while n!=0 or x!=0:
    icnt=0
    for i in range(1,n-1):
        for ii in range(i+1,n):
            if x-i-ii>ii and x-i-ii<=n:
#                print(x,i,ii,x-i-ii)
                icnt+=1
    print(icnt)
    n,x=map(int,input().split())


Measured memory_bytes: 5596
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;
#define ul unsigned long long

#define rup(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define rdn(i, a, b) for(int (i) = (a); (i) > (b); (i)--)

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> l = vector<int>(n, 0);
	rup(i, 0, n) cin >> l[i];
	sort(l.begin(), l.end());
	
	int sum = 0;
	int length = l.size() - 1;
	for (int i = length; i > length - k; i--) {
		sum += l[i];
	}

	cout << sum;

	return 0;
}





Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm;

void main() {
    int n;
    int[] a;

    scan(n);
    a = iota(n).map!(i => readln.chomp.to!int).array;

    auto dp = repeat(10^^9 + 7, n + 2).array.assumeSorted;
    dp[0] = -1;

    int ans = 1;

    foreach (i ; 0 .. n) {
        auto j = dp.lowerBound(a[i]).length.to!int;
        dp[j] = a[i];
        ans = max(ans, j);
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.array : split;
    import std.conv  : to;
    import std.range.primitives;

    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

int main() {

  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;

  if( b % d > 0 ) {
    b = b / d + 1;
  } 
  else {
    b = b / d;
  }

  if( c % e > 0 ) {
    c = c / e + 1;
  } 
  else {
    c = c / e;
  }

  cout << a - max(b, c) << endl;
}

Measured memory_bytes: 1164
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
using Graph = vector<vector<pair<int,int>>>;

int main(){
    int n;
    cin >> n;
    Graph G(n);
    REP(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(make_pair(b,i));
        G[b].push_back(make_pair(a,i));
    }
    vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
    queue<pair<int,int>> que;
    int answer[n-1];

    dist[0] = 0;
    
    int max_ad = 0;

    REP(i,n){
        max_ad = max(max_ad,(int)G[i].size());
    }
    que.push(make_pair(0,-1)); // 0 を橙色頂点にする
    // BFS 開始 (キューが空になるまで探索を行う)
    int color = max_ad-1;
    while (!que.empty()) {
        pair<int,int> v = que.front(); // キューから先頭頂点を取り出す
        que.pop();
        // v から辿れる頂点をすべて調べる
        for (pair<int,int> nv : G[v.first]) {
            if (dist[nv.first] != -1) {
                continue; // すでに発見済みの頂点は探索しない
            }

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv.first] = dist[v.first] + 1;

            // 色の更新
            color = (color+1)%max_ad;
            if(v.second == color){
                color = (color+1)%max_ad;
                //cout << "a" << endl;
            }
            // 答えの格納

            answer[nv.second]=color;
            que.push(make_pair(nv.first,color));
        }
    }

    cout << max_ad << endl;

    REP(i,n-1){
        cout << answer[i]+1 << endl;
    }


    return 0;
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e5;
int main()
{
    FASTINOUT;
    int x,m,k,c=0,y;
    cin>>x>>m>>k;
    for (int i=0;i<m;i++){
        cin>>y;
        if (y<k)
            c++;
    }
   cout<<min(c,m-c)<<endl;
    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
h = list(map(int,input().split()))

data = [0]*n
#print(h)
#print(data)
for i in range(m):
    a,b = map(int,input().split())
    k = max(data[a-1],h[b-1])
    l = max(h[a-1],data[b-1])
    data[a-1],data[b-1] =k,l

ans = 0

#print(data)
for i in range(n):
    if h[i] > data[i]:
        ans += 1

print(ans)


Measured memory_bytes: 86232
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author:   bebebe
# Created:  2019-10-27
#

import math

obj = input().strip().split(' ')
a, b, x = list(map(int, obj))

# x > 1/2
if x > a * a * b * 0.5:
    ret = math.degrees(math.atan( 2 * b / a - 2 * x / (a * a * a)))
    print('{:.10f}'.format(ret))

else:
    ret = math.degrees(math.atan((a * b * b) / (2 * x)))
    print('{:.10f}'.format(ret))




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

int main() {
    int N; cin >> N;
    int t = N % 10;
    if (t == 3) {
        cout << "bon" << endl;
    } else if (t == 0 || t == 1 || t == 6 || t == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define NIL -1
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<char>>;
using P =pair<int,int>;

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

int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    ll div=abs(x)/d;
    if(div==0){
        if(k%2==0){
            cout<<abs(x)<<endl;
        }else{
            cout<<d-abs(x)<<endl;
        }
    }else if(div>k){
        cout<<abs(x)-d*k<<endl;
    }else{
        if((k-div)%2==0){
            cout<<abs(x)-d*div<<endl;
        }else{
            cout<<abs(abs(x)-d*(div+1))<<endl;
        }
    }
    return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    int k = 1;
  	int c = b;
    rep(i,2){
        if(c/10 != 0){
            k++;
            c /= 10;
        }
        else break;
    }
    int r = pow(10,k);
    int s = a*r+b;
    rep(i,350){
        int x = pow(i,2);
        if(x == s){
            cout << "Yes" << endl;
            return 0;
        }
        if(x > s) break;
    }
    cout << "No" << endl;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int n, k;
    cin >> n >> k;

    vector<int> l(n);
    for(int in=0;in<n;in++) {
        cin >> l.at(in);
    }

    sort(l.begin(), l.end(), greater<int>());

    int ans = 0;
    for(int ik=0;ik<k;ik++) {
        ans += l.at(ik);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  if(S == "Sunny")
    cout << "Cloudy" << endl;
  else if(S == "Cloudy")
    cout << "Rainy" << endl;
  else
    cout << "Sunny" << endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val h = sc.nextInt()
    val a = sc.nextInt()
    println(problem153a(h, a))
}

fun problem153a(h: Int, a: Int): Int {
    return h / a + if (h % a != 0) 1 else 0
}

Measured memory_bytes: 29604
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, K;
	cin >> N >> K;

	string S;
	cin >> S;

	Int sector = 0;
	char temp = S[0];

	for (Int i = 1; i < N; i++) {
		if (S[i] == temp)continue;
		else {
			sector++;
			temp = S[i];
		}
	}

	Int ans;
	ans = (N - 1) - max(0LL, sector - 2 * K);

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

Measured memory_bytes: 512
P,L="+<"
p=print
r=range
p(6484,P,0,1,3,L,2,3,3,P,0,3,0,P,1,3,1)
for x in 0,1:[p(P,v:=x+4,v,v,P,v,3,6,*[P,6,6,6]*(29-t),L,6,x,T:=x*60+9+t,P,v,T,v)for t in r(30)]
for t in r(60):p(P,2,2,2);[p(P,8+t-s,69+s,5,L,3,5,6,P,2,6,2)for s in r(t)]

Measured memory_bytes: 9332
#include<bits/stdc++.h>
using namespace std;
int N,H,W,A,B,ans=0;
int main(){
  cin >> N >> H >> W;
  for(int i=0;i<N;i++){
    cin >> A >> B;
    if(A>=H && B>=W) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int x1, y1, x2, y2; readV(x1, y1, x2, y2);
  x2 -= x1; y2 -= y1;

  auto x4 = -y2, y4 = x2;
  if (x2*y4-y2*x4 < 0) { x4 = -x4; y4 = -y4; }

  auto x3 = x2+x4, y3 = y2+y4;

  writefln("%d %d %d %d", x3+x1, y3+y1, x4+x1, y4+y1);
}


Measured memory_bytes: 256
s = input()

if s[-1] == 'B':
   new = 'W'
else:
   new = 'B'

if s == s[0] * len(s):
   print(0)
   exit()

ans = 0
for i in reversed(range(len(s)-1)):
   if s[i] == new:
      ans += 1
      if new == 'B':
         new = 'W'
      else:
         new = 'B'
print(ans)


Measured memory_bytes: 9132
#include "bits/stdc++.h"
using namespace std;
int l[200010], r[200010];

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d %d", &l[i], &r[i]);
		if(l[i] > r[i]) swap(l[i], r[i]);
	}
	int maxid = 0;
	int minid = 0;
	for(int i = 1; i <= n; i++) {
		if(maxid == 0 || r[maxid] < r[i]) maxid = i;
		if(minid == 0 || l[minid] > l[i]) minid = i;
	}
	int mn = INT_MAX;
	int mx = INT_MIN;
	for(int i = 1; i <= n; i++) {
		mn = min(mn, r[i]);
		mx = max(mx, l[i]);
	}
	long long ans = 1LL * (r[maxid] - mn) * (mx - l[minid]);
	if(maxid == minid) {
		printf("%lld\n", ans);
		exit(0);
	}

	typedef pair <int, int> pii;
	vector <pii> Q;


	mn = min(l[maxid], r[minid]);
	mx = max(l[maxid], r[minid]);
	int opt = INT_MAX;

	for(int i = 1; i <= n; i++) {
		if(i == maxid || i == minid) {
			continue;
		}
		Q.push_back(pii(r[i], l[i]));
	}
	sort(Q.begin(), Q.end());	
	for(int i = 0; i < n-2; i++) {
		swap(Q[i].second, Q[i].first);
	}
	int suffMin = INT_MAX;
	int suffMax = INT_MIN;

	for(int i = n-3; i >= 0; i--) {
		int Max = max(mx, Q[i].second);
		int Min = min(mn, Q[0].second);
		// for(int j = i + 1; j < n-2; j++) {
		//	Min = min(Min, Q[j].first);
		// 	Max = max(Max, Q[j].first);
		// }
		Max = max(Max, suffMax);
		Min = min(Min, suffMin);
		opt = min(opt, Max - Min);
		suffMin = min(suffMin, Q[i].first);
		suffMax = max(suffMax, Q[i].first);
	}
	ans = min(ans, 1LL * opt * (r[maxid] - l[minid]));
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3956
n = gets.to_i
as = gets.chomp.split.map(&:to_i)
m = gets.to_i
bs = gets.chomp.split.map(&:to_i)
array = Array.new(10 ** 5){Array.new()}

bs.each_with_index do |b,i|
	array[b] << i
end

ans = Array.new(m,"no")

(2 ** n).times do |i|
	sum = 0
	n.times do |j|
		if i[j] == 1
			sum += as[j]
		end
	end
	array[sum].each do |a|
		ans[a] = "yes"
	end
end

puts ans


Measured memory_bytes: 12132
#include<iostream>
#include<vector>
#include<algorithm>
#include<deque>
#include<climits>
#include<cassert>
#include<cmath>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 110

using namespace std;

int V,E,ans;
vector<int> G[MAX];
int COST[MAX][MAX];
bool used[MAX];

void dfs(int node,deque<int>& deq,int sp){
  if(node >= 15)return;

  if(node >= 2){
    auto check = [&]()mutable->int{
      int ret = 0,len = deq.size();
      int mincost[len];
      //for(int& i : mincost)i = IINF;
      rep(i,len)mincost[i] = IINF;
      for(int i=0;i<len;i++){
	for(int j=i+1;j<len;j++){
	  int cost = COST[deq[i]][deq[j]];
	  if(cost==0)return -1;
	  mincost[i] = min(mincost[i],cost);
	  mincost[j] = min(mincost[j],cost);
	}
      }
      //for(int& i : mincost) ret += i;
      rep(i,len) ret += mincost[i];
      return ret;
    };
    int tmp = check();
    if(tmp != -1)ans = max(ans,tmp);
  }

  REP(i,sp,V){
    if(used[i])continue;
    if(G[i].size() < node)continue;
    used[i] = true;
    deq.push_back(i);
    dfs(node+1,deq,i+1);
    deq.pop_back();
    used[i] = false;
  }
}

int main()
{
  cin >> V >> E;
  rep(i,V)G[i].clear();
  rep(i,E){
    int u,v,f;
    cin >> u >> v >> f;
    u--,v--;
    G[u].push_back(v);
    G[v].push_back(u);
    COST[u][v] = COST[v][u] = f;
  }

  deque<int> deq;
  dfs(0,deq,0);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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

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 long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}


int main() {
    double a,b,h,m,tyou,ta,ans;
    cin >> a >> b >> h >> m;
    tyou = (60*h)+m;
    tyou /= 2;
    ta = 6*m;
    tyou = tyou*M_PI/180;
    ta = ta*M_PI/180;
    ans = a*a+b*b-2*a*b*cos(tyou-ta);
    ans = sqrt(ans);
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

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

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, q; cin >> n >> q;
	set<pair<int, int>> se[2];
	se[0].insert({n, n});
	se[1].insert({n, n});
	long long ans = 1LL * (n - 2) * (n - 2);
	while (q--) {
		int ty, i; cin >> ty >> i;
		ty--;
		auto it = se[ty].lower_bound({i, -1});
		int k = (*it).second;
		ans -= k - 2;
		se[ty ^ 1].insert({(k - 1), i});
	}
	cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 12988
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const ll LLINF = 1e18;


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

	vector<int> c(n), s(n), f(n);
	for (int i = 0; i < n-1; i++){
		cin >> c[i] >> s[i] >> f[i];
	}

	for (int i = 0; i < n; i++){
		int temp = 0;
		for (int now = i; now < n-1; now++){
			while (1){
				if (temp < s[now]){
					temp = s[now];
				}
				if (temp % f[now] == 0){
					break;
				}
				temp++;
			}
			temp += c[now];
		}
		cout << temp << endl;
	}
	return 0;
}

Measured memory_bytes: 3492
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main() {
    int N;
    cin>>N;
    double x[N], y[N];
    for(int i=0;i<N;++i){
        cin>>x[i]>>y[i];
    }
    double sum = 0;
    for(int i=0;i<N;++i){
        for(int j=0;j<N;++j){
            sum += sqrt(pow(x[i]-x[j], 2) + pow(y[i]-y[j], 2));
        }
    }
    cout<<setprecision(20)<<sum/N<<endl;
}


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

int main()
{
ll a , b ;
cin >> a >> b ;
ans=max(0LL,a-2*b);
cout << ans << endl;
return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll K;
    cin >> K;
    if(K % 2 == 0 || K % 5 == 0) {
        cout << -1 << endl;
        return 0;
    }
    if(K % 7 == 0) K /= 7;
    K *= 9;
    ll temp = 1;
    ll index = 1;
    while(true) {
        temp = 10 * temp % K;
        if(temp == 1) break;
        index++;
    }
    cout << index << endl;
    return 0;
}


Measured memory_bytes: 3624
#pragma GCC optimize("Ofast","inline")
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=a;i<=b;i++)
#define Fod(i,b,a) for (int i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define _SEED_ ('C'+'L'+'Y'+'A'+'K'+'I'+'O'+'I')
#define outval(x) printf(#x" = %d\n",x)
#define outvec(x) printf("vec "#x" = ");for (auto _v : x)printf("%d ",_v);puts("")
#define outtag(x) puts("----------"#x"----------")
#define outarr(a,L,R) printf(#a"[%d...%d] = ",L,R);\
						For(_v2,L,R)printf("%d ",a[_v2]);puts("");
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=18;
int n;
int A,B;
int a[1<<N];
int p[N];
void outbin(int x){
	Fod(i,n-1,0)
		putchar('0'+(x>>i&1));
	puts("");
}
int cnt1(int x){
	int res=0;
	while (x)
		x-=x&-x,res++;
	return res;
}
int gray(int x){
	return (x>>1)^x;
}
void solve(int *a,int d,int v){
	if ((v&-v)==v){
		For(i,0,(1<<(d+1))-1)
			a[i]=gray(i);
//		printf("solve(%d,%d): ",d,v);outarr(a,0,(1<<(d+1))-1);
		return;
	}
	For(i,0,(1<<d)-1)
		a[i]=gray(i);
	int tmp=gray(1<<d);
	v^=tmp;
	int p[N],pc=0;
	For(i,0,d-1)
		if (~v>>i&1)
			p[pc++]=i;
	For(i,0,d-1)
		if (v>>i&1)
			p[pc++]=i;
	int _v=0;
	For(i,0,d-1)
		_v|=(v>>p[i]&1)<<i;
	solve(a+(1<<d),d-1,_v);
	For(i,(1<<d),((1<<(d+1))-1)){
		int val=0;
		For(j,0,d-1)
			val|=(a[i]>>j&1)<<p[j];
		a[i]=val^tmp;
	}
//		printf("solve(%d,%d): ",d,v);outarr(a,0,(1<<(d+1))-1);
}
int main(){
	n=read();
	A=read(),B=read();
	if ((cnt1(A^B)&1)!=1||A==B)
		return puts("NO"),0;
	puts("YES");
	B^=A;
	int pc=0;
	For(i,0,n-1)
		if (~B>>i&1)
			p[pc++]=i;
	For(i,0,n-1)
		if (B>>i&1)
			p[pc++]=i;
	int C=0;
	For(i,0,n-1)
		C|=(B>>p[i]&1)<<i;
	solve(a,n-1,C);
	For(i,0,(1<<n)-1){
		int val=0;
		For(j,0,n-1)
			val|=(a[i]>>j&1)<<p[j];
		a[i]=val^A;
	}
	For(i,0,(1<<n)-1)
		printf("%d ",a[i]);
	For(i,1,(1<<n)-1){
		int val=a[i]^a[i-1];
		assert((val&-val)==val);
	}
	sort(a,a+(1<<n));
	For(i,1,(1<<n)-1){
		assert(a[i]!=a[i-1]);
	}
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;

typedef long long ll;
typedef pair<int, int> p;

struct Query{
    int s, e, x;
    bool operator < (const Query &t) const {
        return p(s/700, e) < p(t.s/700, t.e);
    }
} qry[505050];

int n, q, a[505050];
int cnt[505050], now, res[505050];

void insert(int x){ if(!cnt[a[x]]++) now++; }
void erase(int x){ if(!--cnt[a[x]]) now--; }

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n >> q;
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=1; i<=q; i++) cin >> qry[i].s >> qry[i].e, qry[i].x = i;
    sort(qry+1, qry+q+1);
    int s = 1, e = 1; insert(1);
    for(int i=1; i<=q; i++){
        while(qry[i].s < s) insert(--s);
        while(e < qry[i].e) insert(++e);
        while(s < qry[i].s) erase(s++);
        while(qry[i].e < e) erase(e--);
        res[qry[i].x] = now;
    }
    for(int i=1; i<=q; i++) cout << res[i] << "\n";
}

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

int main()
{
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	a.push_back(a[0]+k);
	int l = 0;
	rep(i, n) l = max(l, a[i+1] - a[i]);
	cout << k-l << endl;

	return 0;
}


Measured memory_bytes: 1792