akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)
struct Point {
  ll x;
  ll y;
};
bool operator<(const Point& l, const Point& r) {
  if (l.x == r.x) {
    return l.y < r.y;
  }
  return l.x < r.x;
}

constexpr inline double calcDist(Point a, Point b) {
  return sqrt(((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y)));
}

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

  vector<Point> Towns(N);
  for (ll i = 0; i < N; i++) {
    ll x, y;
    cin >> x >> y;
    Towns[i] = {x, y};
  }
  sort(begin(Towns), end(Towns));

  vector<double> dists;
  do {
    double sum = 0.0;
    for (ll i = 0; i < N - 1; i++) {
      sum += calcDist(Towns[i], Towns[i + 1]);
    }
    dists.push_back(sum);
  } while (next_permutation(begin(Towns), end(Towns)));  // 次の順列を生成

  double ave = accumulate(cbegin(dists), cend(dists), 0.0) / (double)dists.size();
  printf("%.8lf\n", ave);
  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

    long long N,A,B;
    cin >> N >> A >> B;
    long long ans=0;
    long long x=abs(A-B);
    long long y=min(min(min(A-1,B-1),N-A),N-B);
    if(x%2==0) {
        ans=x/2;
    }else{
        x++;
        ans=y+x/2;
    }
    cout << ans << endl;
    


}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int M;
	cin >> M;
	string C;
	cin >> C;
	int N = C.size();
	reverse(C.begin(), C.end());
	if (M == 0 && N == 1) {
		cout << 0 << endl;
		return 0;
	}
	int sum[10];
	for (int i = 0; i < 10; i++) {
		sum[i] = 0;
	}
	int a = 1;
	for (int i = 0; i < N; i++) {
		sum[C[i] - '0'] += a;
		if (sum[C[i] - '0'] >= MOD) {
			sum[C[i] - '0'] -= MOD;
		}

		a = (a * 10) % MOD;
	}
	vector<int> X(10);
	for (int i = 0; i < 10; i++) {
		X[i] = i;
	}
	string res;
	do {
		int a = 0;
		if (X[C.back() - '0'] == 0)continue;
		for (int i = 0; i < 10; i++) {
			a = (a + sum[i] * X[i]) % MOD;
		}
		if (a == M) {
			res = C;
			for (int i = 0; i < N; i++) {
				res[i] = X[C[i] - '0'] + '0';
			}
		}

	} while (next_permutation(X.begin(), X.end()));

	reverse(res.begin(), res.end());
	if (res.size() == 0)res = "-1";

	cout << res << endl;
}


Measured memory_bytes: 3348
<?php
//error_reporting(0);
//$S = trim(fgets(STDIN));
list($A,$B,$C) =  explode(" ",trim(fgets(STDIN)));
//$B =  explode(" ",trim(fgets(STDIN)));

//max = $A
printf("%d\n",max(0,$C-max(0,($A-$B))));


Measured memory_bytes: 4728
#include <iostream>
using namespace std;
static const int N_MAX = 100;

