akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const long long INFL = 2e18;
const int MOD = 1000000007;
int main(){
	int h,w,k;
	cin >> h >> w >> k;

	vector<string> grid(h);
	for(int i = 0;i < h;i++)cin >> grid[i];

	vector<vector<int>> sum_accum(h+1,vector<int>(w+1,0));

	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			if(grid[i][j] == '1')sum_accum[i+1][j+1] = 1;
		}
	}

	for(int i = 0;i <= h;i++){
		for(int j = 1;j <= w;j++){
			sum_accum[i][j] += sum_accum[i][j-1];
		}
	}

	for(int i = 0;i <= w;i++){
		for(int j = 1;j <= h;j++){
			sum_accum[j][i] += sum_accum[j-1][i];
		}
	}


	int ans = INF;

	for(int i = 0;i < (1 << h);i++){
		vector<int> cut_h;
		cut_h.push_back(0);
		for(int j = 0;j < h;j++){
			if((i >> j) & 1){
				cut_h.push_back(j+1);
			}
		}

		if(cut_h[cut_h.size()-1] != h)cut_h.push_back(h);

		int prev_cut_w = 0;
		int cnt = 0;
		bool flag = true;
		for(int i = 1;i <= w;i++){
			for(int j = 1;j < cut_h.size();j++){
				int now_cnt = sum_accum[cut_h[j]][i] - sum_accum[cut_h[j-1]][i] - sum_accum[cut_h[j]][prev_cut_w] + sum_accum[cut_h[j-1]][prev_cut_w];
				int next_cnt;
				if(i != w){
					next_cnt = sum_accum[cut_h[j]][i+1] - sum_accum[cut_h[j-1]][i+1] - sum_accum[cut_h[j]][prev_cut_w] + sum_accum[cut_h[j-1]][prev_cut_w];
				}
				if(now_cnt > k)flag = false;
				if(i != w && now_cnt <= k && next_cnt > k){
					prev_cut_w = i;
					cnt++;
				}
			}
		}
		if(flag)ans = min(cnt + (int)cut_h.size() - 2,ans);
	}


	cout << ans << endl;
}


Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//BufferedReader in = new BufferedReader(new FileReader(new File("input.txt")));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] l = in.readLine().split(" ");
		byte a,b,c;
		a=Byte.valueOf(l[0]);
		b=Byte.valueOf(l[1]);
		c=Byte.valueOf(l[2]);
		if(a<b) {
			System.out.println(a<c&&c<b?"Yes":"No");
		}else {
			System.out.println(b<c&&c<a?"Yes":"No");
		}
	}
}


Measured memory_bytes: 20948
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    ll k;
    cin >> s >> k;
    ll n = s.size();

    if(n < k) {
        rep(i, n) {
            if(s[i] != '1') {
                out(s[i]);
                re0;
            }
        }
        out('1');
    }
    else {
        rep(i, k) {
            if(s[i] != '1') {
                out(s[i]);
                re0;
            }
        }
        out('1');
    }
    
    re0;
}

Measured memory_bytes: 256
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.Unboxed          as AU
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import           Data.Ord
import           Data.Time
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegerLists :: Int -> IO [[Integer]]
readIntegerLists n =
  replicateM n (map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine)

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntLists :: Int -> IO [[Int]]
readIntLists n =
  replicateM n (map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine)

readStrings :: IO [String]
readStrings = map BS.unpack . BS.words <$> BS.getLine

readStringLists :: Int -> IO [[String]]
readStringLists n = replicateM n (map BS.unpack . BS.words <$> BS.getLine)

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main :: IO ()
main = do
  a <- getLine
  putStrLn $ map solve a
  return ()

solve 'A' = 'T'
solve 'T' = 'A'
solve 'G' = 'C'
solve 'C' = 'G'


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; return(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

vl eratos(const ll n) {
    vb is_prime(n + 1);
    vl p;

    for (int i = 0; i <= n; i++) {
        is_prime[i] = true;
    }

    for (int i = 2; i <= n; i++) {
        if (!is_prime[i]) continue;

        for (int j = 2 * i; j <= n; j += i) {
            is_prime[j] = false;
        }
        p.emplace_back(i);
    }
    return p;
}


int main() {
    cin >> n;
    vl a(n+10);
    IPT(a, n);

    ans = 0;
    NREP() {
        ans += a[i] - 1;
    }
    MSG(ans)
}


Measured memory_bytes: 3652
#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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  double n, m; cin >> n >> m;
  double sum = 0;
  vector<double> a(n);
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }

  int cnt = 0;
  double x = sum/(4*m);
  rep(i, n) {
    cnt += (a[i] >= x);
  }
  cout << (cnt >= m ? "Yes" : "No")  << endl;
}


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

