akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

class UnionFind :
    def __init__(self, size) :
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        self.component -= 1  # 連結成分を減らす

        if self.height[root1] < self.height[root2] :
            self.parent[root1] = root2  # root2に結合
            self.size[root2] += self.size[root1]
        else :
            self.parent[root2] = root1  # root1に結合
            self.size[root1] += self.size[root2]
            if self.height[root1] == self.height[root2] :
                self.height[root1] += 1
        return

    def isSameRoot(self, index1, index2) :
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        return self.size[self.root(index)]

    def getComponent(self) :
        return self.component

N, M, K = map(int, input().split())
tree = UnionFind(N)

friend = [[i] for i in range(N)]
for _ in range(M):
    fr, to = map(int, input().split())
    fr -= 1
    to -= 1
    tree.union(fr, to)
    friend[fr].append(to)
    friend[to].append(fr)

dis = [[] for _ in range(N)]
for _ in range(K):
    fr, to = map(int, input().split())
    fr -= 1
    to -= 1
    dis[fr].append(to)
    dis[to].append(fr)

grp = defaultdict(set)
for i in range(N):
    grp[tree.root(i)].add(i)

ans = []
for i in range(N):
    A = grp[tree.root(i)]
    cnt = len(A)
    for to in friend[i]:
        if to in A:
            cnt -= 1
    for to in dis[i]:
        if to in A:
            cnt -= 1
    ans.append(cnt)

print(*ans)

Measured memory_bytes: 117424
#include<iostream>
#include<vector>
using namespace std;
#define inRange(x,a,b) (a <= x && x <= b)

int main(){
    int n, a, d, m, k;
    cin >> n >> a >> d;
    cin >> m;
    vector<int> x(m), y(m), z(m);
    for(int i = 0; i < m; i++){
        cin >> x[i] >> y[i] >> z[i];
        y[i]--, z[i]--;
    }
    cin >> k;
    k--;
    for(int i = m-1; i >= 0; i--){
        if(x[i]==0&&inRange(k,y[i],z[i])){
            k = y[i] + z[i] - k;
        }
    }
    int ans = a+k*d;
    for(int i = 0; i < m; i++){
        if(!inRange(k, y[i], z[i])) continue;
        if(x[i] == 0){
            k = y[i] + z[i] - k;
        }else if(x[i] == 1){
            ans++;
        }else if(x[i] == 2){
            ans /= 2;
        }
    }
    cout << ans << endl;
    return 0;
}


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

 int main() {
 string s;
 string t;
 cin >> s;
 cin >> t;
 sort(s.begin(), s.end());
 sort(t.begin(), t.end(), greater<int>());
 if(s < t) cout << "Yes" << endl;
 else cout << "No" << endl;
 }

