akhauriyash/Code-Regression huggingface dataset:
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Tree = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

int main(void){
	ll n;
	cin >> n;
	Vec a(n), b(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];

	ll ans = LINF;
	rep(bit, 1LL << n){
		bitset<18> bits(bit);
		VecP c(n);
		Vec d(n);
		rep(i, n){
			if(!bits[i]) c[i] = {a[i], i};
			else c[i] = {b[i], i};
		}
		rep(i, n) d[i] = c[i].fs;
		sort(all(d));

		ll cnt = 0;
		bool flg;
		rep(i, n){
			flg = false;
			REP(j, i, n){
				if(d[i] == c[j].fs && abs(i-c[j].sc)%2 == bits[c[j].sc]){
					REPNR(k, j, i+1){
						swap(c[k], c[k-1]);
						cnt++;
					}
					flg = true;
					break;
				}
			}
			if(!flg) break;
		}
		if(flg) chmin(ans, cnt);
	}

	if(ans != LINF) co(ans);
	else co(-1);

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;

void dfs(int i, int j, const vector<vector<int> >& c, vector<vector<int> >& arrived, int count) {
    arrived[i][j] = count;

    if (c[i + 1][j] == 1 && arrived[i + 1][j] == 0) {
        dfs(i + 1, j, c, arrived, count);
    }
    if (c[i - 1][j] == 1 && arrived[i - 1][j] == 0) {
        dfs(i - 1, j, c, arrived, count);
    }
    if (c[i][j + 1] == 1 && arrived[i][j + 1] == 0) {
        dfs(i, j + 1, c, arrived, count);
    }
    if (c[i][j - 1] == 1 && arrived[i][j - 1] == 0) {
        dfs(i, j - 1, c, arrived, count);
    }
    if (c[i + 1][j + 1] == 1 && arrived[i + 1][j + 1] == 0) {
        dfs(i + 1, j + 1, c, arrived, count);
    }
    if (c[i + 1][j - 1] == 1 && arrived[i + 1][j - 1] == 0) {
        dfs(i + 1, j - 1, c, arrived, count);
    }
    if (c[i - 1][j + 1] == 1 && arrived[i - 1][j + 1] == 0) {
        dfs(i - 1, j + 1, c, arrived, count);
    }
    if (c[i - 1][j - 1] == 1 && arrived[i - 1][j - 1] == 0) {
        dfs(i - 1, j - 1, c, arrived, count);
    }
}

void Main() {
    while (true) {
        int w, h;
        cin >> w >> h;
        if (w == 0 && h == 0) {
            break;
        }

        vector<vector<int> > c(h + 2, vector<int>(w + 2, 0));
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                int ct;
                cin >> ct;
                c[i + 1][j + 1] = ct;
            }
        }

        vector<vector<int> > arrived(h + 2, vector<int>(w + 2, 0));
        int count = 0;
        for (int i = 0; i < c.size(); ++i) {
            for (int j = 0; j < c[i].size(); ++j) {
                if (c[i][j] == 1 && arrived[i][j] == 0) {
                    ++count;
                    dfs(i, j, c, arrived, count);
                }
            }
        }

        set<int> ans;
        for (int i = 0; i < c.size(); ++i) {
            for (int j = 0; j < c[i].size(); ++j) {
                if (arrived[i][j] > 0) {
                    ans.insert(arrived[i][j]);
                }
            }
        }
        cout << ans.size() << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  auto m = (long long)a * b;
  while (b) {
    int t = a % b;
    a = b;
    b = t;
  }
  cout << m / a << endl;
  return 0;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        a: [u128; m]
    };
    let a: Vec<u128> = a;

    let base = (10i32.pow(9) + 7) as u128;

    let mut v: Vec<u128> = vec![1; n + 1];

    for &i in a.iter() {
        v[i as usize] = 0;
    }

    for i in 2..=n {
        let x = n - i;
        if v[x] == 0 {
            continue;
        } else {
            let y = v[x + 1] + v[x + 2];
            v[x] = y % base;
        }
    }

    println!("{}", v[0]);
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;