int main() {
   int n, k;
   cin >> n >> k;
   vector<int> h(n);
   rep(i, n) {
       cin >> h[i];
   }

   if (n <= k) {
       cout << 0 << endl;
       return 0;
   }

   sort(h.rbegin(), h.rend());

   ll ans = 0;
   rep2(i, k, n) {
       ans += h[i];
   }

   cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int,int> >adj[MAX];

void dijkstra(){
  priority_queue<pair<int, int> >PQ;
  int i,j;
  int d[MAX],color[MAX];

  for(i = 0;i < n;i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  PQ.push(make_pair(0,0));
  color[0] = GRAY;

  while(!PQ.empty()){
    pair<int,int>a = PQ.top(); PQ.pop();

    int u = a.second;
    color[u] = BLACK;

    if(d[u] < a.first*(-1)) continue;

    for(j = 0;j < adj[u].size();j++){
      int v = adj[u][j].first;

      if(color[v] == BLACK) continue;
      if(d[v] > d[u] + adj[u][j].second){
    	  d[v] = d[u] + adj[u][j].second;
    	  PQ.push(make_pair(d[v]*(-1),v));
    	  color[v] = GRAY;
      }
    }
  }

  for(i = 0;i < n;i++){
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

int main(){
  int i, j, k, u, v, c;

  cin >> n;
  for(i = 0;i < n;i++){
    cin >> u >> k;
    for(j = 0;j < k;j++){
      cin >> v >> c;
      adj[u].push_back(make_pair(v, c));
    }
  }

  dijkstra();

  return 0;
}



Measured memory_bytes: 8052
#include <bits/stdc++.h>
#define ll long long
#define INF INT_MAX 
#define mod 1000000007
using namespace std;
int main(){
    int R,G,B,N;
    int ans = 0;
    cin >> R >> G >> B >> N;
    
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            if((N >= (R*i+G*j) && (N-(R*i+G*j)) % B == 0)){
                ans++;
            } 
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#define fast_cin ios_base::sync_with_stdio(false); cin.tie(NULL)
#define endl "\n"
#define dump(x) cerr<<"~ "<<#x<<" = "<<x<<endl

#define N 1000006

int cnt[N],ar[N];


int main() {

	int n,x,tmp,u,d,flag = 0,ans;
	string s;

	for(int i = 1; i <= N; i++) {

		cnt[i] = cnt[i-1];
		
		x = i;
		tmp = 0;
		
		while( !(x & 1) ) {
			x >>= 1; tmp++;
		}

		cnt[i] += tmp;
	}

	cin >> n;
	cin >> s;

	for(int i = 1; i <= n; i++) {
		ar[i] = (s[i-1] - '1');
		if(ar[i] == 1) flag = 1;
	}

	for(int i = 1; i <= n; i++) {
		if(ar[i] == 2) {
			ar[i] = flag ^ 1;
		}
	}

	ans = 0;

	for(int i = 1; i <= n; i++) {
		
		u = cnt[n-1];
		d = (cnt[i-1] + cnt[n-i]);

		if(u == d) {
			ans ^= ar[i];
		}
	}

	if(!flag and ans) {
		ans++;
	}

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

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


#define base 1000000007LL
#define ll long long
// unsigned long long int t = 10000000000000000003ULL;
#define ulint unsigned long long int
#define ld long double
#define X first
#define Y second
#define pb push_back
#define EPS 1e-15
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())

#define ms(s, n) memset(s, n, sizeof(s))

#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define sqr(a) (a)*(a)

#define foru(i,a,b) for (ll i = (a); i <= (b); i++)
#define ford(i,a,b) for (ll i = (a); i >= (b); i--)
#define cbit(a) __builtin_popcount(a)
#define uni(a) (a).resize(unique(all(a)) - (a).begin())
#define cprint(n) printf("%.6lf + %.6lfi\n", (n).real(), (n).imag())

#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it !=(a).end(); it++)


using namespace std;
typedef pair<ll, ll> II;
typedef pair<int, int> ii;



struct Edge{
    ll u,v,w;
    Edge(ll u=0, ll v=0, ll w=0): u(u),v(v),w(w) {}
    bool operator < (Edge a){return w<a.w;}
};

const int M=1e5+7;
const int MM=4*M;
const ll MOD=base;
const int MAX=1e9;


inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll power(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = r * n % p; n = n * n % p;} return r;}
inline ll inverse(ll n, ll p=MOD){return power(n,p-2);}
ll search(ll a[], ll N, ll x){ ll l = 0, r = N - 1; while (l <= r){ ll mid = (l + r) / 2; if (x == a[mid]){ return 1; } else if (x < a[mid]){ r = mid - 1; } else if (x > a[mid]){ l = mid + 1; } } return -1; }

string s;

int main(){
    ios::sync_with_stdio(0);
	cin >> s;
	int c = 0;
	string ans = "AC";
	if(s[0] != 'A'){
		ans = "WA";
	}
	for(int i = 1; i < s.size(); i++){
		if(isupper(s[i])){
			c++;
			if(i == 1 || i == s.size() - 1){
				ans = "WA";
			}
			if(s[i] != 'C'){
				ans = "WA";
			}
		}
	}
	if(c != 1){
		ans = "WA";
	}
	cout << ans;
    return 0;
}





Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	char str[20];
	cin >> str;
	int seek;
	for(seek = 0;seek < 20;seek++) {
		if(str[seek] == '\0') {
			break;
		}
	}
	seek--;
	for(int rv = seek;rv>=0;rv--) {
		cout << str[rv];
	}
	cout << endl;
	
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repc(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const double PI = acos(-1);


int main(){
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double sh, lh, arg;
  sh = h * 5 + m / 12;
  lh = m;
  arg = abs(sh - lh) / 60;
  double ans;
  ans = sqrt(a*a + b*b - 2*a*b*cos(2*PI*arg));
  cout << fixed << setprecision(12) << ans << endl;
}

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

using namespace std;

#define ll long long

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

    vector<double> x(n), y(n);
    for(int i = 0;i < n;++i)    cin >> x[i] >> y[i];

    vector<vector<double>> dist(n, vector<double>(n, 0.0));
    for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
            dist[i][j] = sqrt(pow(x[i]-x[j], 2.0) + pow(y[i] - y[j], 2.0));
        }
    }

    double ans = 0.0;
    double haha = 1.0;

    for(int i = 0;i < n;++i){
        haha = haha * (double)(i + 1);
    }

    for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
            ans += dist[i][j] * haha/(double)n;
        }
    }

    printf("%.10lf\n", ans/haha);



    return 0;
}



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