Measured memory_bytes: 256
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i,j;
  int a,n,k[10],m[10];
  char c[10];
  for(;;){
    cin>>n;
    if(n==0)
      break;
    memset(k,0,sizeof(k));
    memset(m,0,sizeof(m));
    for(i=0;i<n;i++){
      cin>>c[i];
      for(j=0;j<n-1;j++){
	cin>>a;
	if(a==0)
	  k[i]++;
	else if(a==1)
	  m[i]++;
      }
    }
    do{
      h=0;
      for(i=1;i<n;i++){
	if(k[i-1]<k[i]){
	  swap(k[i-1],k[i]);
	  swap(m[i-1],m[i]);
	  swap(c[i-1],c[i]);
	  h=1;
	}else if(k[i-1]==k[i]){
	  if(m[i-1]>m[i]){
	    swap(k[i-1],k[i]);
	    swap(m[i-1],m[i]);
	    swap(c[i-1],c[i]);
	    h=1;
	  }
	}
      }
    }while(h);
    for(i=0;i<n;i++)
      cout<<c[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005],dp[100005];
ll n,k;
ll ans=0;
ll recur(ll i)
{
	if(dp[i]!=-1)
	{	
		return dp[i];
	}	
	if(i==n-1)
	{
		return 0;
	}
	ll q,mini=LONG_LONG_MAX;
	for(ll j=1;i+j<n && j<=k;j++)
	{
		q=abs(a[i]-a[i+j])+recur(i+j);
		mini=min(q,mini);
	}
	
	dp[i]=mini;
	return(mini);
}
int main()
{
for(ll i=0;i<100005;i++)
dp[i]=-1;
cin>>n>>k;	
for(ll i=0;i<n;i++)
cin>>a[i];
cout<<recur(0);
return 0;
}

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

//var 
LL n, a[100001], tn, suf[100001], amt[100001],mx, ans = 0;

int main(){
	cin >> n;
	for(LL i = 0; i<=n; i++)cin >> a[i];
	suf[n] = a[n];
	for(LL i = n-1; i>=0; i--){
		suf[i] = suf[i+1];
		suf[i] += a[i];
	}
	amt[0] = 1;
	if(a[0] > 0 && n != 0){
		cout << -1 << endl;
		return 0;
	}
	if(n == 0 && a[0] != 1){
		cout << -1 << endl;
		return 0;
	}
	for(LL i = 1; i<=n; i++){
		mx = amt[i-1] * (LL)2;
		mx -= a[i];
		if(mx < 0){
			cout << -1 << endl;
			return 0;
		}
		if(mx == 0 && i != n){
			cout << -1 << endl;
			return 0;
		}
		amt[i] = min(suf[i] - a[i], mx);
		ans += amt[i] + a[i];
	}
	cout << ans+1 << endl;
	return 0;

}

Measured memory_bytes: 5976
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------

int main(void){
    ll n;
    cin >> n;
    vector<pair<pair<ll,ll>,string>> vec1;
    vector<pair<pair<ll,ll>,string>> vec2;

    rep(i, n){
        string s;
        cin >> s;
        ll cnt = 0;
        ll mi = 0;
        rep(j, s.size()){
            if(s[j] == '('){
                cnt++;
            } else {
                cnt--;
            }
            mi = min(mi,cnt);
        }

        ll revcnt = 0;
        ll revmin = 0;
        for(int j = s.size(); j >= 0; j--){
            if(s[j] == ')'){
                revcnt++;
            } else {
                revcnt--;
            }
            revmin = min(revmin, revcnt);
        }
        if(cnt > 0) {
            vec1.push_back({{mi, cnt}, s});
        } else {
            vec2.push_back({{revmin, revcnt}, s});
        }
    }



    sort(all(vec1), greater<pair<pair<ll,ll>,string>>());
    sort(all(vec2));

    string str = "";
    rep(i, vec1.size()){
        str += vec1[i].second;
    }
    rep(i, vec2.size()){
        str += vec2[i].second;
    }
    ll ans = 0;

    rep(i, str.size()){
        if(str[i] == '('){
            ans++;
        } else {
            ans--;
        }
        if(ans < 0){
            cout << "No" << endl;
            return 0;
        }
    }

    if(ans == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 52976
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
//#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}

int n,a,ans=1;
map<int, int>m;
void f(int x) {
	int y = x;
	for (int i = 2; i < 1000; i++) {
		if (!prime(i)) {
			continue;
		}
		while (y % i == 0) {
			if (!m.count(i)) {
				m[i] = 0;
			}
			y /= i;
			m[i]++;
		}
		if (y == 1) {
			break;
		}
	}
}



signed main() {
	cin >> n;
	for (int i = 2; i <= n; i++) {
		f(i);
	}
	for (auto p : m) {
		auto k = p.first;
		auto v = p.second;
		ans *= p.second + 1;
		ans %= mod;
	}
	ans %= mod;
	cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        int c = 0;

        if (a >= b){
            c = a - 1;
            if (b >= c){
                System.out.println(a + b);
            } else {
                System.out.println(a + c);
            }
        } else {
            c = b - 1;
            if (a >= c){
                System.out.println(a + b);
            } else {
                System.out.println(b + c);
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 23124
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
ll n, m, k = 0, l = 0, x, y;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	map<ll,map<ll,ll>> dp;

	cin >> dp[0][0] >> dp[0][1] >> dp[0][2];

	for (int i = 1; i < n; i++) {
		cin >> dp[i][0] >> dp[i][1] >> dp[i][2];
		dp[i][0] += max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] += max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] += max(dp[i-1][1], dp[i-1][0]);
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
}


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

int par[100005];

int parent(int i) {
    if (par[i] == i) return i;
    par[i] = parent(par[i]);
    return par[i];
}

bool areconnected(int a, int b) {
    return parent(a) == parent(b);
}

void connect(int a, int b) {
    int au = parent(a);
    int bu = parent(b);
    par[au] = bu;
}

int main() {

    int n, m;
    cin >> n >> m;
    for (int i=0; i<n; i++) {
        par[i] = i;
    }
    for (int i=0; i<m; i++) {
        int a, b, x;
        cin >> a >> b >> x;
        a--; b--;
        if (!areconnected(a, b)) {
            connect(a, b);
        }
    }
    set<int> pars;
    for (int i=0; i<n; i++) {
        pars.insert(parent(i));
    }
    cout << pars.size();

}

Measured memory_bytes: 5376
#include <stdio.h>
#include<math.h>
using namespace std;

bool rangeCheck(int x,int y){
	if(x >= 0 && x <= 9 && y>=0 && y <= 9)return true;
	else{
		return false;
	}
}

int main(){
	int paper[10][10],x,y,size;
	for(int i=0;i<10;i++){
		for(int k=0;k<10;k++){
			paper[i][k] = 0;
		}
	}

	while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
		switch(size){
		case 1:
			paper[x][y]++;
			if(rangeCheck(x,y-1))paper[x][y-1]++;
			if(rangeCheck(x,y+1))paper[x][y+1]++;
			if(rangeCheck(x-1,y))paper[x-1][y]++;
			if(rangeCheck(x+1,y))paper[x+1][y]++;
			break;
		case 2:
			paper[x][y]++;
			if(rangeCheck(x-1,y-1))paper[x-1][y-1]++;
			if(rangeCheck(x,y-1))paper[x][y-1]++;
			if(rangeCheck(x+1,y-1))paper[x+1][y-1]++;
			if(rangeCheck(x-1,y))paper[x-1][y]++;
			if(rangeCheck(x+1,y))paper[x+1][y]++;
			if(rangeCheck(x-1,y+1))paper[x-1][y+1]++;
			if(rangeCheck(x,y+1))paper[x][y+1]++;
			if(rangeCheck(x+1,y+1))paper[x+1][y+1]++;
			break;
		case 3:
			paper[x][y]++;
			if(rangeCheck(x-1,y-1))paper[x-1][y-1]++;
			if(rangeCheck(x,y-1))paper[x][y-1]++;
			if(rangeCheck(x+1,y-1))paper[x+1][y-1]++;
			if(rangeCheck(x-1,y))paper[x-1][y]++;
			if(rangeCheck(x+1,y))paper[x+1][y]++;
			if(rangeCheck(x-1,y+1))paper[x-1][y+1]++;
			if(rangeCheck(x,y+1))paper[x][y+1]++;
			if(rangeCheck(x+1,y+1))paper[x+1][y+1]++;
			if(rangeCheck(x,y-2))paper[x][y-2]++;
			if(rangeCheck(x-2,y))paper[x-2][y]++;
			if(rangeCheck(x+2,y))paper[x+2][y]++;
			if(rangeCheck(x,y+2))paper[x][y+2]++;
			break;
		}
	}

	int count = 0,max = -1;
	for(int i=0; i< 10;i++){
		for(int k=0; k < 10; k++){
			if(paper[i][k] == 0)count++;
			max = (max >= paper[i][k])?max:paper[i][k];
		}
	}
	printf("%d\n%d\n",count,max);

    return 0;
}

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

int main()
{
    long long ans=0,f=2,s=1;
    int n;
    cin>>n;
    if(n==1) cout<<'1'<<endl;
    else
    {
        for(int i=2;i<=n;i++)
        {
            ans=f+s;
            f=s;
            s=ans;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<string>
#include<iostream>
#define R(i, n) for(int i = 0; i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d",  &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define P(a) printf("%d\n", a)
#define PY printf("%s", "Yes");
#define PN printf("%s", "No");
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> IR;

int main(){
	int n;
	S(n);
	vector<int> v(n);
	R(i, n){
		int num;
		S(num);
		v[i] = num - 1;
	}
	int ans = 0;
	vector<bool> che(n);
	R(i, n){
		if(!che[i] && v[v[i]] == i) {
			ans++;
			che[v[i]] = true;
		}
	}
	P(ans);
}

Measured memory_bytes: 3800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define mod 1000000007
#define PI 3.1415926535897932
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, j, n) for (int i = j; i < n; i++)
#define repi(i, n) for (int i = 0; i <= n; i++)
#define repie(i, j, n) for (int i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<int, int>
#define fi first
#define se second

typedef long long ll;

long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

ll sumf(ll n) {
    ll r = n*(n+1);
    r %= mod;

    return r*modinv(2, mod)%mod;
}

ll fnc(ll k, ll n) {
    ll s = sumf(k-1);
    ll end = sumf(n)-sumf(n - k);
    if(end < 0) {
        end += mod;
    }

    ll r = end - s;
    if(r < 0) {
        r += mod;
    }

    return r;
}

void solve1()
{
    int n, k; cin >> n >> k;
    ll sum = 1;
    for(int i = k; i < n + 1; i++) {
        sum += fnc(i, n) + 1;
        sum %= mod;
    }

    cout << sum << endl;
}

int main()
{
    solve1();
}


Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n,m;cin>>n>>m;
  if(n>=2&&m>=2){
    cout<<(n-2)*(m-2)<<endl;
  }else if(n>=2&&m==1){
    cout<<(n-2)<<endl;
  }else if(n==1&&m>=2){
    cout<<(m-2)<<endl;
  }else{
    cout<<1<<endl;
  }
  return 0;
}

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

#define ll long long

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n,k;
	cin>>n>>k;
	int a[n],sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<k;i++)
		sum+=a[i];
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3680
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

A, B, C, D = LI()

while True:
    C = C - B
    A = A - D
    if C <= 0:
        print("Yes")
        break
    if A <= 0:
        print("No")
        break


Measured memory_bytes: 71692
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;

public class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int n = stdIn.nextInt();
        int m = stdIn.nextInt();
        Integer[] a = new Integer[n];
        long sum = 0;
        for(int i=0; i<n; i++){
            a[i] = stdIn.nextInt();
            sum += a[i];
        }

        Arrays.sort(a, Collections.reverseOrder());

        if(a[m-1] * (4 * m) >= sum){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21972
#include <algorithm>
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int dist(const vector<int>& x, const vector<int>& y) {
    int sum = 0;
    for (int i=0; i<x.size(); i++) {
        sum += (x[i] - y[i]) * (x[i] - y[i]);
    }
    return sum;
}


int main(int argc, char* argv[]) {

    int n, d;
    cin >> n >> d;

    vector<vector<int>> x(n, vector<int>(d));
    for (int i=0; i<n; i++) {
        for (int j=0; j<d; j++) {
            cin >> x[i][j];
        }
    }

    int count = 0;
    for (int i=0; i<n-1; i++) {
        for (int j=i+1; j<n; j++) {
            const int r = dist(x[i], x[j]);

            // check square
            for (int k=1; k*k <= r; k++) {
                if (k*k == r) {
                    count ++;
                }
            }
        }
    }

    cout << count;

    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#include <numeric>
#include <math.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(void) {
	int N;
	cin >> N;
	vector<int> vec(N);
	for (int i = 0; i < N; i++) cin >> vec.at(i);
	sort(vec.begin(), vec.end());
	int ans = 0;
	for (int i = 0; i < N-2; i++) {
		for (int j = i + 1; j < N - 1; j++) {
			if (vec.at(i) == vec.at(j)) continue;
			for (int k = j + 1; k < N; k++) {
				if (vec.at(j) == vec.at(k)) continue;
				if (vec.at(i) + vec.at(j) > vec.at(k)) ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
def main():
    s = str(input())
    t = str(input())

    for i in range(len(s)):
        if(s[i] != t[i]):
            print('No')
            return 0
    if(len(t) == len(s) + 1):
        print('Yes')

if __name__ == "__main__":
    main()

Measured memory_bytes: 8932
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string MARCH = "MARCH";
    int N; cin >> N;
    map<char,ll> mp;
    for(int i = 0; i < N;i++){
        string S; cin >> S;
        mp[S.front()]++;
    }

    for(int i = 0; i < 5;i++){
        for(int j = i+1; j < 5;j++){
            for(int k = j+1; k < 5;k++){
                res += mp[MARCH[i]]*mp[MARCH[j]]*mp[MARCH[k]];
            }
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    //solve<ll>(0);
    cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(){
	int W, H, x, y, r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if (W < (x + r) || H < (y + r) || W == x || H == y || 1 > (x + r) || 1 > (y + r)){
		printf("No\n");
	}
	else{ printf("Yes\n"); }



	return 0;
}

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

int main(){
    ll N,K;
    cin >> N >> K;
    
    //データ入力
    vector<ll> town(N+1);
    vector<ll> step(N+1,0);
    for(ll i=1; i<=N; i++){
        cin >> town[i];
    }
    
    
    ll now=1;
    ll step_su=1; step[1]=0;
    while(K>0){
        now = town[now];
        step_su++;
        K--;
        //訪れたことなければ更新
        if(step[now]==0){
            step[now] = step_su;
        }else{
            ll x = step_su - step[now];
            K %=x;
        }
        
        //cout << now << " ";
        
    }
    //cout << endl;
    //cout << "ans" << endl;
    cout << now << endl;
    
}


Measured memory_bytes: 6412
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

vector<vector<long long>> dp(500001);
long long solve(vector<int> &v) {
  if (v.size() < 2)
    return 0;
  dp[0][0] = dp[1][0] = dp[0][1] = dp[1][1] = dp[0][2] = dp[1][2] = dp[0][3] =
      dp[1][3] = 0;
  for (int i = 1; i < v.size(); i++) {
    dp[i + 1][0] = max(max(dp[i][0], dp[i][1]), max(dp[i][2], dp[i][3]));
    if (v[i - 1] > 1) {
      // right
      dp[i + 1][2] =
          max(max(dp[i][0] + v[i], dp[i][1] + v[i]), dp[i][3] + v[i]);
      // left
      dp[i + 1][1] = max(dp[i][0] + v[i - 1], dp[i][1] + v[i - 1] - 1);
      if (v[i] > 1) {
        dp[i + 1][3] =
            max(max(dp[i][0] + v[i], dp[i][1] + v[i]), dp[i][3] + v[i]) - 1;
      } else {
        dp[i + 1][3] = 0;
      }
    } else {
      dp[i + 1][2] = dp[i][0] + v[i];
      dp[i + 1][1] = dp[i][0] + v[i - 1];
      if (v[i] > 1) {
        dp[i + 1][3] = dp[i][0] + v[i] - 1;
      } else {
        dp[i + 1][3] = 0;
      }
    }
  }
  return max(max(dp[v.size()][0], dp[v.size()][1]),
             max(dp[v.size()][2], dp[v.size()][3]));
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i <= n; i++)
    dp[i].resize(4);
  s.push_back('0');
  vector<pair<int, int>> v;
  int now = '0', c = 1;
  for (int i = 0; i < n + 1; i++) {
    if (s[i] == now) {
      c++;
    } else {
      v.push_back(make_pair(now, c));
      c = 1;
    }
    now = s[i];
  }
  vector<vector<int>> q;
  vector<int> w;
  for (int i = 1; i < v.size(); i += 2) {
    if (v[i - 1].second == 1) {
      w.push_back(v[i].second);
    } else {
      if (w.size() > 0)
        q.push_back(w);
      w.clear();
      w.push_back(v[i].second);
    }
  }
  if (w.size() > 0)
    q.push_back(w);
  long long ans = 0;
  for (int i = 0; i < q.size(); i++) {
    ans += solve(q[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 42872
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

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

int main(){
    int a,b;
    cin >> a >> b;
    if (a + b >= a * b && a + b >= a - b) {
        cout << a + b;
    } else if (a * b >= a - b) {
        cout << a * b;
    } else {
        cout << a - b;
    }
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    x, t = LI()
    print(max(0, x-t))
    return

#B
def B():
    s = S()
    print("".join(s[::2]))
    return

#C
def C():
    II()
    a = LI()
    lis = [0] * (max(a) + 3)
    for ai in a:
        lis[ai - 1] += 1
        lis[ai] += 1
        lis[ai + 1] += 1
    print(lis)
    print(max(lis))
    return

#D
def D():
    n = II()
    p = LI()
    ans = 0
    a = 0
    for i in range(n):
        k = i + 1
        if p[i] == k:
            a += 1
        else:
            ans += (a + 1) // 2
            a = 0
    print(ans + (a + 1) // 2)
    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 53208
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
#include <regex>
#include <cassert>
#include <map>
// #include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N, M) for (ll i = N; i < M; ++i)
#define rrep(i, N, M) for (ll i = N; i < M; --i)
#define pb push_back


typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef priority_queue<ll> pqll;
typedef priority_queue<pll, vector<pll>> pqpll;
typedef priority_queue<ll, vll, greater<ll>> pqll_greater;
typedef priority_queue<pll, vector<pll>, greater<pll>> pqpll_greater;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>
#define _CRT_SECURE_NO_WARNINGS

template<class T, class S>
T atbit(T n, S i) {
	return (n >> i) % i;
}

template<class T>
T getbit(T i) {
	return 1LL << i;
}

//#define TRANSFORM(v,w,func) decltype(v) w ; transform((v).begin(),(v).end(),back_inserter(w),func);

using namespace std;

bool check1(vector<string> W) {
	rep(i, 0, W.size()-1) {
		rep(j, i+1, W.size()) {
			if (W[i] == W[j]) return false;
		}
	}
	return true;
}	
bool check2(vector<string> W) {
	rep(i, 0, W.size()-1) {
		if (W[i].back() != W[i+1].front()) {
			return false;
		}
	}
	return true;
}

int main() {
	ll N;
	cin >> N;
	vector<string> W(N);
	rep(i,0, N) {
		cin>>W[i];
	}
	auto flg = check1(W)&& check2(W);
	if (flg) cout << "Yes";
	else cout << "No";


}
//ll N;
//cin >> N;
//vll a(N);
//rep(i,0, N) cin >> a[i];

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define loop(i,b,e) for(int i=b;i<=e;i++)
#define loop2(i,e,b) for(int i=e;i>=b;i--)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define X real()
#define Y imag()
#define cp(a,b)	( (conj(a)*(b)).imag() )
#define length(a) (hypot((a).imag(), (a).real()))
typedef complex<double> point;
typedef long long ll;
typedef unsigned long long ull;
double PI = 3.141592653589793;
const double EPS = 1e-9;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

int n = 3;
int t[30];

int main() {
	n = 3;
	int ans = 3000;
	loop(i, 0, 2)
		cin >> t[i];
	do {
		int curr = 0;
		loop(i, 1, 2)
			curr += abs(t[i] - t[i - 1]);
		ans = min(ans, curr);
	} while (next_permutation(t, t + n));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/



signed main() {
	int n, m, d; cin >> n >> m >> d;
	if (d == 0) {
		printf("%.12lf\n", (double)n / (n * n) * (m - 1));
	}
	else {
		printf("%.12lf\n", (double)(n - d) * 2 / (n * n) * (m - 1));
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(), v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 1;
vector<int> g[N];
vector<int> vis(N);
void solve(){
    int n;
    cin >> n;
    int a[n];
    map<int, vector<int>> store;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        store[a[i]].push_back(i);
    }
    sort(a, a + n);
    vector<int> ans(n);
    map<int, int> idx;
    for(int i = 0; i < n / 2; i++){
        ans[store[a[i]][idx[a[i]]++]] = a[n / 2];
    }
    for(int i = n / 2; i < n; i++){
        ans[store[a[i]][idx[a[i]]++]] = a[n / 2 - 1];
    }
    for(int &i : ans){
        cout << i << '\n';
    }
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        solve();
    }
}

Measured memory_bytes: 71260
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;

int main(){
  string s;cin>>s;
  map<char, int> mp;
  for(int i=0;i<4;i++){
  	mp[s[i]]++;
  }
  if(mp.size()==2 && mp.begin()->second==2)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
from math import degrees, atan
a, b, x = map(float, input().split())
y = min(x, a * a * b - x)
if y != x:
  print(degrees(atan(2 * y / a / a / a)))
else:
  print(90 - degrees(atan(2 * y / a / b / b)))
  


Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main(){
	int a = 0, b = 0, c=0, d[100000], e[100000],f=0, count = 0;
	char ac,uc[100000];
	cin >>a>>b>>c ;
	cout << a + b + c - max(a, max(b, c)) << endl;
		return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {
    public static void main(String[] args){
       Scanner scan = new Scanner(System.in);
       int a = scan.nextInt();
       int b = scan.nextInt();
       int d;
       int r;
       double f;
       
       d = a / b;
       r = a % b;
       f = 1.0 * a / b;
       
       System.out.print(d + " " + r + " " + String.format("%8f", f));
    }
}

Measured memory_bytes: 26360
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

//
// solution 
//
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        N: usize,
        M: usize,
        Q: usize,
        train: [(usize, usize); M],
        part: [(usize, usize); Q],
    }

    let mut count_map = vec![ vec![0; N+1]; N+1];
    for t in train.iter() {
        count_map[t.0][t.1] += 1;
    }

    let mut cml_sum = vec![ vec![0; N+1]; N+1];
    let mut colum_sum = vec![0; N+1];
    for i in 0..N+1 {
        colum_sum[0] += count_map[i][0];
        cml_sum[i][0] = colum_sum[0];
        for j in 1..N+1 {
            colum_sum[j] += count_map[i][j];
            cml_sum[i][j] = cml_sum[i][j-1] + colum_sum[j];
        }
    }

    for q in part.iter() {
        let count = cml_sum[q.0-1][q.0-1] + cml_sum[q.1][q.1] - cml_sum[q.0-1][q.1] - cml_sum[q.1][q.0-1];
        println!("{}", count);
    }
}


Measured memory_bytes: 13180
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	cout << ((a + b) >= 24 ? a + b - 24 : a + b);
	return 0;
}

Measured memory_bytes: 256
#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)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
struct Node { int hit; Node* c[2]; Node() { hit = 0; c[0] = c[1] = 0; } };
struct Trie01 {
    Node* root; Trie01() { root = new Node(); }
    void add(string x) { update(root, x); }
    void update(Node*& x, string& a, int b = 0) {
        if (!x) x = new Node();
        if (b == a.length()) { x->hit = 1; return; } update(x->c[a[b] - '0'], a, b + 1);
    }
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






typedef long long ll;
int N;ll L;
string S[101010];
//---------------------------------------------------------------------------------------------------
ll dfs(Node* n, ll i) {
    if (!n) return i & (-i);

    if (n->hit) return 0;
    return dfs(n->c[0], i - 1) ^ dfs(n->c[1], i - 1);
}
//---------------------------------------------------------------------------------------------------
void _main() {
    while (cin >> N >> L) {
        rep(i, 0, N) cin >> S[i];

        Trie01 trie;
        rep(i, 0, N) trie.add(S[i]);

        ll g = dfs(trie.root, L + 1);
        if (g != 0) printf("Alice\n");
        else printf("Bob\n");
    }
}


Measured memory_bytes: 6992
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn gcd(a: u64, b: u64) -> u64 {
    let mut a = a;
    let mut b = b;
    if a < b {
        std::mem::swap(&mut a, &mut b);
    }
    if b == 0 {
        return a;
    }
    gcd(b, a % b)
}
fn lcm(a: u64, b: u64) -> u64 {
    let gcd = gcd(a, b);
    (a / gcd) * b
}

fn main() {
    let a: u64 = read();
    let b: u64 = read();
    let c: u64 = read();
    let d: u64 = read();
    let all_count = b - a + 1;
    let c_count = (b / c) - ((a - 1) / c);
    let d_count = (b / d) - ((a - 1) / d);

    let lcm = lcm(c, d);
    let lcm_count = (b / lcm) - ((a -1)/ lcm);
    println!(
        "{}",
        std::cmp::max(
            all_count as i64 - c_count as i64 - d_count as i64 + lcm_count as i64,
            0
        )
    );
}


Measured memory_bytes: 4352
def main():
    n, m, *ab = map(int, open(0).read().split())
    e = [set() for _ in range(n)]
    for u, v in zip(*[iter(ab)] * 2):
        e[u - 1].add(v - 1)
        e[v - 1].add(u - 1)

    ans = 0
    for _ in range(m):
        count = 0
        for i, x in enumerate(e):
            if len(x) == 1:
                j = x.pop()
                e[j] -= {i}
                count += 1
        if count:
            ans += count
        else:
            print(ans)
            exit()


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
t[55],y[55],n,x,z,i;
main(){
	for(;n-2||!z++;){
		for(i=1;i<2||getchar()==',';scanf("%d",y+i++));
		if(i>n)
			for(n=i;--i;t[i]=y[i]+t[t[i]>t[i-1]?i:i-1]);
		else
			for(n=i,i=0;i++<n;t[i]=y[i]+t[t[i]>t[i+1]?i:i+1]);
	}
	n=!printf("%d\n",t[1]);
}

Measured memory_bytes: 0
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE
ll can(string s)
{
    ll f=0;
    ll n1 = s.size();
    for(int i=0;i<s.size()/2;i++)
    {
         if(s[i]!=s[n1-i-1])
         {
            f=1;
            break;
         }
    }
    return 1-f;
}
signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
         
           string s;
           cin>>s;
           ll n = s.size();
           ll rem = n-(n+3)/2+1;
           string s1 = s.substr(0,(n-1)/2);
           string s2 = s.substr((n+3)/2-1,rem);
           // cout<<s2<<endl;
           if(can(s) && can(s1) && can(s2))
           {
              cout<<"Yes\n";

           }
           else
            cout<<"No\n";

      }
      






}



























Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int n,m,ans;
    cin>>n>>m;
    vector<long long>x(n),y(n),a(m),b(m);
    rep(i,n)cin>>x[i]>>y[i];
    rep(j,m)cin>>a[j]>>b[j];
    long long d,l;
    rep(i,n){
        d=1000000000000000000;
        rep(j,m){
            l=abs(x[i]-a[j])+abs(y[i]-b[j]);
            if(l<d){
                d=l;
                ans=j+1;
            }
        }
        cout<<ans<<endl;
    }
	return 0;
}


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

using namespace std;

typedef long long ll;

ll md = 1000000007;


int main(int, char**)
{
	ll a, x;
	cin >> x >> a;

	if (x < a)
		cout << 0 << endl;
	else
		cout << 10 << 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);
		int a=sc.nextInt();
		int b=sc.nextInt();
		long ab=a*b;
		if(ab%2==0){
			System.out.println("Even");
		}else{
			System.out.println("Odd");
		}
	}
}


Measured memory_bytes: 21460
import java.text.DecimalFormat;
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args){
		
		//テキスト入力クラス
		Scanner sc = new Scanner(System.in);
		DecimalFormat df2 = new DecimalFormat("##########.##########");
		
		//半径
		double radius = sc.nextDouble(); 
		//面積
		double area = radius*radius*Math.PI;
		//周の長さ
		double circuit = radius*2*Math.PI;
		
		System.out.print(df2.format(area)+" "+df2.format(circuit));
		
	}

}

Measured memory_bytes: 18476
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class ESumEqualsXor {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String x = in.next();
            long mod = 10000_0000_7;
            long dp[] = new long[x.length() + 1];
            long dp2[] = new long[x.length() + 1];
            dp2[0] = 1;
            for (int i = 1; i <= x.length(); i++) {
                if (x.charAt(i - 1) == '1') {
                    dp2[i] = (2 * dp2[i - 1]) % mod;
                    dp[i] = (3 * dp[i - 1] + dp2[i - 1]) % mod;
                } else {
                    dp2[i] = dp2[i - 1] % mod;
                    dp[i] = (3 * dp[i - 1]) % mod;
                }
            }
            out.println((dp[x.length()] + dp2[x.length()]) % mod);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 26580
#At coder 2020/3/8 C
import math

I = list(map(int, input().split())) 
A=I[0]
B=I[1]

a1=A/0.08
b1=B/0.1

a2=(A+1)/0.08
b2=(B+1)/0.1

af=math.ceil(a1)
ac=math.ceil(a2)
bf=math.ceil(b1)
bc=math.ceil(b2)

if ac<=bf or bc<=af:
    ans=-1
else:
    ans=max(af,bf)
#print(af,ac,bf,bc)
print(ans)

Measured memory_bytes: 3064