signed main(){
    int H, W, K;
    cin >> H >> W >> K;
    int cnt = 0, answer = 0;
    vector<vector<char>> grids(H, vector<char>(W));
    rep(i,0,H) rep(j,0,W) {
        cin >> grids[i][j];
        if (grids[i][j] == '#') cnt++;
    }
    rep(i,0,1<<H) rep(j,0,1<<W) {
        int black = cnt;
        rep(r,0,H) rep(c,0,W) {
            if (grids[r][c] == '#' && ((i&(1<<r))||(j&(1<<c)))) {
                black--;
            }
            if (black < K) break;
        }
        if (black == K) answer++;
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long ll;
int qry(ll x){
	printf("? %lld\n",x);
	fflush(stdout);
	char s[3];
	scanf("%s",s);
	if (s[0]=='Y') return 1;
	return 0;
}
int main(){
	int w=0;ll L=1;
	for (;qry(L) && w<=9;w++,L*=10);
	if (w>9){
		w=0,L=10;
		for (;!qry(L-1);w++,L*=10);
		printf("! %lld\n",L/10);
		fflush(stdout);
		return 0;
	}
	ll R=L-1,ans=R;
	w--,L/=10;
	while (L<=R){
		ll mid=(L+R)>>1;
		if (qry(mid*10)) ans=std::min(ans,mid),R=mid-1;
		else L=mid+1;
	}
	printf("! %lld\n",ans);
	fflush(stdout);
	return 0;
}

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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1e18
using namespace std;
typedef long long ll;

int a,b,q;
vector <ll> s, t;

int main(){
  std::cin >> a >> b >> q;
  s.push_back(-MAX);t.push_back(-MAX);
  rep(i,1,a+1){
    ll tmp_s;
    std::cin >> tmp_s;
    s.push_back(tmp_s);
  }
  rep(i,1,b+1){
    ll tmp_t;
    std::cin >> tmp_t;
    t.push_back(tmp_t);
  }
  s.push_back(MAX);t.push_back(MAX);
  sort(all(s));sort(all(t));

  rep(i,0,q){
    ll x;
    std::cin >> x;
    ll s1 = *lower_bound(all(s),x);
    ll s2 = *(lower_bound(all(s), x)-1);
    ll t1 = *lower_bound(all(t),x);
    ll t2 = *(lower_bound(all(t), x)-1);
    ll res = MAX;
    res = min(res, abs(s1-x)+abs(t1-s1));
    res = min(res, abs(s1-x)+abs(t2-s1));
    res = min(res, abs(s2-x)+abs(t1-s2));
    res = min(res, abs(s2-x)+abs(t2-s2));
    res = min(res, abs(t1-x)+abs(s1-t1));
    res = min(res, abs(t1-x)+abs(s2-t1));
    res = min(res, abs(t2-x)+abs(s1-t2));
    res = min(res, abs(t2-x)+abs(s2-t2));
    std::cout << res << '\n';
  }
}


Measured memory_bytes: 3060
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if(abs(a - b) > k ||
     abs(a - c) > k ||
     abs(a - d) > k ||
     abs(b - c) > k ||
     abs(b - d) > k ||
     abs(b - e) > k ||
     abs(c - d) > k ||
     abs(c - e) > k ||
     abs(d - e) > k ||
     abs(e - a) > k)
    cout << ":(";
  else
    cout << "Yay!";
  return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//const ll INF = 1e18;
//const ll MOD = 1e9+7;
//const double pi = 3.14159265358979;
using vl = vector<ll>;
using P = pair<ll, ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((ll)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((ll)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

ll N;
ll Main() {
    cin >> N;
    vector<string> S(N);
    rep(i,N) {
        cin >> S[i];
    }
    
    
    ll cntA = 0;
    ll cntW = 0;
    ll cntT = 0;
    ll cntR = 0;
    
    rep(i,N) {
        if(S[i] == "AC") {
            cntA++;
        } else if(S[i] == "WA") {
            cntW++;
        } else if(S[i] == "TLE") {
            cntT++;
        } else {
            cntR++;
        }
    }
    
    cout << "AC x " << cntA << endl;
    cout << "WA x " << cntW << endl;
    cout << "TLE x " << cntT << endl;
    cout << "RE x " << cntR << endl;
    
    return 0;
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 6372
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	cout << n/11*2+(n%11+5)/6 << endl ;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"

#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vvi g(n);
  vector<pii> p(m);
  REP(i, m) {
    cin >> p[i].first >> p[i].second;
    p[i].first--;
    p[i].second--;
    g[p[i].first].push_back(p[i].second);
  }

  using ld = long double;

  vector<ld> d(n); 
  {
    REP(i, n) {

      vector<ld> tmp(n);
      tmp[i] = 1;
      RREP(j, n) {
        ld t = g[j].size();
        for (int k : g[j])tmp[j] += tmp[k] / t;
      }
      d[i] = tmp[0];
    }
  }
  vector<ld> dp(n);
  RREP(i, n) {
    ld t = g[i].size();
    REP(j, g[i].size()) dp[i] += (dp[g[i][j]] + 1) / t;
  }
  ld sum = dp[0], ans = dp[0];
  REP(i, m) {
    ld tmp = 0;
    int s, t;
    tie(s, t) = p[i];
    ld sz = g[s].size();
    if (sz == 1)
      continue;
    bool f = false;
    REP(j, g[s].size()) {
      int to = g[s][j];
      tmp -= (dp[to] + 1) / sz;
      if (to == t) {
        if (f)
          tmp += (dp[to] + 1) / (sz - 1);
        f = true;
      }
      else {
        tmp += (dp[to] + 1) / (sz - 1);
      }
    }
    tmp *= d[s];
    chmin(ans, sum + tmp);
  }
  cout << setprecision(10) << ans << endl;
}


Measured memory_bytes: 2816
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();

        bool answer = false;

        if (s.Substring(2, 1) == s.Substring(3, 1) && s.Substring(4, 1) == s.Substring(5, 1))
        {
            answer = true;
        }

        Console.WriteLine(answer ? "Yes" : "No");
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13140
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
map<string, int> m;
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length();i++) {
		s[i] = 'x';
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (n, k) = get!(usize, usize);
    let mut v = Vec::new();
    for _ in 0..n {
        v.push(get!(usize));
    }
    v.sort();
    let mut ans: usize = 1 << 50;
    for i in k - 1..n {
        ans = std::cmp::min(v[i] - v[i - (k - 1)], ans);
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>

int main(void)
{
	char s[110], t[110];
	int i, j;
	char temp;

	scanf("%s", s);
	scanf("%s", t);

	for (i = 0; i < strlen(s); i++)
	{
		if (strcmp(s, t) == 0)
		{
			printf("Yes");
			break;
		}
		
		//回転
		temp = t[0];
		for (j = 0; j < strlen(s) - 1; j++)
		{
			t[j] = t[j + 1];
		}
		t[j] = temp;
	}

	if (i == strlen(s))
	{
		printf("No");
	}

	return 0;
}

Measured memory_bytes: 128
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

int V;
int E;
struct edge { int from, to, cost; };

typedef pair<int, int> PP;

vector<edge> e;

int Par[100000];
int Rank[100000];

void init(int n) {
	for (int i = 0; i < n; i++) {
		Par[i] = i;
		Rank[i] = 0;
	}
}

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

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

bool same(int x, int y) {
	return find(x) == find(y);
}

// ??????????????????????????????????????¢??° 
bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}

int kruskal() {
	init(V);
	sort(e.begin(), e.end(), comp);
	int ans = 0;
	for (int i = 0; i<E; i++) {
		if (!same(e[i].from, e[i].to)) {
			unite(e[i].from, e[i].to);
			ans += e[i].cost;
		}
	}
	return ans;
}

int main() {
	while (cin >> V >> E&&V&&E) {
		e.erase(e.begin(), e.end());
		int a, b, c;
		for (int i = 0; i < E; i++) {
			cin >> a >> b >> c;
			e.push_back(edge{ a,b,c });
		}
		cout << kruskal() << endl;
	}
}

Measured memory_bytes: 2964
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
	int a,b,c;
	double t=1.0;
	int m;
	cin>>a>>b;
	m=b;
	while(m>0)
	{
		m/=10;
		t*=10;
	}
	double r=sqrt(a*t+b);
	if(r==int(r))
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)
#define _popcnt __builtin_popcount

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int N, M; cin >> N;
  map<INTP, int> Idxdict;
  vector<INTV> Tree(N);
  vector<bitset<55> > Edge(N, 0ll);
  REP(i, N-1){
    int a, b; cin >> a >> b;
    a--; b--;
    Tree[a].eb(b); Tree[b].eb(a);
    Idxdict[{a, b}] = i; Idxdict[{b, a}] = i;
  }

  queue<int> que; que.push(0);
  INTV dist(N, -1); dist[0] = 0;
  while(!que.empty()){
    int pos = que.front(); que.pop();
    for(auto nx : Tree[pos]){
      if(dist[nx] == -1){
        que.push(nx);
        dist[nx] = dist[pos]+1;
      }
    }
  }

  REP(st, N){
    int pos = st;
    while(pos != 0){
      for(auto nx : Tree[pos]){
        if(dist[pos] == dist[nx] + 1){
          Edge[st] |= bitset<55>(1ll<<Idxdict[{pos, nx}]);
          pos = nx;
          break;
        }
      }
    }
  }

  cin >> M;
  vector<bitset<55>> white(M);
  REP(i, M){
    int u, v; cin >> u >> v;
    u--; v--;
    white[i] = Edge[u] ^ Edge[v];
  }

  int ans = 0;
  for(int bit = 1; bit < (1ll<<M); bit++){
    int popcnt = _popcnt(bit);
    bitset<55> bt = 0ll;
    REP(i, M){
      if((bit>>i) & 1) bt |= white[i];
    }
    if(popcnt & 1) ans += (1ll<<N-1-bt.count());
    else ans -= (1ll<<N-1-bt.count());
  }
  ans = (1ll<<N-1) - ans;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#define maxn 200+1       
using namespace std;
int n,a[maxn],ans;      
int main(){
    scanf("%d",&n);
    int md=n<<1;   
    for(int i=1;i<=md;++i)scanf("%d",&a[i]);
    sort(a+1,a+1+md);     
    for(int i=1;i<=md;i+=2)ans+=a[i];
    printf("%d\n",ans);
    return 0;
}

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

int main(){
    int n,m; cin >> n >> m;
    vector<bool> hole(n+1,true);
    for(int i=0;i<m;i++){
      int a; cin >> a;
      hole.at(a) = false;
    }

    vector<ll> dp(n+1,0);
    dp.at(0) = 1;

    for(int i=1;i<=n;i++){
      if(i==1){
        if(hole.at(i)) dp.at(i)=1;
      }else{
        if(hole.at(i)){
          dp[i]=(dp[i-1]+dp[i-2])%MOD;
        }else{
          dp[i]=0;
        }
      }
    }

    cout << dp.at(n) << endl;

    return 0;

}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string o, e, ans;  cin >> o >> e;
    int lenO = o.size();
    int lenE = e.size();
    if (lenO == lenE) {
      rep(i, lenO) {
        ans += o[i];
        ans += e[i];
      }
    } else {
      rep(i, lenO) {
        if (i == lenO - 1) {
          ans += o[i];
        } else {
          ans += o[i];
          ans += e[i];
        }
      }
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	map<long long int, long long int>dp;
	cin >> N;
	while (N) {
		dp[N] = 0;
		N >>= 1;
	}
	dp[1] = 1;
	for (auto &i : dp) {
		if (i.first < 2)continue;
		i.second = dp[i.first / 2] * 2 + 1;
	}
	cout << prev(dp.end())->second << endl;
	return 0;
}

Measured memory_bytes: 256
/*AOJ-ITP-4-1*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
 
public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
 
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String st[] = br.readLine().split(" ");
        int count = 0;
        double a = Integer.parseInt(st[0]);
        double b = Integer.parseInt(st[1]);
        
        if(!(a >= 1 && b >= 1 && a <= 10e9 && b <= 10e9)){System.exit(1);}
        
        int d = (int)(a / b);
        int r = (int)(a % b);
        double f = (a / b);
        BigDecimal x = new BigDecimal(f);
        x = x.setScale(5, BigDecimal.ROUND_HALF_UP);
        System.out.print(d + " " + r + " " );
        System.out.printf("%.5f",x);
        System.out.println();
    }
}

Measured memory_bytes: 24928
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(abs(a-b)+abs(b-c), min(abs(b-c)+abs(c-a), abs(c-a)+abs(a-b))) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
int a,b=0,c=0,d=0,out=0,i,point=0;
char x[10];
scanf("%d\n",&a);
for(i=0;i<a;i++){
while(1){
scanf("%s\n",x);
if(strcmp(x,"HIT")==0){
if(d==1){
point++;
d=0;
}
if(c==1){
d=1;
c=0;
}
if(b==1){
b=0;
c=1;
}
b=1;
}
else if(strcmp(x,"OUT")==0){
out++;
}
else{
point=point+b+c+d+1;
b=0;
c=0;
d=0;
}
if(out==3){
break;
}
}
printf("%d\n",point);
b=0,c=0,d=0,out=0,point=0;
}
return 0;
}




Measured memory_bytes: 1984
n = int(input())
ans = [0] * (n + 1)
 
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            val = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if val <= n:
                ans[val] += 1
 
print(*ans[1:], sep="\n")

Measured memory_bytes: 9256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y) {
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
int main(){
  string s;
  cin >> s;
  bool can = false;
  rep(i,3){
    if(s[i] == '7'){
      can = true;
    }
  }
  if(can){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3624
line = input()
elem = line.split()
n = int(elem[0])
k = int(elem[1])

line = input()

ans = ""
ans += line[:k - 1]
if line[k - 1] == 'A':
    ans += 'a'
elif line[k - 1] == 'B':
    ans += 'b'
else:
    ans += 'c'
ans += line[k:]

print(ans)


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

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

	string s;
	cin >> s;
	int l = s.length();

	if (s[(l - 1) / 2 - 1] != s[0] || s[(l + 3) / 2 - 1] != s[l - 1])
	{
		cout << "No";
		return 0;
	}
	else
	{
		for (int i = 0; i < l / 2; i++)
		{
			if (s[i] != s[l - i - 1])
			{
				cout << "No"; return 0;
			}
		}
	}
	cout << "Yes";	

	return 0;
}

Measured memory_bytes: 256
use std::env;
use std::io::*;
use std::str::*;
use std::mem;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}
fn read_char() -> char {
    let c = read::<String>();
    let c = c.chars().collect::<Vec<char>>();
    c[0]
}
fn read_String_Vec() -> Vec<char> {
    let S = read::<String>();
    S.chars().collect::<Vec<char>>()
}

fn vecchar_to_String(Vs: &Vec<char>) -> String {
    let mut S = String::new();
    for i in 0..Vs.len() {
        S.push(Vs[i]);
    }
    S
}

/*
A : 65
Z : 90
a : 97
z : 122
*/

/*
let N = read::<i32>();
let S = read::<String>();
let S = read_String_Vec();
let C = read_char();
*/

/*
 .to_string() : * -> String
 &*S          : String -> &str
*/

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let N = read::<usize>();
    let mut A = Vec::new();

    for i in 0..N {
        let tmp = read::<i32>();
        A.push (tmp);
    }
    let mut cnt = 0;
    loop {
        let mut even = true;
        for n in 0..N {
            if A[n]%2 == 0 {
                A[n] /= 2;
            } else {
                even = false;
                break;
            }
        }
        if even {
            cnt += 1;
        } else {
            break;
        }
    }
    println!("{}", cnt);

}


Measured memory_bytes: 4352
//0316
#include <iostream>
using namespace std;
int main(void){
    int x,y,z,u,a,b,c,d,H,K;
    cin >> x >> y >> z >> u >> a >> b >> c >> d;
    
    H=0;
    K=0;
    
    H += (x/10)*c+x*a;
    K += (z/10)*c+z*a;
    H += (y/20)*d+y*b;
    K += (u/20)*d+u*b;
    
    if(H>K)
        cout << "hiroshi" << endl;
        else if(H==K)
            cout << "even" << endl;
            else if(H<K)
                cout << "kenjiro" << endl;
    
    
}



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

using namespace std;
#define ll  long long
#define ld  long double

#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN=1e5+5;

int main()
{
    int a,b;
    cin>>a>>b;
    cout<<max(0,a-b)<<endl;
    return 0;
}


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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

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

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}
  bool merge(int x, int y){
    x = root(x), y = root(y);
    if (x != y){
      if (data[x] > data[y]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool isSame(int x, int y){
    return root(x) != root(y);
  }
  int size(int x){
    return -data[root(x)];
  }
  int root(int x){
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
};

int main()
{
  int w, h;
  while (w = in(), h = in(), w){
    UnionFind uf(w * h);
    vector<string> field;
    rep(i, h){
      string s;
      cin >> s;
      field.push_back(s);
    }
    int sx, sy;
    rep(y, h){
      rep(x, w){
        char cell = field[y][x];
        if (cell == '#') continue;
        if (cell == '@') {
          sx = x;
          sy = y;
        }
        rep(d, 4){
          int nx = x + dx[d];
          int ny = y + dy[d];
          if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
          if (field[ny][nx] != '#') uf.merge(y * w + x, ny * w + nx);
        }
      }
    }
    printf("%d\n", uf.size(sy * w + sx));
  }
  return 0;
}

Measured memory_bytes: 1244
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647;
const LL mod = 1000000007ll;

int N,M;
int s[5],c[5];
 
int ans = 0;
 
void solve(){
	vector<int> digit(3,-1);//左からi桁目の数をdigit[i]とおく
	for(int i=0;i<M;i++){
		if(digit[s[i]-1]==-1){
			digit[s[i]-1] = c[i];
		}else{
			if(digit[s[i]-1]!=c[i]){
				ans = -1;
				return;
			}
		}
	}

	if(digit[0]==0 && N>1){
		ans = -1;
		return;
	}

	if(N==3){
		if(digit[0]!=-1) ans += digit[0]*100;
		else ans += 100;
		if(digit[1]!=-1) ans += digit[1]*10;
		if(digit[2]!=-1) ans += digit[2];
	}

	if(N==2){
		if(digit[0]!=-1) ans += digit[0]*10;
		else ans += 10;
		if(digit[1]!=-1) ans += digit[1];
	}

	if(N==1){
		if(digit[0]!=-1) ans += digit[0];
	}
}
 
int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++) cin >> s[i] >> c[i];
 
	solve();
 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  while (cin >> N) {
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
      cin >> A[i];
    }
    sort(A.begin(), A.end());
    int n = A[N - 1];
    int mx = -1, k;
    for (int i = 0; i < N - 1; i++) {
      int t = min(A[i], A[N - 1] - A[i]);
      if (t > mx) {
        mx = t;
        k = A[i];
      }
    }
    cout << n << " " << k << endl;
  }
  return 0;
}


Measured memory_bytes: 640
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    n,m = readInt()
    h = readInt()
    ab = [set() for i in range(n)]
    for i in range(m):
        a,b = readInt()
        ab[a-1].add(b-1)
        ab[b-1].add(a-1)
    ans = 0
    for i in range(n):
        res = True
        for x in ab[i]:
            if h[i]<=h[x]:
                res = False
                break
        if res:
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 45260
#include <string>
#include <math.h>
#include <iostream>
using namespace std;
 
int main(){
	long long pos[5];
	long long n, Min;
  	long long t;
	int i;
 
	cin >> n;
	for(i = 0; i < 5;i++){
		cin >> pos[i];
	}
 
	Min = 1000000000000000;
	for(i = 0; i < 5;i++){
		if(pos[i] < Min){
			Min = pos[i];
		}
	}
 
	if(n % Min == 0)
		t = n/Min;
	else
		t = n/Min + 1;

	cout << t + 4 << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long



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

    int x; cin >> x;
    int a = x / 500;
    x %= 500;
    int b = x / 5;

    cout << a * 1000 + b * 5 << endl;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int node[5123][3123];
int root[5123][3123];

vector<ll> comb(const vector<ll> &a,const vector<ll> &b){
  const int t=a.size();
  assert(t==b.size());
  vector<ll> re(t);
  rep(i,t)rep(j,t-i) (re[i+j]+=a[i]*b[j]%MOD)%=MOD;
  return re;
}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  root[0][0]=node[0][0]=1;
  rep(i,5000){
    (root[i+1][0]+=root[i][0])%=MOD;
    rep(j,3000){
      if(j){
	(root[i+1][j-1]+=root[i][j])%=MOD;
	(node[i+1][j-1]+=node[i][j])%=MOD;
      }
      (root[i+1][j+1]+=root[i][j]*2%MOD)%=MOD;
      (node[i+1][j+1]+=node[i][j]*2%MOD)%=MOD;
    }
  }
  int t;
  string s;
  cin>>t>>s;
  int n=s.size();
  t-=n;
  vector<ll> dp(t/2+1),v(t/2+1);
  dp[0]=1;
  rep(i,t/2+1) v[i]=node[i*2][0];
  //cout<<dp<<v;
  for(int i=n;i;i/=2){
    if(i%2) dp=comb(dp,v);
    v=comb(v,v);
  }
  //cout<<dp;

  //rep(i,10){rep(j,10)cout<<root[i][j]<<",";cout<<endl;}cout<<endl;
  //rep(i,10){rep(j,10)cout<<node[i][j]<<",";cout<<endl;}cout<<endl;

  ll re=0;
  rep(i,t+1) if(i%2==0) (re+=root[t-i][0]*dp[i/2]%MOD)%=MOD;
  cout<<re<<endl;
  return 0;
}


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

int main() {
  int n,m,p;
  cin>>n>>m>>p;
  int a[m],b[m],c[m];
  rep(i,0,m){
    cin>>a[i]>>b[i]>>c[i];
    a[i]--;
    b[i]--;
    c[i]-=p;
  }
  int d[n];
  rep(i,0,n){
    d[i]=-3e8;
  }
  d[0]=0;
  rep(i,0,n){
    rep(j,0,m){
      if(d[a[j]]!=-3e8 && d[b[j]]<d[a[j]]+c[j]){
        d[b[j]]=d[a[j]]+c[j];
      }
    }
  }
  int ans=d[n-1];
  
  vector<int> to[n];
  vector<int> ot[n];
  rep(i,0,m){
    to[a[i]].push_back(b[i]);
    ot[b[i]].push_back(a[i]);
  }
  bool e[n];
  rep(i,0,n){
    e[i]=false;
  }
  e[0]=true;
  queue<int> q;
  q.push(0);
  while(q.size()){
    int r=q.front();
    q.pop();
    rep(i,0,to[r].size()){
      if(!e[to[r][i]]){
        e[to[r][i]]=true;
        q.push(to[r][i]);
      }
    }
  }
  
  bool f[n];
  rep(i,0,n){
    f[i]=false;
  }
  f[n-1]=true;
  q.push(n-1);
  while(q.size()){
    int r=q.front();
    q.pop();
    rep(i,0,ot[r].size()){
      if(!f[ot[r][i]]){
        f[ot[r][i]]=true;
        q.push(ot[r][i]);
      }
    }
  }
  
  bool g[n];
  rep(i,0,n){
    if(f[i] && e[i]){
      g[i]=true;
    }
    else{
      g[i]=false;
    }
  }
  
  bool h=true;
  rep(j,0,m){
    if(d[a[j]]!=-3e8 && d[b[j]]<d[a[j]]+c[j]){
      if(g[b[j]]){
        h=false;
      }
    }
  }
  
  if(h) cout<<max(0,ans)<<endl;
  else cout<<-1<<endl;
}


Measured memory_bytes: 640
// Template by [thunder_blade]
// IIIT ALLAHABAD
// includes :)

#include <bits/stdc++.h>
#include <ext/rope> 
using namespace __gnu_cxx;
using namespace std;
#define TEST  int test_case; cin>>test_case; while(test_case--)
#define all(v) (v).begin(),(v).end()
#define fi  first
#define se  second
#define pb push_back
#define mp make_pair
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);  cin.tie(0);  cout.tie(0);
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define pf(x) printf("%f\n",x)
#define ps(x) printf("%s\n",x)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sf(x) scanf("%f",&x)
#define ss(x) scanf("%s",x)
#define pis(x) printf("%d ",x)
#define pls(x) printf("%lld ",x)
#define pfs(x) printf("%f ",x)
#define pss(x) printf("%s ",x)
#define FOR(i,a,b) for(i=a;i<b;i++)
#define mod 1000000007
#define tr(container, it)  for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

