akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <queue>

using namespace std;

#define ll long long
constexpr ll inf = 1e17+7;

struct Edge {
    int from, to, cost;
};

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

    int N, M;
    cin>>N>>M;
    vector<Edge> edges(M);
    for (int m = 0; m < M; m++) {
        cin>>edges[m].from>>edges[m].to>>edges[m].cost;
    }

    vector<ll> d(N+1, -inf);
    d[1] = 0;
    for (int n = 0; n < N; n++) {
        for (auto&& edge : edges) {
            if (d[edge.from] != -inf && d[edge.to] < d[edge.from] + edge.cost) {
                d[edge.to] = d[edge.from] + edge.cost;
                if (n == N - 1 && edge.to == N) {
                    cout<<"inf"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<d[N]<<endl;

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int x,y,z,K;
  cin >> x >> y >> z >> K;
  vector<ll> a(x);
  rep(i,x) cin >> a[i];
  vector<ll> b(y);
  rep(i,y) cin >> b[i];
  vector<ll> c(z);
  rep(i,z) cin >> c[i];
  sort(all(a)); reverse(all(a));
  sort(all(b)); reverse(all(b));
  sort(all(c)); reverse(all(c));
  ll l=2,r=3e10+1;
  while(r-l!=1){
    ll mid=(l+r)/2;
    bool ok=[&]{
      int cnt=0;
      rep(i,x)rep(j,y)rep(k,z){
        if(a[i]+b[j]+c[k]<mid) break;
        cnt++;
        if(cnt==K) return true;
      }
      return false;
    }();
    if(ok) l=mid;
    else r=mid;
  }
  priority_queue<ll> q;
  rep(i,x)rep(j,y)rep(k,z){
    if(a[i]+b[j]+c[k]>=l) q.push(a[i]+b[j]+c[k]);
    if(a[i]+b[j]+c[k]<l) break;
  }
  while(K){
    cout << q.top() << endl;
    q.pop();
    K--;
  }
}

Measured memory_bytes: 132704
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 50;
int a[N], b[N], c[N], d[N];
int A[N];
int n, m, q, ret = 0;

void search(int pos, int low) {
  if (pos == n) {
    // for (int i = 0; i < n; ++i) cout << A[i] << " ";
    // cout << endl;
    int cur = 0;
    for (int i = 0; i < q; ++i) {
      if (A[b[i]] - A[a[i]] == c[i]) cur += d[i];
    }
    ret = max(cur, ret);
    return;
  }
  for (int i = low; i <= m; ++i) {
    A[pos] = i;
    search(pos + 1, i);
  }
}

int main() {
  cin >> n >> m >> q;
  for (int i = 0; i < q; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    --a[i]; --b[i];
  }
  search(0, 1);
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3664
var
	A,B,C,K:Longint;
begin
	read(A,B,C,K);
	while A>=B do begin
		dec(K);
		B:=B*2;
	end;
	while B>=C do begin
		dec(K);
		C:=C*2;
	end;
	if K<0 then writeln('No')else writeln('Yes');
end.

Measured memory_bytes: 1328
N,K=map(int,input().split())
X=list(map(int,input().split()))
answers=[]
whole=0
for n in range(N-K+1):
    if X[K-1+n]>0 and X[n]<0:
        whole += (X[K - 1 + n] - X[n])
        whole+=min(X[K-1+n],-X[n])
    elif X[K-1+n]<0:
        whole-=X[n]
    elif X[n]>0:
        whole+=X[K-1+n]
    answers.append(whole)
    whole=0
print(min(answers))


Measured memory_bytes: 87228
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
#define PI 3.14159265359
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

bool isPrime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    if (x == 1)
        return false;
    return true;
}

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        string s;
        cin >> s;
        loop(0, s.length()) {
            if (s[i] == '7') {
                cout << "Yes\n";
                exit(0);
            }
        }
        cout << "No\n";
    }
    return 0;
}


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

int main(){
	int a,b;
	cin>>a>>b;
	if(a*b%2==0){
		cout<<"Even"<<endl;
	}else{
		cout<<"Odd"<<endl;
	}
return 0;}

/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
# 2019/01/27
# NIKKEI Programming Contest 2019 - C
from operator import itemgetter

# Input
n = int(input())
ablist = list()

for idx in range(n):
    a, b = map(int, input().split())
    ablist.append([a, b, a+b])

ablist.sort(key=itemgetter(2), reverse=True)

tsum = 0
asum = 0

# Sum
for idx in range(n):
    if idx % 2 == 0:
        # Turn of Takahashi
        tsum += ablist[idx][0]
    else:
        # Turn of Aoki
        asum += ablist[idx][1]

ans1 = tsum - asum

# Output
print(ans1)


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int G[30][30];

void remove(int (&G)[30][30], int h, int w){
    for (int i = 0; i < w; ++i) {
        for (int k = 0; k < h; ++k) {
            for (int j = 0; j < h -1; ++j) {
                if(G[i][j] == 0) swap(G[i][j], G[i][j+1]);
            }
        }
    }
}

int solve(int h, int w, int k, int sx, int sy){
    int tmp[30][30] = {};
    for (int i = 0; i < w; ++i) {
        for (int j = 0; j < h; ++j) {
            tmp[i][j] = G[i][j];
        }
    }
    tmp[sx][sy] = 0;
    remove(tmp, h, w);
    int res = 0;
    int cnt = 0;
    bool flag;
    do {
        flag = false;
        for (int j = 0; j < h; ++j) {
            for (int i = 0; i < w - k + 1; ++i) {
                int l = i;
                for (; tmp[l][j] == tmp[l + 1][j] && tmp[l][j] != 0; ++l);
                if (l >= i + k - 1) {
                    flag = true;
                    res += pow(2, cnt) * tmp[l][j] * (l - i + 1);

                    for (int m = i; m <= l; ++m) {
                        tmp[m][j] = 0;
                    }
                }
            }
        }
        cnt++;
        remove(tmp, h, w);
    } while(flag);
    return res;
}

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    string s;
    for (int i = h - 1; i >= 0; --i) {
        cin >> s;
        for (int j = 0; j < w; ++j) {
            G[j][i] = s[j] - '0';
        }
    }

    int res = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            res = max(res, solve(h, w, k, i, j));
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  static public void main(String args[]){
    int N;
    Scanner sc = new Scanner(System.in);
    N = sc.nextInt();
    int vec1[] = new int[N];
    int vec2[] = new int[N];
    for(int i = 0; i < N; i++){
    vec1[i] = sc.nextInt();
  }
  for(int i = 0; i < N; i++){
  vec2[vec1[i]-1] = i + 1;
  }
  for(int i = 0; i < N; i++){
    System.out.print(vec2[i] + " ");
  }
  }
}