int main() {
  string s;
  cin >> s;
  int ans;
  if (s=="SSS") ans=0;
  else if (s=="SSR" || s=="SRS" || s=="RSS" || s=="RSR") ans=1;
  else if (s=="RRS" || s=="SRR") ans=2;
  else if (s=="RRR") ans=3;
  cout << ans;
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
int bsr(int x) { return 31 - __builtin_clz(x); }

using VI = vector<int>;
using G = vector<vector<int>>;
G calc(int n) {
    assert(n >= 2);
    G res = G(n);
    if (n == 4) {
        res[0] = VI{1, 2, 3};
        res[1] = VI{2, 3, 0};
        res[2] = VI{0, 3, 1};
        res[3] = VI{1, 0, 2};
        return res;
    } 
    if (n % 2) {
        for (int i = 0; i < n-1; i++) {
            for (int j = 0; j < n; j++) {
                res[j].push_back((j+i+1)%n);
            }
        }
        return res;
    }
    // divide and conquer
    auto dg = calc(n/2);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n/2-1; j++) {
            res[i].push_back(dg[i/2][j]*2+(i%2));
        }
    }

    vector<int> r(n/2);
    for (int i = 0; i < n/2; i++) {
        r[i] = 2*i+1;
    }
    for (int fe = 0; fe < n/2; fe++) {
        for (int i = 0; i < n/2; i++) {
            int li = 2*i, ri = r[i];
            res[li].push_back(ri);
            res[ri].push_back((li+2)%n);
        }
        rotate(r.begin(), r.begin()+1, r.end());
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if (n == 2) {
        cout << -1 << endl;
        return 0;
    }
    auto g = calc(n);
    for (int i = 0; i < n; i++) {
        for (auto d: g[i]) {
            cout << d+1 << " ";
        } cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

ll tmp[202020];

int main(){

    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    map<ll, ll>cnt;
    tmp[0] = 0;
    cnt[0] = 1;
    rep1(i, N){
        if(i - K >= 0)cnt[tmp[i - K]]--;
        ll a;
        cin >> a;
        tmp[i] = (tmp[i - 1] + a + K - 1) % K;
        ans += cnt[tmp[i]];
        cnt[tmp[i]]++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<endl
#define AA(i) cout<<i<<endl
const int U=2e5+5;
const ll MOD=998244353;
const int INF = 1001001001;

int main(){
    int N,K; cin>>N>>K;
    int i;
    for(i=1;;i++){
        N = N/K;
        if(N==0)break;
    }
    AA(i);
    return 0;
}

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

// ------ graph ------ //
using Weight = long long;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) { }
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // pqが降順のため
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
using Edges = vector<Edge>;
struct Graph {
    vector<Edges> adj;
    Graph(int n) : adj(n) { }
    int size() { return adj.size(); }
    Edges operator [] (int v) { return adj[v]; }
    void add_edge(int a, int b, Weight w = 1) { // graph
        adj[a].emplace_back(a, b, w);
        adj[b].emplace_back(b, a, w);
    }
    void add_arc(int a, int b, Weight w = 1) {  // digraph
        adj[a].emplace_back(a, b, w);
    }
};
using Array = vector<Weight>;
using Matrix = vector<Array>;
using UnweightedGraph = vector<vector<int>>;

// ------ Low-Link ------ //
struct LowLink {
    vector<int> aps;                // articulation points
    vector<pair<int, int>> brs;     // brides
    vector<int> seen, ord, low;
    int dfs(const UnweightedGraph &G, int u, int p = -1, int time = 0) {
        seen[u] = true;
        ord[u] = low[u] = time++;
        bool exists = false;
        int cnt_ch = 0;
        for (auto v : G[u]) {
            if (!seen[v]) {
                ++cnt_ch;
                time = dfs(G, v, u, time);
                low[u] = min(low[u], low[v]);   // forward edge
                if (ord[u] < low[v]) brs.emplace_back(u, v);
                if (ord[u] <= low[v]) exists = true;
            } else if (v != p) {
                low[u] = min(low[u], ord[v]);   // back edge
            }
        }
        if ((p == -1 && cnt_ch > 1) || (p != -1 && exists)) {
            aps.emplace_back(u);
        }
        return time;
    }
    void solve(const UnweightedGraph &G) {
        int N = G.size();
        seen.assign(N, 0); ord.resize(N); low.resize(N);
        aps.clear(); brs.clear();
        for (int v = 0; v < N; ++v) if (!seen[v]) dfs(G, v);
        for (auto &br: brs) if (br.first > br.second) swap(br.first, br.second);
        sort(brs.begin(), brs.end());
        sort(aps.begin(), aps.end());
    }
};

int main() {
    int V, E; cin >> V >> E;
    UnweightedGraph G(V);
    while (E--) {
        int s, t; cin >> s >> t;
        G[s].emplace_back(t);
        G[t].emplace_back(s);
    }
    LowLink ll;
    ll.solve(G);

    for (auto b: ll.brs) cout << b.first << " " << b.second << endl;
    return 0;
}


Measured memory_bytes: 4496
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k,l;
  int a[100],lx[100][100],uy[100][100],rx[100][100],dy[100][100],x,y,m,n,w,h;
  int cr,sz;
  string s[100],t[100][100],v;
  vector<string> u;
  while(cin>>n&&n){
    cin>>w>>h;
    for(i=0;i<n;i++){
      cin>>s[i]>>a[i];
      for(j=0;j<a[i];j++)
	cin>>lx[i][j]>>uy[i][j]>>rx[i][j]>>dy[i][j]>>t[i][j];
    }
    u.clear();
    u.push_back(s[0]);
    cr=0;
    cin>>m;
    for(i=0;i<m;i++){
      cin>>v;
      if(v=="click"){
	cin>>x>>y;
	for(j=0;u[cr]!=s[j];j++);
	for(k=0;k<a[j];k++){
	  if(lx[j][k]<=x&&x<=rx[j][k]&&uy[j][k]<=y&&y<=dy[j][k])
	    break;
	}
	if(k!=a[j]){
	  sz=u.size();
	  for(l=0;l<sz-cr-1;l++)
	    u.pop_back();
	  u.push_back(t[j][k]);
	  cr++;
	}
      }else if(v=="show"){
	cout<<u[cr]<<endl;
      }else if(v=="back"){
	if(cr)
	  cr--;
      }else if(v=="forward"){
	if(cr!=(int)u.size()-1)
	  cr++;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
N, Y = (int(x) for x in input().split())
ichiman = -1
gosen = -1
sen = -1

for x in range(N + 1):
    for y in range(N + 1):
        z = N - x - y
        if z >= 0 and (10000 * x + 5000 * y + 1000 * z == Y):
            ichiman = x
            gosen = y
            sen = z
            break

print(ichiman, ' ', gosen, ' ', sen)

Measured memory_bytes: 3064
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
#define TP int
inline TP read(){
    char c=getchar();TP x=0;bool f=0;
    while(!isdigit(c))f^=!(c^45),c=getchar();
    while(isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f)x=-x;return x;
}
int dic[12093];
char s[1000010];
int main()
{
	dic['b']=0;dic['p']=1;dic['d']=2;dic['q']=3;
	cin>>(s+1);
    for(int l=strlen(s+1),i=1;i<=(l>>1)+1;i++)
    {
        if(dic[s[i]]!=((dic[s[l-i+1]]+2)%4))return puts("No"),0;
    }puts("Yes");
    return 0;
}


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

 

 
int32_t main() 
{
	//ll INF = 10000000000;
	
		ll n = -1, m = -1, l = -1, q = -1, a, b, c, s, t;
		cin >> n >> m >> l;
		//if (n <= 0) break;
		vector<vector<ll>> d(n,vector<ll>(n,INF));
		vector<vector<ll>> h(n, vector<ll>(n, INF));
		for (ll i = 0; i < m; ++i) 
        {
			cin >> a >> b >> c;
			d[a - 1][b - 1] = c;
			d[b - 1][a - 1] = c;
		}
		for (ll i = 0; i < n; ++i) {
			h[i][i] = 0;
		}
		for (ll k = 0; k < n; ++k) {
			for (ll i = 0; i < n; ++i) {
				for (ll j = 0; j < n; ++j) {
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
					if (d[i][j] <= l) {
						h[i][j] = 1;
					}
				}
			}
        }
		for (ll k = 0; k < n; ++k) {
			for (ll i = 0; i < n; ++i) {
				for (ll j = 0; j < n; ++j) {
					h[i][j] = min(h[i][j], h[i][k] + h[k][j]);
				}
			}
		}
		cin >> q;
		for (ll i = 0; i < q; ++i) {
			cin >> s >> t;
			ll dist = h[s - 1][t - 1];
			cout << (dist < INF ? dist - 1 : -1) << endl;
		}
	
	return 0;
}

Measured memory_bytes: 1920
object Main extends App {


  val (n, q)                        = readLine.split(" ").map(_.toInt) match { case Array(n, q) => (n, q)}
  val init: IndexedSeq[(String, Int)] = (1 to n)
    .map(_ => readLine)
    .map(_.split(" ") match {
      case Array(name, time) => (name, time.toInt)
    })
    .toIndexedSeq

  def exec(s: (IndexedSeq[(String, Int)], IndexedSeq[(String, Int)], Int)): (IndexedSeq[(String, Int)], IndexedSeq[(String, Int)], Int) = s match {
    case (h +: tail, acc, total) => if (h._2 <= q) (tail, (h._1, h._2 + total) +: acc, total + h._2) else (tail :+ (h._1, h._2 - q), acc, total + q)
    case _ => ???
  }

  val last = Stream.iterate((init, IndexedSeq[(String, Int)](), 0))(exec).span(_._1.nonEmpty) match {
    case (h, t) => t.head
  }
  last._2.sortBy(_._2).foreach {
    case (name, time) => println(name + " " + time)
  }

}


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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, a, b; cin >> n >> a >> b;
    cout << min(n * a, b) <<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int i, j=0, n, p, q, A[50], B[1000];
  while(1) {
    scanf("%d %d", &n, &p);
    if((n == 0) && (p == 0)) break;
    for(i=0; i<n; i++) {
      A[i] = 0;
    }
    i=0;
    q=p;
    while(1) {
      if(A[i] == q) break;
      if(p == 0) {
	p = A[i];
	A[i] = 0;
      } else  {
	p--;
	A[i]++;
      }
      ++i;
      if(i == n) i = 0;
    }
    B[j] = i;
    j++;
  }
  for(i=0; i<j; i++) {
    printf("%d\n",B[i]);
  }
  return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a < b) cout << "a < b";
    if(a == b) cout << "a == b";
    if(a > b) cout << "a > b";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3124
import java.util.Scanner;
public class Main {
	static int[][] gyo2=new int[100000][12];
	static int count=0;
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		long X=sc.nextLong();
		int C[]=new int[N];
		int A[][]=new int[N][M];
		for(int i=0;i<N;i++) {
			C[i]=sc.nextInt();
			for(int j=0;j<M;j++) {
				A[i][j]=sc.nextInt();
			}
		}
		int gyo[]=new int[N];
		zenbit(0,N,gyo);
		long ans=1000000000;
		boolean flag=true;
		boolean kuso=false;
		for(int i=0;i<count;i++) {
			int money=0;
			int kari[]=new int[M];
			for(int j=0;j<N;j++) {
			if(gyo2[i][j]==1) {
				for(int z=0;z<M;z++) {
				kari[z]+=A[j][z];
				}
				money+=C[j];
			}
				}
			for(int j=0;j<M;j++) {
				if(X>kari[j]) {
					flag=false;
					//System.out.println(money);
					//System.out.println(kari[j]);
				}
			}
			if(flag) {kuso=true;
			}
			if(flag&&(ans>money)) {
				ans=money;
			}
			flag=true;
		}
		if(kuso) {
			System.out.println(ans);
		}else {
			System.out.println(-1);
		}

}
	public static void zenbit(int kosu,int N,int gyo[]) {
		if(kosu<N) {
			gyo[kosu]=0;
			zenbit(kosu+1,N,gyo);
			gyo[kosu]=1;
			zenbit(kosu+1,N,gyo);
		}else {
			for(int i=0;i<N;i++) {
				gyo2[count][i]=gyo[i];
			}
			count++;
			return;
		}
	}

}


Measured memory_bytes: 44520
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val abcde = Array.fill(5)(sc.nextInt)
    val k = sc.nextInt

    if (abcde.max - abcde.min > k) ":(" else "Yay!"
  }
}


Measured memory_bytes: 25928
def main():
    C = str(input())
    ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
    list_ascii_lowercase = list(ascii_lowercase)
    for c in list_ascii_lowercase:
        if C == c:
            i = list_ascii_lowercase.index(c)
            print(list_ascii_lowercase[i + 1])



if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
let () =
  let n = read_int () in
  let rec read = function
      0 -> ()
    | i ->
       let line = read_line ()
                  |> Str.split (Str.regexp " ")
                  |> List.map int_of_string in
       let rec insert b c = function
           [] -> true
         | hd::tl -> if List.length b = 0 || List.hd b < hd then
                       insert (hd::b) c tl
                     else if List.length c = 0 || List.hd c < hd then
                       insert b (hd::c) tl
                     else
                       false
       in print_endline (if insert [] [] line then "YES" else "NO");read (i-1)
  in read n;;

Measured memory_bytes: 2108
#include <functional>  
#include <algorithm>  
#include <iostream>  
#include <fstream>  
#include <sstream>  
#include <iomanip>  
#include <numeric>  
#include <cstring>  
#include <cassert>  
#include <cstdio>  
#include <string>  
#include <vector>  
#include <bitset>  
#include <queue>  
#include <stack>  
#include <cmath>  
#include <ctime>  
#include <list>  
#include <set>  
#include <map> 
#include <bits/stdc++.h>

using namespace std;

#define PB push_back  
#define MP(A, B) make_pair(A, B)  
#define fi first  
#define se second  

#define gcd(a,b) __gcd(a,b)
#define pi acos(-1.0)
#define pii pair<int,int>
#define ll long long  
#define MAX 1000005  
#define MOD 1000000007  
#define INF 0x3f3f3f3f  
#define EXP 1e-8  
#define lowbit(x) (x&-x)  
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int nobind = []() {std::ios::sync_with_stdio(false);cin.tie(NULL);return 0;}();

/*************************************** 
prime table 
O(n) 
***************************************/  
const int PRIMERANGE = 1000000;  
int prime[PRIMERANGE + 1];  
int getPrime() {  
    memset (prime, 0, sizeof (int) * (PRIMERANGE + 1));  
    for (int i = 2; i <= PRIMERANGE; i++) {  
        if (!prime[i]) prime[++prime[0]] = i;  
        for (int j = 1; j <= prime[0] && prime[j] <= PRIMERANGE / i; j++) {  
            prime[prime[j]*i] = 1;  
            if (i % prime[j] == 0) break;  
        }  
    }  
    return prime[0];  
}  
/*************************************** 
get factor of n 
O(sqrt(n)) 
factor[][0] is prime factor 
factor[][1] is factor generated by this prime 
factor[][2] is factor counter 

need: Prime Table 
***************************************/  
///you should init the prime table before  
long long factor[100][3], facCnt;  
long long getFactors(long long x) {  
    facCnt = 0;  
    long long tmp = x;  
    for(long long i = 1; prime[i] <= tmp / prime[i]; i++) {  
        factor[facCnt][1] = 1, factor[facCnt][2] = 0;  
        if(tmp % prime[i] == 0)  
            factor[facCnt][0] = prime[i];  
        while(tmp % prime[i] == 0)  
            factor[facCnt][2]++, factor[facCnt][1] *= prime[i], tmp /= prime[i];  
        if(factor[facCnt][1] > 1) facCnt++;  
    }  
    if(tmp != 1)  
        factor[facCnt][0] = tmp, factor[facCnt][1] = tmp, factor[facCnt++][2] = 1;  
    return facCnt;  
}  

// hash func for pair
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const { 
        auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

int main() {
    int h1, m1, h2, m2, k;
    cin>>h1>>m1>>h2>>m2>>k;
    int t1 = h1 * 60 + m1, t2 = h2 * 60 + m2;
    cout << t2 - t1 - k <<endl;
    return 0;
}

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

int main(void) {
    int A, B, C, D, left, right;
    cin >> A >> B >> C >> D;
    left = A + B;
    right = C + D;

    if (left > right) {
        cout << "Left" << endl;
    } else if (left == right) {
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	long i,n,ai;
	long max=-1000001,min=1000001,sum=0;
	scanf("%ld",&n);

	for (i = 0; i < n; i++)
	{
		scanf("%ld",&ai);
		
		if (max < ai)
		{
			max=ai;
		}
		if (min > ai)
		{
			min=ai;
		}
		
		sum+=ai;
	}

	printf("%ld %ld %ld\n",min,max,sum);
	
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 100000;
const int INF = 1e9 + 5;
 
int pa[MAXN+5], sz[MAXN+5], a[MAXN+5], N, K, Q;
PII b[MAXN+5];
bool enable[MAXN+5];
multiset<int> global;
priority_queue<int, vector<int>, greater<int>> candidate[MAXN+5];
 
void init() {
	for (int i = 0; i < N; i++) {
		pa[i] = i;
		sz[i] = 1;
		enable[i] = false;
		candidate[i].push(a[i]);
	}
}
 
int find_root(int x) {
	return pa[x] == x ? x : pa[x] = find_root(pa[x]);
}
 
void merge(int x, int y) {
	x = find_root(x);
	y = find_root(y);
	if (x == y) return;
	if (sz[x] < sz[y]) swap(x, y);
	while (!candidate[y].empty()) {
		candidate[x].push(candidate[y].top());
		candidate[y].pop();
	}
	pa[y] = x;
	sz[x] += sz[y];
}
 
int test(PII p) {
	int x = p.first, pos = p.second;
	enable[pos] = true;
	if (pos > 0 && enable[pos - 1]) merge(pos, pos - 1);
	if (pos < N - 1 && enable[pos + 1]) merge(pos, pos + 1);
	
	int root = find_root(pos);
	while (candidate[root].size() >= K) {
		if (global.size() < Q) {
			global.insert(candidate[root].top());
			candidate[root].pop();
		}
		else if (*global.rbegin() > candidate[root].top()) {
			global.erase(--global.end());
			global.insert(candidate[root].top());
			candidate[root].pop();
		}
		else break;
	}
	
//	cout << "SZ " << candidate[root].size() << "\n";
//	cout << "Test " << p.first << " at " << p.second << "\n";
//	for (int x : global) cout << x << " "; cout << "\n";
	
	if (global.size() < Q) return INF;
	return *global.rbegin() - *global.begin();
}
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> K >> Q;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		b[i] = {a[i], i};
	}
	
	int ans = INF;
	sort(b, b + N);
	init();
	for (int i = N - 1; i >= 0; i--) {
		ans = min(ans, test(b[i]));
	}
	
	cout << ans << '\n';
	/**** Note MAXN ****/
}

Measured memory_bytes: 4608
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n = 100;
	int k;
	cin >> k;
	for(int i=1;i<=1e5;i++){
		if(n >= k){
			cout << i - 1 ;
			break;
		}
		n = n + n/100;
	}
}
//.........

Measured memory_bytes: 3648
a, b, c, d = map(int, input().split())

ab_distance = max(a, b) - min(a, b)
bc_distance = max(b, c) - min(b, c)
ac_distance = max(a, c) - min(a, c)

if ab_distance <= d and bc_distance <= d:
  print('Yes')
elif ac_distance <= d:
  print('Yes')
else:
  print('No')


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

using namespace std;

int main() {
    // 考え方メモ
    // 終了判定に気をつけよう！！

    int N;
    string S;
    cin >> N >> S;

    int count = 0;
    for (int i = 0; i <= N - 3; i++) {
        if (S.substr(i, 3) == "ABC") {
            count++;
        }
    }

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

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		if(x==7||x==5||x==3) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 22868
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define P pair<int, int>
#define chmin(x, y) x = min(x, y)

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  rep(i, k) cin >> l[i] >> r[i];
  vector<mint> dp(n + 1), dpsum(n + 1);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; i++)
  {
    rep(j, k)
    {
      int li = i - r[j];
      int ri = i - l[j];
      if (ri <= 0)
        continue;
      li = max(li, 1);
      dp[i] += dpsum[ri] - dpsum[li - 1];
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }

  cout << dp[n] << endl;
}


Measured memory_bytes: 6408
fun main(args: Array<String>) {
    abc153e()
}

fun abc153e() {
    val (h, n) = readLine()!!.split(' ').map { it.toInt() }
    val magics = (1..n)
        .map { readLine()!!.split(' ').map { it.toInt() }.let { Magic(it[0], it[1]) } }

    val dp = LongArray(h + 1) { Int.MAX_VALUE.toLong() }
    dp[0] = 0

    for (i in 0 until n) {
        val (damage, mp) = magics[i]
        for (damageSum in 0 until h) {
            val min = Math.min(damageSum + damage, h)
            dp[min] = Math.min(dp[min], dp[damageSum] + mp)
        }
    }

    val answer = dp[h]

    println(answer)
}

private data class Magic(val damage: Int, val mp: Int)


Measured memory_bytes: 40596
/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

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

using namespace std;

int n, m;

unordered_map <int, vector <int > > g[N];

unordered_map <int, int> d[N];

int c[N];

int main() {
	#ifdef IOI2018
		freopen ("in.txt", "r", stdin);
    freopen ("E.out", "w", stdout);
	#endif
	Kazakhstan
	cin >> n >> m;
	rep(i, 1, m) {
		int a, b, c;
		cin >> a >> b >> c;
		g[a][c].pb(b);
    g[b][c].pb(a);
	}
	d[1][0] = 0;
	deque < pair <int, pair <int, int> > > st;
	st.pb({0, {1, 0}});
  vector <bool> was(n + 1, 0);
	while (sz(st)) {
		int dist = st.front().f;
		int v = st.front().s.f, last = st.front().s.s;
		st.pop_front();
    
    if (!was[v]) {
      for (auto it : g[v]) {
        int C = it.f;
        for (auto to : it.s) {
          if (!d[to].count(C) || d[to][C] > dist + 1) {
            d[to][C] = dist + 1;
            st.pb({d[to][C], {to, C}});
          }
        }
      }
      was[v] = 1;
    }
    if (sz(g[v][last])) {
      int C = last;
      for (auto to : g[v][last]) {
        if (!d[to].count(last) || d[to][last] > dist) {
          d[to][C] = dist;
          st.push_front({d[to][C], {to, C}});
        }
      }
      g[v][last].clear();
      g[v].erase(last);
    }
  }
  int ans = inf;
  for (auto it : d[n]) ans = min(ans, it.s);
  cout << (ans == inf ? -1 : ans);
	ioi
}


Measured memory_bytes: 104576
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

const ll MOD = 1e9+7;

ll pow(ll x, ll exp) {
  if(exp == 0) {
    return 1;
  }
  if(exp % 2 == 1) {
    return pow(x, exp - 1) * x % MOD;
  } else {
    ll y = pow(x, exp / 2);
    return y * y % MOD;
  }
}

struct dat {
  VL fact;
  VL inv_fact;
  dat(int n): fact(n), inv_fact(n) {
    fact[0] = 1;
    inv_fact[0] = 1;
    REP(i,1,n) {
      fact[i] = fact[i-1] * i % MOD;
      inv_fact[i] = pow(fact[i], MOD - 2);
    }
  }
  ll comb(ll x, ll y) {
    if(y > x) return 0;
    return fact[x] * inv_fact[y] % MOD * inv_fact[x-y] % MOD;
  }
};

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VI as(n+1);
  VI freq(n+1, 0);
  FOR(a,as) {
    cin >> a;
    freq[a]++;
  }
  VI lr;
  REP(i,0,n+1) {
    if(freq[as[i]] == 2) {
      lr.push_back(i);
    }
  }
  int l = lr[0];
  int r = lr[1];
  dat d(n+2);
  REP(k,1,n+2) {
    cout << ((d.comb(n+1, k) - d.comb(n-r+l, k-1)) % MOD + MOD) % MOD << endl;
  }

  return 0;
}


Measured memory_bytes: 3584
#include <cmath>
#include <iostream>
#include <vector>
#include <tuple>
#include <limits>

using lli=long long;
int main(){
  int N,M,P;
  std::cin >> N >> M >> P;

  std::vector<std::tuple<int,int,int>> edge_arr;
  for(int i = 0; i < M; i++){
    int a,b,c;
    std::cin >> a >> b >> c;
    a--; b--; c-=P; c *= -1;
    edge_arr.push_back(std::make_tuple(a,b,c));
  }

  std::vector<lli> length_arr(N, std::numeric_limits<lli>::max());
  length_arr[0] = 0;
  for(int i = 0; i < N-1; i++){
    for(auto&& e: edge_arr){
      lli a,b,c;
      std::tie(a,b,c) = e;
      if(length_arr[a] == std::numeric_limits<lli>::max()) continue;
      length_arr[b] = std::min(length_arr[b], length_arr[a]+c);
    }
  }

  std::vector<int> loop_arr(N, false);
  for(int i = 0; i < N; i++){
    for(auto&& e: edge_arr){
      lli a,b,c;
      std::tie(a,b,c) = e;
      if(length_arr[a] == std::numeric_limits<lli>::max()) continue;
      if(loop_arr[a]) loop_arr[b] = true;
      if(length_arr[b] > length_arr[a]+c) loop_arr[b] = true;
    }
  }

  if(loop_arr[N-1]) std::cout << -1 << std::endl;
  else std::cout << std::max(static_cast<lli>(0), -length_arr[N-1]) << std::endl;

  return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;cin>>n;
  ll ans=1;
  int mod=1e9+7;
  reps(i,n){
    ans*=i;
    ans%=mod;
  }
  cout(ans);
  return 0;
}

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

int list[100][100] = {0};

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      list[i][a]++;
    }
  }

  int ans = 0;
  for (int i = 1; i <= m; i++) {
    int flag = 1;
    for (int j = 0; j < n; j++) {
      if (list[j][i] == 0) {
        flag = 0;
      }
    }
    if (flag) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int a[n];
    map<int, int> mp;
    rep(i, 0, n) {
        cin >> a[i];
        a[i]--;
        mp[a[i]]++;
    }
    ll sum = 0;
    for (auto i : mp) {
        ll x = i.second;
        sum += x * (x - 1) / 2;
    }
    rep(i, 0, n) {
        ll ans = sum - mp[a[i]] * (mp[a[i]] - 1) / 2 + max(0, (mp[a[i]] - 1) * (mp[a[i]] - 2) / 2);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 8320
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int ans = 0;
            int t = 1;
            while (true) {
                if (t >= b) {
                    break;
                } else {
                    t += a - 1;
                    ans++;
                }
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 23252
N = int(input())
d = dict({'AC':0, 'WA':0, 'TLE':0, 'RE':0})
for i in range(N):
    S = input()
    d[S] += 1
print('AC x {}'.format(d['AC']))
print('WA x {}'.format(d['WA']))
print('TLE x {}'.format(d['TLE']))
print('RE x {}'.format(d['RE']))

Measured memory_bytes: 9200