int main() {
    int n, arr[N_MAX];
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }

    for (int i = 1; i < n; i++) {
        for (int j = 0; j < n-1; j++) {
            cout << arr[j] << " ";
        }
        cout << arr[n - 1] << endl;

        int v = arr[i];
        int j = i - 1;
        while (j >= 0 && arr[j] > v) {
            arr[j + 1] = arr[j];
            j--;
        }
        arr[j + 1] = v;
    }

    for (int j = 0; j < n-1; j++) {
        cout << arr[j] << " ";
    }
    cout << arr[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 3088
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<long long> d;
	d.push_back(0);
	int cur = 1;
	while (true) {
		long long x = 1LL * cur * cur * cur * cur * cur;
		if (x - d.back() <= N) {
			d.push_back(x);
		}
		else {
			break;
		}
		++cur;
	}
	vector<long long> nd;
	for (int i = int(d.size()) - 1; i >= 1; --i) {
		nd.push_back(-d[i]);
	}
	nd.insert(nd.end(), d.begin(), d.end());
	bool found = false;
	for (int i = 0; i < nd.size(); ++i) {
		for (int j = i + 1; j < nd.size(); ++j) {
			if (nd[j] - nd[i] == N && !found) {
				cout << j - int(d.size()) + 1 << ' ' << i - int(d.size()) + 1 << endl;
				found = true;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define pie 3.141592653589793
#define si(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
#define sl(a) scanf("%lld",&a)
#define pi(a) printf("%d",a)
#define pl(a) printf("%lld",a)
#define ps(a) printf("%s",a)
#define ll long long
using namespace std;
int main()
{
  ll a,b,c;
  cin >> a >> b >> c;
  a-=2*c;
  ll ans = (a+c)/(b+c);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
l = [['the', 'uif', 'vjg', 'wkh', 'xli', 'ymj', 'znk', 'aol', 'bpm', 'cqn', 'dro', 'esp', 'ftq', 'gur', 'hvs', 'iwt', 'jxu', 'kyv', 'lzw', 'max', 'nby', 'ocz', 'pda', 'qeb', 'rfc', 'sgd'], \
['this', 'uijt', 'vjku', 'wklv', 'xlmw', 'ymnx', 'znoy', 'aopz', 'bpqa', 'cqrb', 'drsc', 'estd', 'ftue', 'guvf', 'hvwg', 'iwxh', 'jxyi', 'kyzj', 'lzak', 'mabl', 'nbcm', 'ocdn', 'pdeo', 'qefp', 'rfgq', 'sghr'], \
['that', 'uibu', 'vjcv', 'wkdw', 'xlex', 'ymfy', 'zngz', 'aoha', 'bpib', 'cqjc', 'drkd', 'esle', 'ftmf', 'gung', 'hvoh', 'iwpi', 'jxqj', 'kyrk', 'lzsl', 'matm', 'nbun', 'ocvo', 'pdwp', 'qexq', 'rfyr', 'sgzs']]

while 1:
    try:
        s = raw_input()
        for w in l:
            for i in xrange(25):
                o = w[i]
                if s.find(w[i]) != -1:
                    r = ''
                    for c in s:
                        if c == ' ' or c == '.' : r+= c
                        else: r += chr((ord(c) - ord('a') - i) % 26 + ord('a'))
                    print r
                    break
            else:
                continue
            break
    except:
        break

Measured memory_bytes: 6348
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = zeros(Int,n)
	for i in 1:n
		a[i] = readline() |> parseInt
	end
	if a[1] != 0
		println(-1)
	else
		d = Dict{Int,Int}()
		md = n
		f = 0
		for i in n:-1:2
			if i-a[i]>md||i-a[i]<1
				f = 1
				break
			elseif i-a[i]<md
				md = i-a[i]
				d[i-a[i]] = a[i]
			end
		end
		if f == 1
			println(-1)
		else
			s = 0
			for i in keys(d)
				s += d[i]
			end
			println(s)
		end
	end
end

main()

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

int main() {
    int N;
    cin>>N;
    int count=0;
    for (int i = 0; i < N; i++){
        int a,b; cin>>a>>b;
        if(a==b)count++;
        else count=0;
        if(count==3){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
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 (b<a) { a=b; return 1; } return 0; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) do{}while(0)
#endif





/*
	DP?
	
	dp[i][j] : [i,j)の範囲を全て食べたとき、その右側と左側に加算する数。1つの数ではなく、vector<pair<ll,ll>>で
	
	
	
*/


vector<pll> tmp;
vector<pll> dp[18][18];
vector<ll> a;
ll n;

void f( int i, int j ){
	if ( i+1 == j ){
		dp[i][j].push_back({a[i],a[i]});
	}
	else {
		
		tmp.clear();
		for ( int k = i; k < j; k++ ){
			// [i,k)と[k+1,j)を食べて、kを食べる
			for ( auto l : dp[i][k] ){
				for ( auto r : dp[k+1][j] ){
					tmp.push_back({l.first+l.second+a[k]+r.first, l.second+a[k]+r.first+r.second});
				}
			}
		}
		sort(tmp.begin(),tmp.end(),[&](const pll& l, const pll &r){
			return l.first < r.first || (l.first == r.first && l.second < r.second);
		});
		
		for ( int k = 0; k < SZ(tmp); k++ ){
			if ( k == 0 || dp[i][j].back().second > tmp[k].second ){
				dp[i][j].push_back(tmp[k]);
				//eprintf( "%d %d : + %lld %lld\n", i, j, tmp[k].first, tmp[k].second );
			}
			else {
				//eprintf( "%d %d :   %lld %lld\n", i, j, tmp[k].first, tmp[k].second );
			}
		}
	}
}


int main(){
	cin >> n;
	a.resize(n);
	rep(i,n)
		cin >> a[i];
	
	rep(i,18)
		dp[i][i].push_back({0,0});
	
	for ( int d = 1; d < n; d++ ){
		for ( int i = 1; i+d < n; i++ ){
			f( i, i+d );
		}
	}
	
	//rep(i,n){
	//	rep(j,n){
	//		cout << dp[i][j].size() << " ";
	//	}
	//	cout << endl;
	//}
	
	ll result = LLONG_MAX;
	for ( auto it : dp[1][n-1] ){
		chmin(result, it.first+it.second);
	}
	cout << a[0]+result+a[n-1] << endl;
	
	return 0;
}




Measured memory_bytes: 3816
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

const ll P = 998244353;
int main(){
	int N;
	cin >> N;
	vector<int> D(N);
	for(int i=0; i<N; i++) cin >> D[i];

	vector<int> cnt(N);
	int mx = 0;
	for(int i=0; i<N; i++){
		cnt[D[i]]++;
		mx = max(mx, D[i]);
	}

	if(D[0]!=0){
		cout << 0 << endl;
		return 0;
	}
	if(cnt[0]!=1){
		cout << 0 << endl;
		return 0;
	}
	bool ok = true;
	for(int i=0; i<=mx; i++){
		if(cnt[i]==0){
			cout << 0 << endl;
			return 0;
		}
	}

	ll ans = 1;
	for(int i=1; i<N; i++){
		for(int k=0; k<cnt[i]; k++){
			ans *= cnt[i-1];
			ans %= P;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int n, m, d;
    char area[101][101];
    int ans = 0;
    int cnt = 0;

    cin >> n >> m >> d;

    for (int i = 0; i < n; i++) {
        cin >> area[i];
    }

    if (n >= d) {
        for (int j = 0; j <= n-d; j++) { 
            for (int i = 0; i < m; i++) {
                for (int k = j; k < d+j; k++) {
                    if (area[k][i] == '.') {
                        cnt++;
                    }
                }
                if (cnt == d) {
                    ans++;
                }
                cnt = 0;
            }
        }
    }

    if (m >= d) {
        for (int j = 0; j <= m-d; j++) {
            for (int i = 0; i < n; i++) {
                for (int k = j; k < d+j; k++) {
                    if (area[i][k] == '.') {
                        cnt++;
                    }
                }
                if (cnt == d) {
                    ans++;
                }
                cnt = 0;
            }
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3092
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	if(n==22)printf("Christmas Eve Eve Eve");
	if(n==23)printf("Christmas Eve Eve");
		if(n==24)printf("Christmas Eve");
			if(n==25)printf("Christmas");
	return 0;
 } 

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

int main() {
	int N;
	cin >> N;
	int64_t answer = 0;
	vector<int64_t>height(N);
	for(int i=0;i<N;i++){
		cin >> height.at(i);
	}
	
	for(int i=1;i<N;i++){
		if(height.at(i-1)>height.at(i)){
			int64_t c = height.at(i-1)-height.at(i);
			answer += c;
			height.at(i)=height.at(i-1);
		}
	}
	cout << answer << endl;


}

Measured memory_bytes: 4788
n = int(input())
A = list(map(int,input().split()))

ans_li = []

sum_val = sum(A) // 2
count = 0
for i in range((n - 1) // 2):
    count += A[2 * i + 1]

ans_li.append(2 * (sum_val - count))

for j in range(n-1):
    ans_li.append(2 * A[j] - ans_li[j])

print(*ans_li)

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

int main() {
    int R;
	cin >> R;
	string s;
	if (R < 1200) {
	    s = "ABC";
	} else if (R < 2800) {
	    s = "ARC";
	} else {
	    s = "AGC";
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long N = sc.nextLong()-1;
		long gSize=26;
		int length=1;
		while(true) {
			if(N<gSize) {
				String ans = "";
				for(int i=0; i<length; i++) {
					ans = String.valueOf((char)('a'+(N%26)))+ans;
					N/=26;
				}
				System.out.println(ans);
				break;
			} else {
				N-=gSize;
				gSize*=26;
				length++;
			}
		}
		sc.close();
	}
}


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

using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 998244353;

int parent[N];

int gcd(int a, int b) { 
    if (a == 0) 
        return b;  
    return gcd(b%a, a);  
} 
   
int lcm(int a, int b) {  
    return (a*b)/gcd(a,b);  
} 

ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}

int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}

void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}

int main()
{
    IOS
    int n, s;
    cin >> n >> s;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    vector<vector<ll>> dp(n+1, vector<ll>(s+1, 0));
    dp[0][0] = 1;
    for(int i=0;i<n;i++) {
        for(int j=0;j<=s;j++) {
            dp[i+1][j] += (dp[i][j] * 2) % MOD;
            if(j - a[i] >= 0) dp[i+1][j] += dp[i][j-a[i]];
            dp[i+1][j] %= MOD;
        }
    }
    cout << dp[n][s] << endl;
    return 0; 
}



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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + (ch ^ '0');
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = (int) 2e5, MAX_LOG = 30;

// Template-Libs

// END

int n;

int a[MAXN + 5];

inline void input()
{
	n = read<int>();
	for(int i = 1; i <= n; ++i) a[i] = read<int>();
}

inline void solve()
{
	sort(a + 1, a + n + 1);
	int ans = 0;
	for(int p = MAX_LOG; p >= 0; --p)
	{
		int d = 1 << p;

		static int vis[MAXN + 5], b[MAXN + 5];
		for(int j = 1; j <= n; ++j) vis[j] = 0;

		for(int i = 1, j = n; i < j; --j)
		{
			while(i + 1 < j && a[i] + a[j] < d) ++i;
			if(a[i] + a[j] == d) vis[i] = vis[j] = 1, ++ans, ++i;
		}
		int m = 0;
		for(int i = 1; i <= n; ++i) if(!vis[i]) b[++m] = a[i];
		for(int i = 1; i <= m; ++i) a[i] = b[i];
		n = m;
	}
	printf("%d\n", ans);
}

int main()
{
	input();
	solve();

	return 0;
}



Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 1025, M = 1025;
int n, m, ans[N][M];
void Solve(int L, int R, int U, int D) {
	if (L > R || U > D)
		return ;
	if (L == R && U == D) {
		ans[L][U] = 1;
		return ;
	}
	int cMid = (L + R) >> 1, rMid = (U + D) >> 1;
	ans[cMid][rMid] = 1;
	Solve(L, cMid - 1, U, rMid - 1);
	Solve(cMid + 1, R, U, rMid - 1);
	Solve(L, cMid - 1, rMid + 1, D);
	Solve(cMid + 1, R, rMid + 1, D);
}
int main() {
	scanf("%d%d", &n, &m);
	int mx = max(n, m);
	Solve(1, (1 << mx) - 1, 1, (1 << mx) - 1);
	for (int i = 1; i < (1 << n); ++i) {
		for (int j = 1; j < (1 << m); ++j)
			printf("%d", ans[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
ll modexpo(ll a,ll b){
    ll res = 1;
    a%=mod;
    while(b){
        if(b&1)
            res = (res*a)%mod;
        b>>=1;
        a = (a * a)%mod;
    }
    return res%mod;
}

void solve(){
    ll n;
    cin>>n;
    ll a[n];
    // ll hash[]
    map<ll,ll> mp;
    vector<ll> arr;
    
    ll sum = 0;
    for(int i =0;i<n;i++){
        cin>>a[i];
        // if(mp[a[i]]==0){
        //     arr.push_back(a[i]);
        // }
        // mp[a[i]]++;
        sum=(sum + a[i])%mod;
    }
    // n = arr.size();
    ll ans = 0;
    for(int i =0;i<n;i++){
        sum = (sum - a[i] + mod)%mod;
        ll p  = ((sum)%mod*(a[i])%mod)%mod;
        ans = (ans + p)%mod;
    }
    cout<<ans<<'\n';
}
int main(){
    IOS
    int tt;
    tt = 1;
    // cin>>tt;
    while(tt--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 5224
#include <bits/stdc++.h>
#define FI freopen ("inp.txt", "r", stdin)
#define FO freopen ("out.txt", "w", stdout)
using namespace std;

const int INF = 1e9 + 5;

int main() {
    //FI;

    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> h(n);
    for (int& x : h) scanf("%d", &x);

    vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j <= i + k; ++j)
            if (j < n)
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
    }
    printf("%d\n", dp[n-1]);

    return 0;
}


Measured memory_bytes: 1024
fun main(args: Array<String>) {

    val bb = IntArray(100) // 要素数が100の配列を定義（要素は0 で初期化） intArrayOf(1,2,3) は IntArray を 1,2,3で初期化する
    var n = readLine()!!.toInt()

    for (i in 0..(n-1)) {
        var input = readLine()!!.toInt() - 1
        bb[input] += 1
    }
    var cnt = bb.count { it!=0 }
    print(cnt)
}

Measured memory_bytes: 31388
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (b);)
#define trav(x,v) for(auto &x : (v))
#define all(v) (v).begin(),(v).end()
#define sz(v) (int)(v).size()
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

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

int main(){
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);

	int n;
	cin >> n;

	vector<vi> cost(n, vi(n));
	rep(x,0,n) rep(y,0,n)
		cost[x][y] = 1 + min( min(x, n-1-x),
				  min(y, n-1-y) );

	vector<vector<bool>> cinema(n, vector<bool>(n, true));

	function<void(int,int,int)> upd = [&](int x, int y, int d){
		cost[x][y] = d;
		rep(t,0,4){
			int x1 = x + dx[t], y1 = y + dy[t];
			if(max(x1, y1) < n && min(x1,y1) >= 0){
				int cnd = d + cinema[x1][y1];
				if(cost[x1][y1] > cnd) upd(x1, y1, cnd);
			}
		}
	};

	int ans = 0;

	rep(_,0,n*n){
		int p;
		cin >> p;
		--p;
		int x = p / n, y = p % n;
		ans += cost[x][y]-1;
		upd(x, y, cost[x][y] - 1);
		cinema[x][y] = false;
	}

	cout << ans << endl;
}


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

using namespace std;


long long cost(long long* A, const long long& index, const long long& area){
  if (area==0 || area==4) {
    return A[index];
  } else if (area==1 || area==3) {
    if (A[index]==0) {
      return 2;
    } else if(A[index]%2==0) {
      return 0;
    } else {
      return 1;
    }
  } else {
    if (A[index]%2==0){
      return 1;
    } else {
      return 0;
    }
  }
}

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

  long long A[n];
  for(long long i=0;i<n;i++){
    cin >> A[i];
  }

  vector< vector<long long> > dp;
  dp.resize(n);
  for(long long i=0; i<n; i++){
    dp[i].resize(5);
  }

  for(int j=0;j<5;j++){
    dp[0][j] = cost(A,0,j);
  }

  for(long long i=1;i<n;i++){
    dp[i][0] = dp[i-1][0]+cost(A,i,0);
    for(int j=1;j<5;j++){
      long long mindp = *std::min_element(dp[i-1].begin(), dp[i-1].begin()+j+1);
      dp[i][j] = min(mindp+cost(A,i,j), dp[i][j-1]);
    }
  }

  long long ans = *std::min_element(dp[n-1].begin(), dp[n-1].end());
  cout << ans << endl;

  return 0;
}

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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   double N, K, ans = 0.0;
   cin >> N >> K;

   if (K <= N) {
     for (int i = 1; i <= K - 1; i++) {
       ans += pow(0.5, ceil(log2(K) - log2(i)));
     }
     ans += (N - K + 1.0);
     ans /= N;
   }

   else {
      for (int i = 1; i <= N; i++) {
        ans += pow(0.5, ceil(log2(K) - log2(i)));
      }
      ans /= N;
   }

   cout << fixed << setprecision(17) << ans << endl;
 }


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int to2; int cost; };
string qt, qd;
signed main() {
	int n, q; cin >> n >> q;
	string X; cin >> X;
	string s = "%";
	s += X; s.push_back('%');
	rep(i, q) {
		char t, d; cin >> t >> d;
		qt.push_back(t);
		qd.push_back(d);
	}
	int lb = 0, ub = n+1;
	while (ub - lb > 1) {
		int mi = (lb + ub) / 2;
		char nlt = s[mi];
		int pos = mi;
		rep(i, q) {
			if (pos == 0)break;
			if (nlt == qt[i]) {
				if (qd[i] == 'L') {
					pos--;
					nlt = s[pos];
				}
				else if(qd[i]=='R'){
					pos++;
					nlt = s[pos];
				}
			}
		}
		if (pos == 0)lb = mi;
		else ub = mi;
	}
	int lb2 = 0, ub2 = n + 1;
	
	while (ub2 - lb2 > 1) {
		int mi = (lb2 + ub2) / 2;
		char nlt = s[mi];
		int pos = mi;
		rep(i, q) {
			if (pos == n+1)break;
			if (nlt == qt[i]) {
				if (qd[i] == 'L') {
					pos--;
					nlt = s[pos];
				}
				else if (qd[i] == 'R') {
					pos++;
					nlt = s[pos];
				}
			}
		}
		if (pos == n+1)ub2 = mi;
		else lb2 = mi;
	}
	cout << ub2-lb-1<< endl;
}

Measured memory_bytes: 1196
#include<iostream>
#include<vector>
#include<climits>
using namespace std;

int find(int a,vector<int>&parent){
    if(parent[a]<=-1){
        return a;
    }
    else
    {
        int k=find(parent[a],parent);
        parent[a]=k;
        return k;
    }
}


void union1(int a,int b,vector<int>&parent){

    int l=find(a,parent);
    int r=find(b,parent);
    if(l==r){
        return;
    }
    if(parent[l]<parent[r]){
        parent[l]+=parent[r];
        parent[r]=l;
    }
    else
    {
        parent[r]+=parent[l];
        parent[l]=r;
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    vector<int>parent(n,-1);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        a--,b--;
        union1(a,b,parent);
    }
    int result=INT_MAX;
    for(int i=0;i<parent.size();i++)
    {
        if(parent[i]<result){
            result=parent[i];
        }
    }
    cout<<result*-1;
}

Measured memory_bytes: 4008
#include<stdio.h>
#define N 101
#define WHITE 0
#define BLACK 1
#define GRAY 2

typedef struct
{
  int  d,f,k,color;
}Depth;

int  B[N][N],n,cnt=0;
Depth D[N];

void DFS(int);
void Print();


int main()
{
  int i,j,u,v;
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    for(j=0;j<n;j++)B[i][j] = 0;
  }
  for(i=0;i<n;i++)
  {
    D[i].d = 0;
    D[i].color = WHITE;
    scanf("%d%d",&u,&D[i].k);
    u--;
    for(j=0;j<D[i].k;j++)
    {
      scanf("%d",&v);
      v--;
      B[u][v] = 1;
    }
  }

  Print();

  return 0;
}

void DFS(int u)
{
  int i;
  D[u].color = BLACK;
  D[u].d = ++cnt;
  for(i=0;i<n;i++)
  {
    if(B[u][i] == 0) continue;
    if(D[i].color == WHITE)DFS(i);
  }
  D[u].color = GRAY;
  D[u].f = ++cnt;
}

void Print()
{
  int i;
  for(i=0;i<n;i++)if(D[i].color == WHITE)DFS(i);
  for(i=0;i<n;i++)
  {
    printf("%d %d %d\n",i+1,D[i].d,D[i].f);
  }
}



Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;

inline int read()
{
	int X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}

int n;
double p[N];
double dp[4000][4000];
int main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	n=read();
	for(int i=1;i<=n;++i){
		scanf("%lf",&p[i]);
	}

	dp[1][0]=1-p[1];
	dp[1][1]=p[1];

	for(int i=2;i<=n;++i){
		for(int j=0;j<=i;++j){
			if(j==0){
				dp[i][j]=dp[i-1][j]*(1-p[i]);
			}
			else{
				dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]);
			}
		}
	}
	double res=0.0000000000;
	for(int i=(n/2)+1;i<=n;++i){
		res+=dp[n][i];
	}
	printf("%.10lf",res);

    return 0;
}

Measured memory_bytes: 50744
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 2019;
const ll inf = 1e15;

ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main(){FIN

    map<ll,ll> r;
    string s;cin>>s;

    r[0]++;
    ll n = s.size();
    ll now=0;
    REP(i,n){
        now += (s[n-1-i]-'0') * power(10, i);
        now %= 2019;
        r[now]++;
    }
    ll ans=0;
    for(auto p:r){
        ans += p.second * (p.second-1) /2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define myfill(a, val, type) fill((type *)a, (type *)a+sizeof(a)/sizeof(type), val)

int main() {
	long long n, k;
	cin >> n >> k;
	vector<pair<int,int>> sushi(n);
	for (int i = 0; i < n; i++) {
		cin >> sushi[i].second >> sushi[i].first;
		sushi[i].second--;
	}
	sort(sushi.begin(), sushi.end(), greater<pair<int,int>>());
	int neta_t[n]; myfill(neta_t, 0, int);
	long long oishi = 0, neta = 0;
	for (int i = 0; i < k; i++) {
		int d = sushi[i].first, t = sushi[i].second;
		if (neta_t[t] == 0) neta++;
		neta_t[t]++;
		oishi += d;
	}
	long long ans = oishi + neta * neta;
	int a = k-1, b = k;
	auto next_sushi = [&]() {
		bool ok1 = false, ok2 = false;
		while (a >= 0) {
			int d = sushi[a].first, t = sushi[a].second;
			a--;
			if (neta_t[t] == 1) continue;
			neta_t[t]--;
			oishi -= d;
			ok1 = true;
			break;
		}
		while (b < n) {
			int d = sushi[b].first, t = sushi[b].second;
			b++;
			if (neta_t[t] != 0) continue;
			neta_t[t]++;
			neta++;
			oishi += d;
			ok2 = true;
			break;
		}
		return ok1 && ok2;
	};
	while (next_sushi()) {
		long long now = oishi + neta * neta;
		ans = max(ans, now);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4588
s = list([input() for _ in range(3)])
alphaList = ["a", "b", "c"]
ALPHAList = ["A", "B", "C"]
swi = "a"
while len(s[0]) * len(s[1]) * len(s[2]) >= 0:
    # 選んだカードが一枚もなかったら終了
    if len(s[alphaList.index(swi)]) == 0:
        print(ALPHAList[alphaList.index(swi)])
        break

    # 次のカード
    nextSwi = s[alphaList.index(swi)][0]

    # 不要なカードを消す
    sLen = len(s[alphaList.index(swi)])
    s[alphaList.index(swi)] = s[alphaList.index(swi)][1:sLen]

    swi = nextSwi


Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int a;
char s[11];
int main(void)
{
  cin >> a >> s;
  if (a >= 3200) {
    cout << s << endl;
  }
  else {
    cout << "red" << endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include <vector>
#include <functional>
using namespace std;

template <typename T, typename E>
class lazy_segtree {
private:
    using Op = function<T(T, T)>;
    using Compose = function<E(E, E)>;
    using Act = function<T(T, E)>;
    using Power = function<E(E, int)>;

    size_t N;
    vector<T> data;
    vector<E> lazy;
    const T idT;
    const E idE;
    const Op op;
    const Compose compose;
    const Act act;
    const Power power;

    void eval(size_t k, size_t len) {
        if(lazy[k] == idE) return;
        if(2 * k + 1 < 2 * N) {
            lazy[2 * k] = compose(lazy[2 * k], lazy[k]);
            lazy[2 * k + 1] = compose(lazy[2 * k + 1], lazy[k]);
        }
        data[k] = act(data[k], power(lazy[k], len));
        lazy[k] = idE;
    }

    void update(size_t a, size_t b, size_t k, size_t l, size_t r, E x) {
        eval(k, r - l);
        if(r <= a || b <= l) return;
        if(a <= l && r <= b) {
            lazy[k] = compose(lazy[k], x);
            eval(k, r - l);
            return;
        }
        update(a, b, 2 * k, l, (l + r) / 2, x);
        update(a, b, 2 * k + 1, (l + r) / 2, r, x);
        data[k] = op(data[2 * k], data[2 * k + 1]);
    }

    T get(size_t a, size_t b, size_t k, size_t l, size_t r) {
        eval(k, r - l);

        if(r <= a || b <= l) return idT;
        if(a <= l && r <= b) return data[k];
        
        T vl = get(a, b, 2 * k, l, (l + r) / 2);
        T vr = get(a, b, 2 * k + 1, (l + r) / 2, r);
        if(2 * k + 1 < 2 * N) data[k] = op(data[2 * k], data[2 * k + 1]);
        return op(vl, vr);
    }

public:
    lazy_segtree(size_t n, T idT, E idE,
    const Op op, const Compose compose,
    const Act act, const Power power = [](E a, int){ return a; })
    : idT(idT), idE(idE), op(op), compose(compose), act(act), power(power) {
        for(N = 1; N < n; N <<= 1);
        data = vector<T>(2 * N, idT);
        lazy = vector<E>(2 * N, idE);
    }
    
    lazy_segtree(const vector<T> &init, T idT, E idE,
    const Op op, const Compose compose,
    const Act act, const Power power = [](E a, int){ return a; })
    : idT(idT), idE(idE), op(op), compose(compose), act(act), power(power) {
        for(N = 1; N < init.size(); N <<= 1);
        data = vector<T>(2 * N, idT);
        lazy = vector<E>(2 * N, idE);
        for(int i = 0; i < init.size(); ++i) data[i + N] = init[i];
        for(int i = N - 1; i >= 0; --i) data[i] = op(data[2 * i], data[2 * i + 1]);
    }

    void update(size_t left, size_t right, E x) {
        update(left, right, 1, 0, N, x);
    }

    T get(size_t left, size_t right) {
        return get(left, right, 1, 0, N);
    }

    T operator[](int k) {
        return get(k, k + 1);
    }
};


#include <iostream>

int main() {
    int n, q;
    cin >> n >> q;
    lazy_segtree<int, int> st(n, 0, -1001,
    plus<long long>(), [](int, int b){ return b; },
    [](int, int b){ return b; }, multiplies<int>());

    while(q--) {
        int c, s, t; cin >> c >> s >> t;
        if(c == 0) {
            long long x; cin >> x;
            st.update(s, t + 1, x);
        } else {
            cout << st.get(s, t + 1) << endl;
        }
    }
}


Measured memory_bytes: 4940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;


int main() {
	ll n, k; cin >> n >> k;
	ll ans = 0;
	if (k == 0) {
		cout << n*n << endl;
		return 0;
	}
	for (ll b = k + 1; b <= n; b++) {
		ans += (b - k)*(n / b) + (n%b == 0 ? 0 : max(0LL, n%b - k + 1));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int N;
int kotae[500][500];
void sagasu(int L, int R, int r) {
	int H = (L + R) / 2;
	for (int i = L; i < H; i++) {
		for (int j = H; j < R; j++) kotae[i][j] = r;
	}
	if(L + 1 != H) sagasu(L, H, r + 1);
	if(H + 1 != R) sagasu(H, R, r + 1);
}


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


	cin >> N;

	sagasu(0, N, 1);

	rep(i, N - 1) {
		for (int j = i + 1; j < N; j++) {
			if (j == N - 1) co(kotae[i][j]);
			else cosp(kotae[i][j]);
		}
	}


	Would you please return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    string s;
    cin >> s;
    for(const char c : s)
    {
        cout << (c == ',' ? ' ' : c);
    }
    cout << endl;
}


Measured memory_bytes: 256
n,*a=map(int,open(0).read().split())
mod=10**9+7
ans=0
for j in range(60):
  cnt=0
  for i in range(n):
    cnt+=a[i]&1
    a[i]=(a[i]>>1)
  ans+=(cnt*(n-cnt)%mod)*pow(2,j,mod)
  ans%=mod
print(ans)

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

ll nCr(ll n, ll r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

int main(){
  ll N,M;
  cin>>N>>M;
  
  cout<<nCr(N,2)+nCr(M,2)<<endl;
}

Measured memory_bytes: 256
from math import log2
L=int(input())
ans=[]
i=1
while True:
    if 2**i>L:
        last=i
        break
    ans.append([i,i+1,2**(i-1)])
    ans.append([i,i+1,0])
    i+=1
"""for i in ans:
    print(i)
print(last)"""
num=2**(last-1)
a=L-num
while a>0:
    ans.append([int(log2(a))+1,last,num])
    num+=2**(int(log2(a)))
    a=L-num
print(last,len(ans))
for i in ans:
    print(*i)


Measured memory_bytes: 3064
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      int N = nextInt();
      ArrayList<Integer> list = nextIntArray();
      int output = 0;
      int now = 1;
      for(int i = 0; i < N; i++){
        if(list.get(i) == now){
          now++;
        }else{
          output++;
        }
      }
      myout((output == N) ? -1 : output);
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 62776
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    vector<pair<int, int>> p(m);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        p[i].first = a;
        p[i].second = b;
    }
    int res = 0;
    for (int e = 0; e < m;e++){
        vector<int> edge[55];
        for (int i = 0; i < m;i++){
            if(i==e)
                continue;
            else{
                edge[p[i].first].push_back(p[i].second);
                edge[p[i].second].push_back(p[i].first);
            }
        }
        bool use[55];
        fill(use, use + 55, false);
        use[0] = true;
        queue<int> Q;
        Q.push(0);
        while(!Q.empty()){
            int x = Q.front();
            Q.pop();
            for(auto it:edge[x]){
                if(use[it]==false){
                    Q.push(it);
                }
                use[it] = true;
            }
        }
        bool bridge=false;
        for (int i = 0; i < n;i++){
            if(use[i]==false){
                bridge= true;
            }
        }
        if(bridge)
            res++;
    }
    cout << res << endl;
}

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

int main() {
	int N, M, tmp; cin >> N;
	int A[N+1];
	for (int i = 1; i <= N; ++i) {
    	cin >> A[i];
    }
	int box[N+1] = { 0 };
	for (int i = N; i > N/2; --i) {
    	if (A[i] == 1) { box[i] = 1; }
    }
	for (int i = N/2; i >= 1; --i) {
    	tmp = 0;
    	for (int j = 2*i; j <= N; j += i) {
        	tmp += box[j];
        }
    	if (tmp % 2 == A[i]) { continue; }
    	else { box[i] = 1; }
    }
	M = count(box+1,box+(N+1),1);
	cout << M << endl;
	for (int i = 1; i <= N; ++i) {
    	if (box[i]) {
        	cout << i << ' ';
        }
    }
	cout << endl;
}

Measured memory_bytes: 2432
#include<stdio.h>
int main(void){
  int k,l;
  int a[4],b[4];
  int hit,blow;
  while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])!=EOF){
    scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
    hit = 0, blow = 0;
    for(k=1;k<=4;k++){
      if(a[k-1]==b[k-1]) hit++;
    }
    for(k=1;k<=4;k++){
      for(l=1;l<=4;l++){
        if(a[k-1]==b[l-1] && k!=l){
          blow++;
        }
      }
    }
    printf("%d %d\n",hit,blow);
  }
  return 0;
}

Measured memory_bytes: 596
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

void solve(){
	int n;
	cin >> n;
	map<string, pair<int, int>> variables;
	REP(i, n) {
		string a;
		int b, c;
		cin >> a >> b >> c;
		variables[a] = mp(b, c);
	}
	stack<set<int>> now_stack;
	int m;
	cin >> m;
	REP(te, m) {
		string s;
		cin >> s;
		if (s[0] >= '0' && s[0] <= '9') {
			now_stack.push(set<int>{stoll(s)});
		}
		else if(variables.find(s) != variables.end()) {
			set<int> geko;
			for (int q = variables[s].first; q <= variables[s].second; ++q) {
				geko.insert(q);
			}
			now_stack.push(geko);
		}
		else {
			set<int> now[2];
			now[0] = now_stack.top();
			now_stack.pop();
			now[1] = now_stack.top();
			now_stack.pop();
			set<int> result;
			for (auto x : now[1]) {
				for (auto y : now[0]) {
					if (s == "+") {
						result.insert((x + y) % 256);
					}
					else if (s == "-") {
						result.insert((x - y + 256) % 256);
					}
					else if (s == "*") {
						result.insert((x * y) % 256);
					}
					else {
						if (y == 0) {
							cout << "error" << endl;
							return;
						}
						result.insert((x / y) % 256);
					}
				}
			}
			now_stack.push(result);
		}
	}
	cout << "correct" << endl;
}

#undef int
int main() {
	init();

	solve();
}


Measured memory_bytes: 3304
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
 
int main(){
  int a,b,c,d,e;
  int k, N;
  cin >> a >> b >> c >> d >> e;
  cin >> k;
  
  N = e - a;
  if (N <= k)cout << "Yay!";
  else cout << ":(";
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,m,cnt,ans,head[1100000],h[1100000];
struct road
{
    int to;
    int next;
}road[1100000];
void add(int u,int v)
{
    ++cnt;
    road[cnt].to=v;
    road[cnt].next=head[u];
    head[u]=cnt;
}
int check(int t)
{
    for(int i=head[t];i;i=road[i].next)
    {
        if(h[t]<=h[road[i].to])return 0;
    }
    return 1;
}
int main(void)
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>h[i];
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        add(u,v);
        add(v,u);
    }
    for(int i=1;i<=n;i++)
    {
        if(check(i))
        {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5932
MOD = 10**9 + 7

N,M = map(int,input().split())
a = [0] * N
b = [0] * N
c = [0] * M
d = [0] * M
min = [MOD] * N
min_num = [0] * N
for i in range(N):
    a[i],b[i] = map(int,input().split())
for t in range(M):
    c[t],d[t] = map(int,input().split())

for j in range(N):
    for q in range(M):
        dist = abs(a[j] - c[q]) + abs(b[j] - d[q])
        if dist < min[j]:
            min[j] = dist
            min_num[j] = q + 1
for k in min_num:
    print(k)


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

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            String pin = reader.readLine();
            char[] chars = pin.toCharArray();
            char prev = ' ';
            boolean first = true;
            for (char c : chars) {
                if (!first) {
                    if (prev == c) {
                        System.out.println("Bad");
                        return;
                    }
                }
                first = false;
                prev = c;
            }
            System.out.println("Good");
        }
    }

}

Measured memory_bytes: 21332
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  vector<int> pos;
  vector<int> left;
  vector<int> right;
  int i;
  int cnt_f = 0;
  int cnt_b = 0;
  int cnt_1 = 0;
  int cnt_2 = 0;
  for (i=0; i<N; ++i){
    if (S[i] == '#'){
      left.push_back(cnt_f);
      pos.push_back(i);
      ++cnt_f;
      ++cnt_1;
    }else{
      ++cnt_2;
    }
    if (S[N-1-i]=='#'){
      right.push_back(cnt_b);
      ++cnt_b;
    }
  }
  if (cnt_1 == 0 || cnt_2 ==0){
    cout << 0 << endl;
  }else{
    int ans = 1000000;
    int pat3 = 0;
    if (pos.empty()) ans = 0;
    int PN = pos.size();
    for (i=0; i<pos.size(); ++i){
      pat3 = left[i] + N - pos[i] - 1 - right[PN-1-i]; //左变. 右边# 自己#
      ans = min(ans, pat3);
    }
    ans = min(ans, cnt_1);
    ans = min(ans, cnt_2);
    cout << ans << endl;
  }
}

Measured memory_bytes: 3044