Measured memory_bytes: 63184
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

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

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

using namespace std;

int main() {
  int n;
  scan(n);
  vll t(n);
  scan(t);
  ll ans = 1;
  rep (i, n) {
    ans = lcm(ans, t[i]);
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>
#include <iomanip>

using namespace std;
using lint = long long;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repf(i, f, n) for (int i = (f); i < (n); i++)
#define mp(x, y) make_pair((x), (y))
#define all(x) (x).begin(), (x).end()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20

constexpr lint MOD = 1e9 + 7;
int A, B, C, D, E, F, G, H, I, J, K, L, M, N;
int O, P, Q, R, S, T, U, V, W, X, Y, Z;
string s;
lint ans = 0;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> X;

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

    cout << ans << endl;
	return 0;
}

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, m;
  cin >> n >> m;

  vector<int> w(n, 0), e(n, 0);
  int allw = 0, alle = 0;
  for ( int i = 0; i < m; i++ ) {
    string d;
    cin >> d;    
    for ( int j = 0; j < n; j++ ) {
      if ( d[j] == 'W' ) {
	w[j]++;
	allw++;
      }
      else {
	e[j]++;
	alle++;
      }
    }    
  }

  int l = 0;
  int mi = allw;
  int sumw = allw, sume = 0;  
  for ( int i = 0; i < n; i++ ) {
    sumw -= w[i];
    sume += e[i];
    if ( mi > sumw+sume ) {
      l = i+1;
      mi = sumw+sume;      
    }
  }

  cout << l << " " << l+1 << endl;
  
  return 0;
}



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

#define FOR(a,b,c) for (int a=(b);a<(c);++a)
#define REP(i,n) FOR(i,0,n)
#define ll long long
#define pii pair<int,int>
#define x first
#define y second
#define pb push_back
#define lf double

using namespace std;

const int MAX = (int)1e6 + 5;
const ll INF = (ll)1e18;