const int N = 5000005;

int main()
{
    ll n,m, ans=1,f=0;
    sl(n), sl(m);
    ll var = n+m;
    if(n==m)
        f=1;
    if(n<m){
        swap(n,m);
    }
    for(int i=1;i<=var;i++){
        if(i%2){
            ans = ((ans%mod)*(n%mod))%mod;
            n--;
        }
        else{
            ans = ((ans%mod)*(m%mod))%mod;
            m--;
        }
        ans%=mod;
    }
    if(f)
        ans = ((ans%mod)*(2%mod))%mod;
    pl(ans);
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns        #-}
{-# LANGUAGE FlexibleContexts    #-}
{-# LANGUAGE MultiWayIf          #-}
{-# LANGUAGE RankNTypes          #-}
{-# LANGUAGE ScopedTypeVariables #-}
import           Control.Monad.State
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import qualified Data.Vector.Unboxed   as VU

main :: IO ()
main = do
  n <- readLn :: IO Int
  abcs <- readLnAsUVecWith3Tuple unconsInt n

  print $ solve n abcs


solve :: Int -> VU.Vector (Int,Int,Int) -> Int
solve n abcs = go 1 $ abcs VU.! 0
  where go :: Int -> (Int,Int,Int) -> Int
        go m (a,b,c)
          | m == n = maximum [a,b,c]
          | otherwise = let (a',b',c') = abcs VU.! m
                        in go (m+1) ((a' + max b c),(b' + max c a),(c' + max a b))


unconsInt :: StateT BS.ByteString Maybe Int
unconsInt = StateT $ BS.readInt . BS.dropWhile isSpace

-- for unboxed vector
readLnAsUVecWith :: VU.Unbox a => StateT BS.ByteString Maybe a -> Int -> IO (VU.Vector a)
readLnAsUVecWith !st !n = VU.unfoldrN n (runStateT st) <$> BS.getLine

-- example: 1D tuple vector
readLnAsUVecWith3Tuple :: VU.Unbox a => StateT BS.ByteString Maybe a -> Int -> IO (VU.Vector (a,a,a))
readLnAsUVecWith3Tuple !st !n = VU.replicateM n $ (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2)) <$> readLnAsUVecWith st 3


Measured memory_bytes: 56584
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

void printV(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

/* answer */

int candidates[50000];
int a[] = {3, 5, 7};
int insert_index = 0;

void rekkyo(int keta, string s){
    //cout << keta << " " << s << endl;
    if(keta <= 0){
        candidates[insert_index] = stoi(s);
        insert_index++;
        return;
    }
    rekkyo(keta - 1, s + "7");
    rekkyo(keta - 1, s + "5");
    rekkyo(keta - 1, s + "3");
}

bool is_753(int v){
    string s = to_string(v);
    bool is_exist_3 = false;
    bool is_exist_5 = false;
    bool is_exist_7 = false;
    
    for(char c : s) {
        if(c == '3'){
            is_exist_3 = true;
        }else if(c == '5'){
            is_exist_5 = true;
        }else if(c == '7'){
            is_exist_7 = true;
        }
    }

    if(is_exist_3 && is_exist_5 && is_exist_7){
        return true;
    }else{
        return false;
    }
}

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

    // make candidates list
    for(int keta=3; keta<=9; keta++){
        rekkyo(keta, "");
    }

    for(int i=0; i<100; i++){
        //cout << candidates[i] << endl;
    }

    // check
    int count = 0;
    for(int i=0; i<insert_index; i++){
        int candidate = candidates[i];
        if(candidate <= n && is_753(candidate)){
            count++;
        }
    }

    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

int main() {
	long long N;
	cin >> N;
	map<long long, long long> card;
	long long pair = 0;
	for (long long i = 0; i < N; ++i) {
		cin >> card[i];
	}

	for (long long i = 1; i < N; ++i) {
		pair += (card[i - 1]) / 2;
		card[i - 1] = card[i - 1] % 2;
		
		long long buf = min(card[i], card[i - 1]);
		pair += buf;
		card[i] -= buf;
		card[i - 1] -= buf;
	}
	pair += (card[N - 1]) / 2;
	card[N - 1] = card[N - 1] % 2;

	cout << pair << endl;
	return 0;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  cin >> k;
  int a,b;
  cin >> a >> b;
  bool ans=false;
  int res=a;
  for(int i=0;i<b-a+100;++i) {
    if(res%k==0 && res<=b) {
      ans=true;
      break;}
    res++;
  }
  puts(ans?"OK":"NG");
  return 0;
}

Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;;
#define ato find_by_order
#define of order_of_key
typedef long long ll;
#define mp make_pair
#define pb push_back
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
int main()
{
    flash
    ll n;ll x;ll m;
    cin>>n>>x>>m;ll cnt=n-1;ll sum=x;
    if(x%m==0)
    {
        cout<<"0"<<endl;
        return 0;
    }
    map<ll,ll> maxu;map<ll,ll> s;s[0]=0;s[1]=x;ll dix=0;ll ins=0;
    for(ll i=1;i<=n-1;i++)
    {
        x=(x*x)%m;
        if(maxu.find(x)!=maxu.end())
        {
            ins=s[i]-s[maxu[x]-1];
            dix=(i+1)-(maxu[x])+1;
            break;
        }
        maxu[x]=i+1;
        cnt--;
       sum=(sum+x);
       s[i+1]=sum;
    }
    ll yo=cnt/(dix-1);yo=yo*ins;
    yo+=(s[maxu[x]-1+cnt%(dix-1)]-s[maxu[x]-1]);
    cout<<yo+sum<<endl;
}

Measured memory_bytes: 9836