int main(){
	int n;
	scanf ("%d",&n);
	ll res=1;
	lf q=1;
	bool has=0;
	REP(i,n){
		ll a;
		scanf ("%lld",&a);
		res*=a;
		q*=a;
		if (a==0){
			puts ("0");
			return 0;
		}
		if (q>=1.1e18 || res>(ll)1e18){
			has=1;
		}
	}
	if (has){
		puts ("-1");
	}
	else
	printf ("%lld\n",res);
	
	return 0;
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
int n = s.length();
// for(int i=0; i<n; i++)
if(s[n-1] != 's')
{
    cout<<s<<"s"<<endl;
}
else{
    cout<<s<<"es"<<endl;
}
// for(int i=0; i<n; i++){
//     if(s[n] == 's')
//     cout<<s<<"es"<<endl;}

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

// int prime[1000001];
// vector<ll> primes;

// void soe() {
//     int i,j;
//     for(i=2;i<1000001;i++) prime[i] = 1;
//     for(i=2;i<=sqrt(1000001);i++) {
//         if(prime[i] == 1) {
//             for(j=i*i;j<1000001;j+=i) {
//                 prime[j] = 0;
//             }
//         }
//     }
//     for(i=2;i<1000001;i++) {
//         if(prime[i]) primes.pb(i);
//     }
// }

int d[10];

bool valid(int n) {
    while(n) {
        if(d[n%10]) return false;
        n/=10;
    }
    return true;
}

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

    int n,k,i;
    cin >> n >> k;
    
    for(i=0;i<k;i++) {
        int x;
        cin >> x;
        d[x]++;
    }
    i=n;
    while(i) {
        if(valid(i)) {
            cout << i << "\n";
            break;
        }
        i++;
    }
    return 0;
}




Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>

typedef long long ll;
const int N = 1e7 + 10;

ll a[N];

int main() {
	int ans = 0, n, cnt = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		if (a[i] == a[i-1]) cnt++;
		else {
			ans += cnt / 2;
			cnt = 1;
		}
	}
	ans += cnt / 2;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int h, w;
	cin >> h >> w;
	int a[501][501];
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			cin >> a[i][j];
		}
	}
	vector<pair<pair<int, int>, pair<int, int> > > v;
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w - 1; j++){
			if(a[i][j] % 2 == 1){
				a[i][j]--;
				a[i][j + 1]++;
				v.push_back(make_pair(make_pair(i, j), make_pair(i, j + 1)));
			}
		}
		if(a[i][w] % 2 == 1 && i < h){
				a[i][w]--;
				a[i + 1][w]++;
				v.push_back(make_pair(make_pair(i, w), make_pair(i + 1, w)));
		}
	}
	cout << v.size() << endl;
	for(int i = 0; i < v.size(); i++){
		cout << (v[i].first).first << " " << (v[i].first).second << " " << (v[i].second).first << " " << (v[i].second).second << endl;
	}
}

Measured memory_bytes: 5232
nums = list(map(int, input().strip().split(' ')))
x = nums[0]
k = nums[1]
d = nums[2]
x = abs(x)
if x >= k * d:
    print(x - (k * d))
else:
    ans = []
    ans.append(x)
    m = x // d
    k1 = x - (m * d)
    left = k - m
    if(left % 2 == 0):
        ans.append(abs(k1))
    else:
        ans.append(abs(k1 - d))
    sorted(ans)
    print(ans[len(ans) - 1])

Measured memory_bytes: 9220
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <fstream>
#include <complex>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i <(b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a,value, sizeof(a))

#define ALL(a) a.begin(),a.end()
#define SZ(a) (int)a.size()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<LL> VI;
typedef pair<int, LL> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 * 2 + 47;

VI G[MAX];
int H[MAX];
int HH[MAX];

void DFS(int v, int H[], int p = -1, int h = 0)
{
    H[v] = h;
    FOR(i, 0, SZ(G[v]))
    {
        int to = G[v][i];
        if (to == p)continue;
        DFS(to, H, v, h+1);
    }
}


int main()
{
    //freopen("input.txt", "r", stdin);
    //ios::sync_with_stdio(false);cin.tie(NULL);

    int n, k;
    scanf("%d%d", &n, &k);
    FOR(i, 0, n-1)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        --a, --b;
        G[a].PB(b);
        G[b].PB(a);
    }
    int ans = n;
    if (k % 2 == 0)
    {
        FOR(i, 0, n)
        {
            DFS(i, H);
            int res = 0;
            FOR(i, 0, n)
                if (H[i] > k / 2)
                    res++;
            ans = min(ans, res);
        }
    }
    else
    {
        FOR(i, 0, n)
            FOR(j, 0, SZ(G[i]))
            {
                int res = 0;
                int to = G[i][j];
                DFS(i, H);
                DFS(to, HH);
                FOR(i, 0, n)
                {
                    int d = min(H[i], HH[i]);
                    if (d > (k - 1) / 2)res++;
                }
                //cout << "*" << res << endl;
                ans = min(res, ans);
            }
        
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 512
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, m, k;
  rd(n, m, k);
  import std.array;

  auto r = readln.split
    .to!(int[])
    .map!((e) => (e - 1))
    .array;
  auto d = new int[][](n, n);
  const int inf = 10 ^^ 9;
  foreach (i; 0 .. n)
    foreach (j; 0 .. n)
      d[i][j] = inf;
  foreach (i; 0 .. n)
    d[i][i] = 0;
  foreach (_; 0 .. m) {
    int a, b, c;
    rd(a, b, c);
    a--;
    b--;
    d[a][b] = d[b][a] = c;
  }
  foreach (_; 0 .. n)
    foreach (i; 0 .. n)
      foreach (j; 0 .. n)
        d[i][j] = min(d[i][j], d[i][_] + d[_][j]);
  import std.range : iota;

  auto idxs = iota(0, k).array;
  int mn = inf;
  do {
    int s = 0;
    foreach (i; 1 .. k) {
      s += d[r[idxs[i - 1]]][r[idxs[i]]];
    }
    mn = min(mn, s);
  }
  while (nextPermutation(idxs));
  writeln(mn);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


Measured memory_bytes: 1276
N = gets.to_i

sum = 0
x=[]
u=[]

for i in 0..N-1 do
  x[i], u[i] = gets.split(" ")
end

for i in 0..N-1 do
  if u[i] == "JPY"
    sum += x[i].to_i
  else
    sum += 380000.0 * (x[i].to_f)
  end
end

puts sum


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

int min(int r, int l) {
    if (r>l) return l;
    else return r;
}

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    cout << A+B+C+D+E+F-min(min(A,B),min(C,D))-min(E,F) << endl;
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{ 
    set<int > s;
    int n,k;
    scanf("%d%d",&n,&k);
    int i,cnt=1;
    for(i=0;i<=n;++i)
    {
       s.insert(cnt + (n-i)*k);
       cnt*=2;
    }
  
  auto it=s.begin();
    cout<<*it;
                
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int t=sc.nextInt();
        int a[] =new int[101];
        for(int i=0;i<a.length;i++){
            a[i]=0;
        }
        int tot=0;
        while(t-->0){
            int n=sc.nextInt();
            if(a[n]==0){
                tot++;
                a[n]=1;
            }
        }
        System.out.println(tot);
    }
}

Measured memory_bytes: 23892
#include<iostream>

using namespace std;

int n, a, b, c, x;

int main () {
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> x;
		if (x%4==0) a++;
		if (x%4==2) c++;
		if (x%2==1) b++;
	}
	if (c) b++;
	if (a+1>=b) cout << "Yes"; else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#![allow(unused)]

use std::io::{Read, Stdin, StdinLock};
use std::iter::{FromIterator, Iterator};
use std::str::{FromStr};
use std::string::String;

macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

struct TokenReader<'a> {
    lock: StdinLock<'a>,
}

impl<'a> TokenReader<'a> {
    fn new(s: &'a Stdin) -> TokenReader<'a> {
        TokenReader { lock: s.lock() }
    }

    fn read_chars<T: FromIterator<char>>(&mut self) -> T {
        self.lock
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<T>()
    }

    fn read_str(&mut self) -> String {
        self.read_chars::<String>()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read_str().parse().ok().unwrap()
    }
}

//==============================================================================
//
// Problem specific code
//
//==============================================================================

fn main() {
    let sin = std::io::stdin();
    let mut tr = TokenReader::new(&sin);

    let r: i64 = tr.read();
    println!("{}", (r as f64) * 2. * std::f64::consts::PI);
}

Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,C;
int D[31][31];
int c[510][510];
int mod[510][510];
vector<P> B[3];
int cost[3][31];

signed main(){
	cin>>N>>C;
	REP(i,C){
		REP(j,C){
			cin>>D[i][j];
		}
	}
	REP(i,N){
		REP(j,N){
			cin>>c[i][j];
			c[i][j]--;
			mod[i][j]=(i+1+j+1)%3;
			B[mod[i][j]].push_back({i,j});
		}
	}
	REP(i,3){
		REP(j,C){
			REP(k,B[i].size()){
				int s=B[i][k].first,t=B[i][k].second;
				int color=c[s][t];
				cost[i][j]+=D[color][j];
			}
		}
	}
	int ans=INF;
	REP(i,C){
		REP(j,C){
			REP(k,C){
				if(i!=j&&j!=k&&i!=k){
					ans=min(ans,cost[0][i]+cost[1][j]+cost[2][k]);
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
/*
2 0
0 1
*/

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

using namespace std;
using ll=long long;

void max_self(vector<int> &a, int b, int x, int y){
    if(b>a[0]){
        a={b,x,y};
    }
}


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

    string s,t;
    cin>>s>>t;
    int n1=s.size(), n2=t.size();
    vector<vector<vector<int>>>dp(n1+1, vector<vector<int>>(n2+1, vector<int>(3,0)));
    for(int i=0; i<n1; i++){
        for(int j=0; j<n2; j++){
            if(s[i]==t[j]){
                max_self(dp[i+1][j+1],dp[i][j][0]+1,i,j);
            }
            max_self(dp[i][j+1],dp[i][j][0],i,j);
            max_self(dp[i+1][j],dp[i][j][0],i,j);
        }
    }
    string res;
    int i=0, j=0, ans=0;
    for(int f=0; f<=n1; f++){
        for(int g=0; g<=n2; g++){
            if(dp[f][g][0]>ans){
                ans=dp[f][g][0];
                i=f,j=g;
            }
        }
    }
    if(ans==0){
        cout<<""<<endl;
        return 0;
    }
    while(i&&j){
        int prv_i=dp[i][j][1], prv_j=dp[i][j][2];
        if(prv_i+1==i&&prv_j+1==j){
            res+=s[prv_i];
        }
        i=prv_i, j=prv_j;
    }
    reverse(res.begin(),res.end());
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 495972
#include <bits/stdc++.h>
#define INF 1.0e9
#define MOD 1.0e9+7
using namespace std;
typedef long long ll;

int x_1, y_1, x_2, y_2;

int main() {
    cin >> x_1 >> y_1 >> x_2 >> y_2;
    int a = x_2 - x_1;
    int b = y_2 - y_1;
    int x_3 = x_2 - b;
    int y_3 = y_2 + a;
    int x_4 = x_1 - b;
    int y_4 = y_1 + a;
    cout << x_3 << " " << y_3 << " " << x_4 << " " << y_4 << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int AHP=A,BAK=B,CHP=C,DAK=D;
  while(AHP>0&&CHP>0){
    CHP-=BAK;
    if(CHP<=0){
      Yes();
      break;
    }
    AHP-=DAK;
    if(AHP<=0){
      No();
      break;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3640
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
using namespace std;

struct St
{
	int small;
	int big;
	bool operator < (const St &st) const
	{
		if (st.small == small)
		{
			return st.big > big;
		}
		return st.small > small;
	}
};


int N;
St st[200000];

int func1()
{
	int max = LLONG_MIN;
	int min_big = LLONG_MAX;
	for (int i = 0; i < N; i++)
	{
		max = MAX(max, st[i].big);
		min_big = MIN(min_big, st[i].big);
	}
	int min = st[0].small;

	int const_min_b = LLONG_MAX;
	int const_max_b = LLONG_MIN;
	for (int i = 0; i < N; i++)
	{
		if (st[i].small == min)
		{
			const_min_b = MIN(const_min_b, st[i].big);
			const_max_b = MAX(const_max_b, st[i].big);
		}
		if (st[i].big == max)
		{
			const_min_b = MIN(const_min_b, st[i].small);
			const_max_b = MAX(const_max_b, st[i].small);
		}
	}
	if (max == const_max_b || min == const_min_b) return LLONG_MAX;

	int min_b = LLONG_MAX;
	int max_b = LLONG_MIN;
	for (int i = 0; i < N; i++)
	{
		if (st[i].small != min)
		{
			min_b = MIN(min_b, st[i].small);
			max_b = MAX(max_b, st[i].small);
		}
	}

	int min_val = (max - min) * (MAX(max_b, const_max_b) - MIN(min_b, const_min_b));
	for (int i = 0; i < N; i++)
	{
		if (st[i].small == min || st[i].big == max) continue;

		min_b = (i < N - 1) ? st[i + 1].small : min_big;
		max_b = MAX(max_b, st[i].big);
		const_min_b = MIN(const_min_b, st[i].big);

		min_val = MIN(min_val, (max - min) * (MAX(max_b, const_max_b) - MIN(min_b, const_min_b)));
	}

	return min_val;
}

int func2()
{
	int min = st[0].small;
	int max = LLONG_MIN;
	int max_i;
	for (int i = 0; i < N; i++)
	{
		if (max < st[i].big)
		{
			max = st[i].big;
			max_i = i;
		}
	}
	int min_r = st[0].big;
	int max_b = st[max_i].small;
	for (int i = 1; i < N; i++)
	{
		if (i == max_i) continue;
		min_r = MIN(st[i].big, min_r);
		max_b = MAX(st[i].small, max_b);
	}
	return (max - min_r) * (max_b - min);
}

signed main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int x, y;
		cin >> x >> y;
		int max = MAX(x, y);
		int min = MIN(x, y);
		st[i].small = min;
		st[i].big = max;
	}
	ARY_SORT(st, N);

	if (N == 1)
	{
		return 0;
	}

	int val = MIN(func1(), func2());

	cout << val << endl;
}

Measured memory_bytes: 3964
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <complex>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
P rotate(const P &p, double rad){
    return p *P(cos(rad), sin(rad));
}

int main(){
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    P aa = rotate(P(0,a), (h/12.0+m/60.0/12.0)*2*PI);
    P bb = rotate(P(0,b), m/60.0*2*PI);
    cout << fixed << setprecision(10);
    cout << abs(aa-bb) << endl;
    return 0;
}

Measured memory_bytes: 4168
x1, y1, x2, y2 = map(int, input().split())
d1 = x2 - x1
d2 = y2 - y1
x3 = x2 - d2
y3 = y2 + d1
x4 = x3 - d1
y4 = y3 - d2
print(x3, y3, x4, y4)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   ll a,b,c;
   cin>>a>>b>>c;
   if((c-a-b)*(c-a-b)>4*a*b && c>(a+b))
        cout<<"Yes";
   else cout<<"No";        
   
   return 0;        
}  
   

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


int main(){
int n,w;
cin>>n>>w;
vector<vector<int>> dish(n+1, vector<int>(2));

// dp[i][j]
// i番目までの料理を食べるか選択したとき
// 経過時間をjとすると
// 最大満足値はdp[i][j]
vector<vector<int>> dp(n+1, vector<int>(w+1));

for(int i=0;i<n;i++) cin>>dish[i][0]>>dish[i][1];

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

int ans=0;
for(int i=0;i<n;i++){
  for(int j=0;j<=w;j++){
    if(dish[i][0]<=j)dp[i+1][j] = max(dp[i][j-dish[i][0]]+dish[i][1],dp[i][j]);
    else dp[i+1][j] = dp[i][j];
    ans = max(ans, dp[i+1][w-1]+dish[i+1][1]);
  }
}




cout<<ans<<endl;
}


Measured memory_bytes: 35712
#include <stdio.h>
int main()
{
    long long int a, b, k;
    long long int ans;
    scanf("%lld%lld%lld", &k, &a, &b);
    if ((k - a) % 2 == 0)
    {
        ans = ((k - a) / 2) * b - ((k - a) / 2 - 1) * a + 1;
    }
    else
    {
        ans = ((k - a + 1) / 2) * b - ((k - a + 1) / 2 - 1) * a;
    }
    if (ans < k + 1)
    {
        ans = k + 1;
    }
    printf("%lld", ans);
    return 0;
}

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

signed main() {
  int N;
  cin >> N;
  
  set<int> kazu;
  int A;
  for( int i = 0; i < N; i++ ){
    cin >> A;
    if( kazu.count(A) ) kazu.erase(A);
    else kazu.insert(A);
  }
  
  cout << kazu.size() << endl;
}

Measured memory_bytes: 4864
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

namespace yaito {
  template<class T, class Func>
  class segmentTree {
  private:
    std::vector<T> data;
    size_t height;
    size_t bottom_size;
    Func func;
    T invalid;

    T get(size_t l, size_t r, size_t k, size_t left, size_t right) const {
      if (right <= l || r <= left)return invalid;
      if (l <= left && right <= r)return data[k];
      T a = get(l, r, k * 2 + 1, left, (left + right) / 2);
      T b = get(l, r, k * 2 + 2, (left + right) / 2, right);
      return func(a, b);
    }

  public:
  	segmentTree() = default;
    template<class Iter>
    segmentTree(Iter first, Iter last, Func func, T invalid) : func(func), invalid(invalid) {
      size_t dif = std::distance(first, last);
      bottom_size = 1;
      height = 1;
      while (bottom_size < dif) {
        bottom_size <<= 1;
        ++height;
      }
      data.resize(2 * bottom_size - 1, invalid);
      for (size_t i = 0; i < dif; ++i, ++first)update(i, *first);
    }

    void update(size_t i, T value) {
      i += bottom_size - 1;
      data[i] = value;
      while (i > 0) {
        i = (i - 1) / 2;
        data[i] = func(data[i * 2 + 1], data[i * 2 + 2]);
      }
    }

    T get(size_t l, size_t r) const {
      return get(l, r, 0, 0, bottom_size);
    }

    void show()const {
      for (size_t i = 0; i < 2 * bottom_size - 1; ++i) {
        std::cout << data[i] << ", ";
        if (!((i + 2) & (i + 1)))std::cout << '\n';
      }
    }

  };

  template<class T, class Iter, class Func>
  auto make_segmentTree(Iter first, Iter last, Func func, T init) {
    return segmentTree<T, Func>(first, last, func, init);
  }

}

ostream& operator<<(ostream& os, const set<char>& s){
	os << '{';
    for(const auto& e : s)os << ' ' << e;
    os << " }";
    return os;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string S;
  cin >> S;
  array<yaito::segmentTree<int, plus<>>, 26> trees;
  for(char c = 'a'; c <= 'z'; ++c){
    vector<int> v(N);
    for(int i = 0; i < N; ++i)v[i] = (S[i]==c ? 1 : 0);
    trees[c-'a'] = yaito::make_segmentTree(begin(v),end(v), plus<>{}, 0);
  }
  int Q;
  cin >> Q;
  for (int q = 0; q < Q; ++q) {
    int t;
    cin >> t;
    if (t == 1) {
      int i;
      char c;
      cin >> i >> c;
      --i;
      trees[S[i]-'a'].update(i, 0);
      trees[c-'a'].update(i, 1);
      S[i] = c;
    }
    else if (t == 2) {
      int l, r;
      cin >> l >> r;
      --l;
      int ans = 0;
      for(const auto& e : trees)if(e.get(l, r)>0)++ans;
      cout << ans << "\n";
    }
  }
}


Measured memory_bytes: 109304
#ifndef VS
#include<bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	int R, C, D;
	cin >> R >> C >> D;
	vector<int> pr(R*C);
	vector<int> pc(R*C);
	vector<vector<LL>> d(D);
	for (int i : range(R)) {
		for (int j : range(C)) {
			int v;
			cin >> v;
			pr[v - 1] = i;
			pc[v - 1] = j;
		}
	}
	for (int i : range(D)) {
		d[i].push_back(0);
		for (int j = i+D; j < R*C; j+=D) {
			int latte = abs(pr[j] - pr[j - D]);
			latte += abs(pc[j] - pc[j - D]);
			d[i].push_back(d[i].back() + latte);
		}
	}
	int Q;
	cin >> Q;
	for (int _ : range(Q)) {
		int l, r;
		cin >> l >> r; l--; r--;
		const int mod = l%D;
		l /= D; r /= D;
		cout << d[mod][r] - d[mod][l] << endl;
	}
	return 0;
}


Measured memory_bytes: 6144
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

vi g[10];
int ans = 0;
int n, m;

void dfs(int cur, vi vis, int tot){
	if(vis[cur]) return;
	vis[cur] = 1;
	tot++;
	if(tot == n) ans++;
	for(int x : g[cur]) if(!vis[x]) dfs(x, vis, tot);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	cin >> n >> m;
	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	vi emp(n, 0);
	dfs(0, emp, 0);
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int A[555][555];

void go(vector<int> &S, int dep) {
    int N = S.size();
    if(N <= 1) return;
    vector<int> P, Q;
    for(int i=0; i<N/2; i++) P.push_back(S[i]);
    for(int i=N/2; i<N; i++) Q.push_back(S[i]);
    int PS = P.size(), QS = Q.size();
    for(int i=0; i<PS; i++) {
        for(int j=0; j<QS; j++) {
            A[P[i]][Q[j]] = A[Q[j]][P[i]] = dep;
        }
    }
    go(P, dep + 1);
    go(Q, dep + 1);
}

int main() {
    int N; scanf("%d",&N);
    vector<int> S;
    for(int i=1; i<=N; i++) S.push_back(i);
    go(S, 1);
    for(int i=1; i<N; i++) {
        for(int j=i+1; j<=N; j++) {
            printf("%d ", A[i][j]);
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 1536
s = list(input())
s.append('R')
ans = [0] * (len(s)-1)
Rc = 0
Lc = 0
for i in range(len(s)) :
    if Lc != 0 and s[i] == 'R' :
        ans[Ri] = Rc % 2 + Rc // 2 + Lc // 2
        ans[Ri+1] = Rc//2 + Lc//2 + Lc%2
        Rc = 1
        Ri = i
        Lc = 0
    elif s[i] == 'R' :
        Rc += 1
        Ri = i
    elif s[i] == 'L':
        Lc += 1

ans = ' '.join([str(n) for n in ans])
print(ans)

Measured memory_bytes: 17856
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	long long res = 0;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i)cin>>vec[i];
	for(int i = 0; i < n; ++i){
		for(int j = i + 1; j < n; ++j){
			res += vec[i] * vec[j];
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int p = scan.nextInt();
		int q = scan.nextInt();
		int r = scan.nextInt();
		scan.close();
		int max = Math.max(Math.max(p, q), r);
        System.out.println(p + q + r - max);
	}
}

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

long long yz(long long K, long long a){
    if (a > 2*K) return 0;
    else if (a > K) return 2*K - a + 1;
    else if (a >= 0) return a+1;
    else return 0; // a < 0
}

void solve(long long K, long long S){
    long long cnt = 0;
    for (int x=0; x<= K; x++){
        cnt += yz(K, S - x);
    }
    cout << cnt << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    long long S;
    scanf("%lld",&S);
    solve(K, S);
    return 0;
}


Measured memory_bytes: 256
from collections import deque
n,q=map(int,input().split())
tree=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    tree[a].append(b)
    tree[b].append(a) # 無向グラフなので
ans=[0]*n
for _ in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x

stack=deque([[0,-1]]) # 根の位置、現位置の元になる根
visited=[0]*n
visited[0]=1

while stack:
    cur,rot=stack.pop()
    for i in tree[cur]:
        if visited[i]==0 and i!=rot:
            visited[i]=1
            ans[i]+=ans[cur]
            stack.append([i,cur])
print(*ans)

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

#include <bits/stdc++.h>

using namespace std;

class dwacon5_c {
public:
    void solve(istream& in, ostream& out) {
        int N, Q;
        string S;
        in >> N >> S >> Q;
        for (int i = 0; i < Q; ++i) {
            int k;
            in >> k;
            long long res = 0;
            long long d = 0, m = 0, dm = 0;
            for (int i = 0; i < N; ++i) {
                if (i >= k) {
                    int j = i - k;
                    if (S[j] == 'D') {
                        dm -= m;
                        d -= 1;
                    } else if (S[j] == 'M') {
                        m -= 1;
                    }
                }
                if (S[i] == 'D') {
                    d += 1;
                } else if (S[i] == 'M') {
                    m += 1;
                    dm += d;
                } else if (S[i] == 'C') {
                    res += dm;
                }
            }
            out << res << "\n";
        }
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	dwacon5_c solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> xs(n);
    for (auto& x : xs) {
        cin >> x.first >> x.second;
    }
    sort(xs.begin(), xs.end());
    vector<int> happiness(t+1, 0);
    for (int i = 0; i < n; ++i) {
        int a = xs[i].first, b = xs[i].second;
        happiness[t] = max(happiness[t], happiness[t-1] + b);
        for (int j = t-1; j >= a; --j) {
            happiness[j] = max(happiness[j], happiness[j - a] + b);
        }
    }
    cout << happiness[t] << endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  if (s.size() == 2) {
    if (s.at(0) == s.at(1)) {
      cout << 1 << " " << 2 << endl;
    } else {
      cout << -1 << " " << -1 << endl;
    }
    return 0;
  }
  for (int i = 0; i <= s.size() - 3; i++) {
    if (s.at(i) == s.at(i + 1) or s.at(i) == s.at(i + 2) or s.at(i + 1) == s.at(i + 2)) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <tuple>
using namespace std;
    #define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
    #define ll long long
    #define int long long 
    #define ull unsigned long long 
    #define ld long double
    #define sb __builtin_popcount
    #define vi vector<int>
    #define vc vector<char>
    #define ii pair<int, int>
    #define pq priority_queue<ii, vector<ii>, greater<ii>>
    #define vii vector<ii>
    #define sz(a) int((a).size())
    #define f(a, b) for (int i = a; i < b; i++)
    #define fr(a, b) for (int i = a - 1; i >= b; i--)
    #define tr(x, m) for (auto x : m)
    #define in(a, b) (b.find(a) != string::npos)
    #define minin(a) *min_element(all(a))
    #define maxin(a) *max_element(all(a))
    #define X first
    #define Y second
    #define fill(a, x) memset(a, x, sizeof(a))
    #define pb push_back
    #define pf push_front
    #define mp make_pair
    #define all(v) v.begin(), v.end()
    #define rall(v) reverse(v.begin(), v.end())
    #define unq(v) v.erase(unique(all(v)), v.end())
    #define el "\n"
    #define mx3(a, b, c) max(max(a, b), c)
    #define mn3(a, b, c) min(min(a, b), c)
    #define S(v) accumulate(all(v), (ll)0)
    #define SP(n) cout.precision(n)
    const ld PI = atan(1.0) * 4.0;
    const ll MOD = 1e9 + 7;
    const ll INF = 1e18;
    const ld EPS = 0.0000001;
    const ll MD = 998244353;
   
    int32_t main() {
        fio;
        int x;
        cin>>x;
        int xx, frt;
        int nm = pow(x,1.0/5);
      //  cout<<nm<<el;
        nm++;
        for(int i=-nm;;i++){
            xx = pow(i,5);
            xx+=x;
            frt = pow(xx,1.0/5);
            if( pow(frt,5)==xx){
                cout<<frt<<" "<<i<<el;
                return 0;
            }
        }
        return 0;
    }


Measured memory_bytes: 4140