akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int maxn = 1e5 + 10;
typedef long long ll;

class UnionFind {
private:
  vector<int> p, rank, setSize;
  int numSets;
public:
  UnionFind(int N) {
    setSize.assign(N, 1); numSets = N; rank.assign(N, 0);
    p.assign(N, 0); for (int i = 0; i < N; i++) p[i] = i; }
  int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
  bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
  void unionSet(int i, int j) {
    if (!isSameSet(i, j)) { numSets--;
    int x = findSet(i), y = findSet(j);
    if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
    else                   { p[x] = y; setSize[y] += setSize[x];
                             if (rank[x] == rank[y]) rank[y]++; } } }
  int numDisjointSets() { return numSets; }
  int sizeOfSet(int i) { return setSize[findSet(i)]; }
};

int main()
{
    int n;
    cin >> n;
    UnionFind uf(2 * maxn);
    for (int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        y += maxn;
        uf.unionSet(x, y);
    }
    map<int, ll> freqx, freqy;
    for (int i = 0; i < maxn; i++){
        freqx[uf.findSet(i)]++;
    }
    for (int i = maxn; i < 2 * maxn; i++){
        freqy[uf.findSet(i)]++;
    }
    ll ans = 0;
    for (int i = 0; i < 2 * maxn; i++){
        ans += freqx[i] * freqy[i];
    }
    ans -= n;
    cout << ans;
    return 0;
}


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

#define EPS (1e-7)
#define INF (99999999999L)
#define PI (acos(-1))

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

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

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; }

using ll = long long;

bool isprime[55556];

int main() {
  ll n; cin >> n;
  REP(i,55556) isprime[i] = true;
  isprime[0] = false, isprime[1] = false;
  for (int i = 2; i*i <= 55555; ++i) {
    if (isprime[i]) {
      for (int j = 2; i*j <= 55555; ++j) {
        isprime[i*j] = false;
      }
    }
  }
  vector<int> prime;
  REP(i,55556) if (isprime[i] && i%5 == 1) prime.push_back(i);
  REP(i,n) {
    cout << prime[i] << " ";
  }
  return 0;
}


Measured memory_bytes: 256
/*"Nothing is true."*/
#include<bits/stdc++.h>
using namespace std;
inline int min(int _a, int _b) {return _a < _b ? _a : _b;}
inline int max(int _a, int _b) {return _a > _b ? _a : _b;}
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;

template <class _T> inline void rd(_T &_a) {
	int _f=0,_ch=getchar();_a=0;
	while(_ch<'0' || _ch>'9'){if(_ch=='-')_f=1;_ch=getchar();}
	while(_ch>='0' && _ch<='9')_a=(_a<<1)+(_a<<3)+_ch-'0',_ch=getchar();
	if(_f)_a=-_a;
}

long long a[100100];
int n;

int main() {
	//freopen("AtCoder_020_B.in","r",stdin);
	//freopen("AtCoder_020_B.out","w",stdout);
	rd(n);int flag = 0;
	for(int i = 1;i <= n; ++i) {
		rd(a[i]); if(a[i] < 2 && i != n) flag = 1;;
	}
	long long ans = 0, minn = a[n], maxn = a[n] * 2 - 1;
	for(int i = n - 1;i >= 1; --i) {
		if(minn / a[i] * a[i] < minn) minn = ((minn / a[i]) + 1) * a[i];
		if(maxn * 2 - 1 < a[i]) {flag = 1; break;}
		maxn = ((maxn / a[i]) + 1) * a[i] - 1;
		if(maxn < minn) {flag = 1; break;}
	}
	if(a[n] != 2) flag = 1;
	if(flag == 1) puts("-1");
	else printf("%lld %lld\n", minn, maxn);
	return 0;
}



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

int main() {
  string N;
  cin >> N;
  if (N[0]!='7' && N[1]!='7' && N[2]!='7'){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  } 
}


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

const long long MOD = 1000000007;

int main() {
	int n, m;
	cin >> n >> m;

	long long sum_x = 0;
	for (int i = 1; i <= n; i++) {
		long long x;
		cin >> x;
		sum_x = (sum_x + (2*i-n-1)*x) % MOD;
	}

	long long sum_y = 0;
	for (int i = 1; i <= m; i++) {
		long long y;
		cin >> y;
		sum_y = (sum_y + (2*i-m-1)*y) % MOD;
	}
	
	cout << (sum_x * sum_y) % MOD << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
//----------program from here----------



int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int ab,bc,ca;
  ab=max(a,b)-min(a,b);
  bc=max(b,c)-min(b,c);
  ca=max(a,c)-min(a,c);
  if(ab<=d&&bc<=d||ca<=d){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <iomanip>

#include <algorithm>

#include <vector>

#include <stack>

#include <queue>

#include <cmath>

#include <set>

#include <map>

#include <string>

#include <numeric>

#include <cstdio>

#include <cstdlib>

using namespace std;


const int INF = 10000000;

typedef pair<int, int> P;
typedef long long ll;
#define PB push_back

//char maze[100][101];

ll n, m;

int sx, sy;

int gx, gy;

int qqq;

//各座標までの最短距離

int d[100][100];


//移動方向のベクトル

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

int ans = 0;
pair<int, int> red[101], blue[101];
//ll a[200000], b[20000];

//ユークリッドの互除法
ll gcd(ll x, ll y) {
	if (x < y) swap(x, y);
	if (y == 0) return x;
	return gcd(y, x%y);
}

//エラトステネスの篩 prime(n)[k]で1~nまで探索して(k+1)番目の素数を出力
vector<int> prime(int n) {
	vector<int> erst;
	for (int i = 0; i < n; ++i) erst.PB(i);
	erst[0] = erst[1] = NULL;
	auto dmax = sqrt(n);

	for (int dx = 2; dx < dmax; ++dx) {
		if (erst[dx] == NULL) continue;
		for (int i = dx * 2; i < n; i += dx) erst[i] = NULL;
	}

	vector<int> erstlist;
	for (auto i : erst) if (i) erstlist.PB(i);

	return erstlist;
}

ll v_find(std::vector<ll> vec, ll number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

ll BIG = 10000000000;

ll POW(ll a, ll b) {
	if (b == 0) return 1;
	return (a*POW(a, b - 1)) % BIG;
}

int Kaijou(int a) {
	if (a < 2) return 1;
	return a * Kaijou(a - 1);
}


ll aa[51];

int main() {
	int n;
	cin >> n;
	int a[100000] = { 0 };
	vector<int> b;
	vector<int> c;
	int aa;
	for (int i = 0; i < n; ++i) {
		cin >> aa;
		b.PB(aa);
	}
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) {
		cin >> aa;
		c.PB(aa);
	}
	sort(a, a + n); sort(b.begin(), b.end()); sort(c.begin(), c.end());
	ll pp=0;
	vector<int>::iterator p1,p2;
	for (int i = 0; i < n; ++i) {
		p1 = lower_bound(b.begin(), b.end(), a[i]);
		p2= upper_bound(c.begin(),c.end(), a[i]);
		pp += (ll)(p1-b.begin()) * (ll)(c.end() - p2);
	}
	cout << pp << endl;
	cin >> qqq;
	return 0;
}

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

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

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

    int a, b;
    cin >> a >> b;
    int l1 = a * 12.5 + 0.5, r1 = l1 + 12 - (a % 2),
        l2 = b * 10, r2 = l2 + 9;
    if (r1 > r2) {
        swap(r1, r2);
        swap(l1, l2);
    }
    if (l2 > r1) {
        cout << "-1";
        return 0;
    }
    cout << max(l1, l2);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int s1=0,s2=0;
		bool flag =1;
		for(int i=0;i<10;i++)
		{
			int n;
			cin>>n;
			if(i==0)
			{
				s1=n;
			}
			else
			{
				if(n>s1 && n>s2)
				{
					if(s1>s2)
						s1=n;
					else
						s2=n;
				}
				else if(n>s1 && n<s2)
				{
					s1=n;
				}
				else if(n>s2 && n<s1)
					s2=n;
				else 
				{
					flag=0;
					break;
				}
				
				
			}
		}
		if(flag)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>

using namespace std;

const int MOD = 10000;
int N, K, A, B;
int AB[101];
int dp[101][4][3];

int main() {

    fill(AB, AB + 101, 0);
    fill(dp[0][0], dp[100][3], 0);

    cin >> N >> K;

    for (int i = 1; i <= K; i++) {
        cin >> A >> B;
        AB[A] = B;
    }

    if (AB[1]) {
        dp[1][AB[1]][1] = 1;
    } else {
        dp[1][1][1] = 1;
        dp[1][2][1] = 1;
        dp[1][3][1] = 1;
    }

    for (int i = 2; i <= N; i++) {
        if (AB[i]) {
            for (int j = 1; j <= 3; j++) {
                if (j == AB[i]) {
                    dp[i][AB[i]][2] += dp[i - 1][j][1];
                } else {
                    dp[i][AB[i]][1] += dp[i - 1][j][1];
                    dp[i][AB[i]][1] += dp[i - 1][j][2];
                }
                dp[i][AB[i]][1] %= MOD;
                dp[i][AB[i]][2] %= MOD;
            }
        } else {
            for (int k = 1; k <= 3; k++) {
                for (int j = 1; j <= 3; j++) {
                    if (j == k) {
                        dp[i][k][2] += dp[i - 1][j][1];
                    } else {
                        dp[i][k][1] += dp[i - 1][j][1];
                        dp[i][k][1] += dp[i - 1][j][2];
                    }
                    dp[i][k][1] %= MOD;
                    dp[i][k][2] %= MOD;
                }
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= 2; j++) {
            ans += dp[N][i][j];
            ans %= MOD;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3092
import sys
input=sys.stdin.buffer.readline
from math import*

n=int(input())
arr=list(map(int,input().split()))
ans=1
if n>2:
	ans=gcd(arr[0],arr[1])
	for i in range(2,n):
		ans=gcd(ans,arr[i])
else:
	ans=gcd(arr[0],arr[1])
print(ans)

Measured memory_bytes: 84100
s = input()
n = len(s)

l = 0
r = 0

for i in range(n):
    if s[i] == 'A':
        l = i
        break

for i in reversed(range(n)):
    if s[i] == 'Z':
        r = i
        break

ans = len(s[l:r + 1])
print(ans)


Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
    }
    int ans=1;
    ans+=(n-k)/(k-1);
    if((n-k)%(k-1)!=0)ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
/*
 KUNAL RAUT (ZUKONIT14)  :- "DO WHAT YOU DONT LIKE!"
 -PICT,PUNE! :)
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define inv (mod+1)/3
#define mod9 1000000009
#define pi 3.1415926535
#define MAXN 1000001
#define MAX2N 1*1000 + 10
#define all(v) v.begin(), v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define forci(p,n) for(ll i=p;i<(ll)n;i++)
#define forcj(p,n) for(ll j=p;j<(ll)n;j++)
#define bolt ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define bits(a) __builtin_popcount(a)
#define test ll t;cin>>t;while(t--)
ll zero=0;
ll one=1;
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 expo(ll x, ll y) {ll res=1;x=x%mod;while(y>0){if(y&1)res=(1ll*res*x)%mod;
    y=y>>1;x=(1ll*x*x)%mod;} return res;}
ll ncr(ll n,ll r){ ll res=1; if(r>n-r)r=n-r; for(ll i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime(ll n){ll i;for(i=2;i<=sqrt(n);i++){if(n%i==0)return false;}return true;}
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return(a.second<=b.second);}

//https://www.youtube.com/watch?v=k4V3Mo61fJM

ll rr[]={0,1,1,1,0,-1,-1,-1,};
ll cc[]={1,1,0,-1,-1,-1,0,1};

ll fun(ll n)
{
    if(n==1) return 1;
    return (2*fun(n/2) + 1);
}

signed main()
{
    bolt;
    ll n;cin>>n;
    cout<<fun(n);
    return 0;
}


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

//49 
typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<ll> a(n + 1);
	vector<ll> b(n);
	//vector<ll> val(n);
	for (int i = 0; i < n + 1; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
	}
	//sort(val.rbegin(),val.rend());
	//sort(b.rbegin(),b.rend());
	ll ans = 0;
    for (int i = 0; i < n; ++i) {
		if (a[i] <= b[i]) {
			ans += a[i];
			if (i + 1 <= n) {
				ans += min(b[i] - a[i],a[i + 1]);
				a[i + 1] -= b[i] - a[i];
				if (a[i + 1] < 0) {
					a[i + 1] = 0;
				}
			}
		}else {
			ans += b[i];
		}
	}
	//for (int i = 0; i < n; ++i) {
		//ans += 1LL * min(val[i],b[i]);
	    //if (i + 1 < n) val[i + 1] -=  (min(val[i],b[i]) - min(a[i],b[i]));
	//}
	cout << ans;
}


Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double inf = 1e20;
const double pi = acos(-1.0);
const int maxp = 1010;
int sgn(double x) {
    if(fabs(x) < eps) return 0;
    if(x < 0) return -1;
    return 1;
}
inline double sqr(double x) {return x*x;}
struct Point {
    double x,y;
    Point() {}
    Point(double _x,double _y) {
        x = _x;
        y = _y;
    }
    void input() {
        scanf("%lf%lf",&x,&y);
    }
    void output() {
        printf("%.2f %.2f\n",x,y);
    }
    bool operator == (Point b)const {
        return sgn(x-b.x) == 0 && sgn(y-b.y) == 0;
    }
    bool operator < (Point b)const {
        return sgn(x-b.x) == 0 ? sgn(y-b.y)<0 : sgn(x-b.x)<0;
    }
    Point operator - (const Point &b)const {
        return Point(x-b.x,y-b.y);
    }
    //　叉积
    double operator ^ (const Point &b)const {
        return x*b.y - y*b.x;
    }
    //　点积
    double operator * (const Point &b)const {
        return x*b.x + y*b.y;
    }
    // 返回长度
    double len() {
        return hypot(x,y); // 库函数
    }
    // 
    double len2() {
        return x*x + y*y;
    }
    double distance(Point p) {
        return hypot(x-p.x,y-p.y);
    }
    Point operator + (const Point &b)const {
        return Point(x+b.x,y+b.y);
    }
    Point operator * (const double &k)const {
        return Point(x*k,y*k);
    }
    Point operator / (const double &k)const {
        return Point(x/k,y/k);
    }
    // 计算 pa 和 pb 的夹角
    // 测试LightOJ1203
    double rad(Point a,Point b) {
        Point p = *this;
        return fabs(atan2(fabs((a-p)^(b-p)),(a-p)*(b-p)));
    }
    // 化为长度为r的向量
    Point trunc(double r) {
        double l = len();
        if(!sgn(l)) return *this;
        r /= l;
        return Point(x*r,y*r);
    }
    // 逆时针旋转90度(绕原点)
    Point rotleft() {
        return Point(-y,x);
    }
    // 顺时针旋转90度(绕原点)
    Point rotright() {
        return Point(y,-x);
    }
    // 绕着p点逆时针旋转angle
    Point rotate(Point p,double angle) {
        Point v = (*this) - p;
        double c = cos(angle),s = sin(angle);
        return Point(p.x + v.x*c - v.y*s,p.y+v.x*s + v.y*c);
    }
};
int main()
{
    int x1,x2,y1,y2,x3,x4,y3,y4;
    while(~scanf("%d%d%d%d",&x1,&y1,&x2,&y2)){
        Point a(x1,y1),b(x2,y2);
        Point c = a.rotate(b,pi+pi/2);
        Point d = b.rotate(a,pi/2);
        printf("%.0f %.0f %.0f %.0f\n",c.x,c.y,d.x,d.y);
    }  
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INT long long
#define oo 1987654321
using namespace std;
INT n, m, w[100010], grp[100010], p = 0, ans;
priority_queue<INT> val[100010];
vector<INT> G[100010], V;
void dfs(INT x, INT y)
{
    grp[x] = y;
    for(INT v : G[x])
        if( !grp[v] )
            dfs(v, y);
}
void put(INT x, INT y){ val[x].push(-y); }
INT get(INT x){ INT ret = -val[x].top(); val[x].pop(); return ret; }
INT top(INT x){ return -val[x].top(); }
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0 ; i < n ; i++ ) cin>>w[i];
    for(int i = 0 ; i < m ; i++ )
    {
        int a, b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 0 ; i < n ; i++ )
    {
        if( grp[i] == 0 )
        {
            p = p + 1;
            dfs(i, p);
        }
    }
    for(int i = 0 ; i < n ; i++ ) put(grp[i], w[i]);
    if( p > 1 )
    {
        for(int i = 1 ; i <= p ; i++ ) ans += get(i);
        for(int i = 1 ; i <= p ; i++ )
            while( val[i].size() > 0 ) V.push_back(get(i));
        sort(V.begin(), V.end());
        if( V.size() < p-2 ) return cout<<"Impossible\n", 0;
        for(int i = 0 ; i < p-2 ; i++ ) ans += V[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 13304
#!/usr/bin/env python3


def point(vs, skip_n):
    vs = sorted(vs)
    total = 0
    for v in vs:
        if v < 0 and skip_n > 0:
            skip_n -= 1
        else:
            total += v
    return total


def solv(n, k, vs):
    rvs = list(reversed(vs))
    max_take = min(k, n)
    max_val = 0
    for take in range(1, max_take+1):
        for l in range(take+1):
            r = take - l
            vs1 = vs[:l] + rvs[:r]
            max_val = max(point(vs1, k-take), max_val)
    return max_val


if __name__ == '__main__':

    n, k = map(int, input().split())

    vs = list(map(int, input().split()))

    ans = solv(n, k, vs)
    print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;

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

int main () {
  int a, b, t;
  cin>>a>>b>>t;
  cout<<t/a*b;
  return 0;
}


Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    P = {tuple(map(int, input().split())) for _ in range(M)}
    P = sorted(P)
    ans = [0 for _ in range(N)]

    if N == 1 and M == 0:
        print(0)
        return

    if N == 2 and M == 0:
        print(10)
        return

    if N == 3 and M == 0:
        print(100)
        return

    if N > 1 and (1, 0) in P:
        print(-1)
        return

    if N > 1 and P[0][0] != 1:
        ans[0] = 1

    for i in range(len(P) - 1):
        if P[i][0] == P[i + 1][0]:
            print(-1)
            return

    for p in P:
        ans[p[0] - 1] = p[1]

    print("".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <algorithm>    
#include <vector>       
#include <set>
#include <utility>  
#include <cstring>
#include <stdio.h>
#include <limits.h>
#include <queue>
#include <algorithm> 
#define MAX_DOUBLE  40000000000.0 
#include <math.h> 
#include <unistd.h>

using namespace std;

int max(int a, int b){
	if(a > b) return a;
	return b;
}


double res[3010][3010];
double p[3010];



int main(){
	
	int n;
	cin>>n;
	
	for(int i = 0; i<n; i++){
		double a;
		cin>>a;
		p[i] = a;
	}
	
	res[0][0] = 1.0 - p[0];
	res[0][1] = p[0];
	
	for(int i = 1; i < n; i++){
		for(int j = 0; j <= i; j++){
			res[i][j] += res[i-1][j] * (1.0 - p[i]);
		}
		for(int j = 1; j <= i+1; j++){
			res[i][j] += res[i-1][j-1] * (p[i]);
		}
	}
	
	double ans = 0;
	for(int i = n; i > n/2; i--){
		ans += res[n-1][i];
	}
	cout.precision(17);
	cout<<ans;
}


Measured memory_bytes: 69120
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  cin>>n>>x;
  if(x==1||x==2*n-1)cout<<"No"<<endl;
  else{
    cout<<"Yes"<<endl;
    int c=0;
    for(int i=1;i<=2*n-1;i++){
      if(x!=i&&x-1!=i&&x+1!=i)cout<<i<<endl,c++;
      if(c==n-2){
	cout<<x-1<<endl<<x<<endl<<x+1<<endl;
	c++;
      }
    }
  }
  return 0;
}


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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}


int main() {
  lint a,b,c; cin >> a >> b >> c;

  if(c-a-b > 0 && (c-a-b)*(c-a-b) > 4*a*b) { cout << "Yes\n"; }
  else { cout << "No\n"; }
  return 0;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
V = list(map(int, input().split()))

V.sort(reverse=True)

mean = sum(V[:A]) / A
mean = float(mean)

print(mean)


def fact(n):
    if n == 0 or n == 1: return 1
    return fact(n-1) * n

def comb(n,a):
    return fact(n)//fact(a)//fact(n-a)

from collections import Counter
c = Counter(V)
n = c[V[0]]


if V[0] != V[A-1]:
    n = c[V[A-1]]
    if n > 1:
        idx = V.index(V[A-1]) 
        _A = A - idx
        print( comb( n, _A ) )
    else:
        print(1); exit()

if V[0] == V[A-1]:
    ans = 0
    for i in range(A, min(n+1, B+1)):
        ans += comb(n, i)

    print( ans )

Measured memory_bytes: 45808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define itn int
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6+1;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

void solve()
{
    vi p(MAXN);
    p[1]=1;
    for (int i=2;i<MAXN;i++)
    {
        if (p[i])
            continue;
        p[i]=i;
        for (ll j=1ll*i*i;j<MAXN;j+=i)
        {
            if (p[j])
                p[j]=min(p[j],i);
            else
                p[j]=i;
        }
    }
    vector <int> cnt(MAXN);
    int n;
    cin>>n;
    vector <int> a(n);
    rep(i,n)
    {
        cin>>a[i];
        int x=a[i];
        while (x>1)
        {
            int y=p[x];
            while (x%y==0)
                cnt[y]++,x/=y;
        }
    }
    bool ok=true;
    for (int i=0;i<n;i++)
    {
        if (!ok)
            break;
        int x=a[i];
        while (x>1)
        {
            int chet=0;
            int y=p[x];
            while (x%y==0)
                chet++,x/=y;
            if (cnt[y]>chet)
            {
                ok=false;
                break;
            }
        }
    }
    if (ok)
    {
        cout<<"pairwise coprime\n";
        return;
    }
    int x=0;
    for (int i=0;i<n;i++)
        x=__gcd(x,a[i]);
    if (x==1)
        cout<<"setwise coprime\n";
    else
        cout<<"not coprime\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef Mip182
    freopen("a.in","r",stdin);
    #endif
    int _t;
//    cin>>_t;
    _t=1;
    while (_t--)
        solve();
    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 15040
import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

n, m = nl()
cond = [nl() for _ in range(m)]
ans = -1

def check(i, s, c):
    i //= (10 ** (n-s))
    i %= 10
    return i == c

for i in range(1000):
    if i == 0 and n == 1:
        if all([check(i, s, c) for s, c in cond]):
            ans = i
            break

    if 10 ** (n-1) <= i < 10 ** n:
        if all([check(i, s, c) for s, c in cond]):
            ans = i
            break

print(ans)       

Measured memory_bytes: 39664
import java.util.*;

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

        int ans = 0;
        if (a < b && b-a-w > 0) {
            ans = b-a-w;
        } else if (a > b && a-b-w > 0) {
            ans = a-b-w;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

const ll inf  = 1e18;

int main(){
    int n,k;
    while(cin>>n>>k){
        vi a(n);
        vl dp(n, inf);
        forn(i,n) cin>>a[i];

        dp[0] = 0;
        forn(i,n){
            fore(j,1,k+1){
                if(i+j<n)
                    min_self(dp[i+j], dp[i] + abs(a[i] - a[i+j]));
            }
        }
        // print(dp);
        cout<<dp[n-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int c[1000006];
vector<int> V;
set<int> S;
multiset<int> T;

int N, A[200005];

int dp[200005];

int main(void) {
	cin >> N;
	int Am = 0;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		V.push_back(A[i]);
		//S.insert(A[i]);
		//T.insert(A[i]);
		Am = max(Am, A[i]);
	}

	//sort(V.begin(), V.end());

	

	for(auto y: V){
		if (c[y] >= 1) { c[y] = 2; }
		else if (c[y] >= 0) { c[y]++;
		for (long long int j = y*2; j <= Am; j+=y) {
			c[(int) j] = -1;
		}
		}
	}


	int ans = 0;

	for (int i = 1; i <= N; i++) {
		//if (T.count(A[i]) >= 2) { continue; }
		if (c[A[i]] == 1) { ans++; }
	}

	cout << ans << endl;

	return 0;
}

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

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

int MOD=1e9+7;
ll INF=1e18;

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

ll factorial[300000];

ll mod_pow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = mod_pow(a, b/2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * mod_pow(a, b-1)) % MOD;
    }
}

void calc(){
    factorial[0]=1;
    for(int i=1; i<=250000; i++){
        factorial[i] = factorial[i-1]*i;
        factorial[i] %= MOD;
    }
}

int main(){
    int h, w; cin>>h>>w;
    int a, b; cin>>a>>b;

    calc();

    ll sum=0;
    for(int i=0; i<h-a; i++){
        ll ans=1;
        ans *= factorial[i+b-1];
        ans %= MOD;
        ans *= mod_pow(factorial[i], MOD-2);
        ans %= MOD;
        ans *= mod_pow(factorial[b-1], MOD-2);
        ans %= MOD;
        ans *= factorial[h-i+w-b-2];
        ans %= MOD;
        ans *= mod_pow(factorial[w-b-1], MOD-2);
        ans %= MOD;
        ans *= mod_pow(factorial[h-i-1], MOD-2);
        ans %= MOD;
        sum += ans;
        sum %= MOD;
    }
    cout << sum << endl;
}

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

int main() {
 ll x, k, d;
 cin >> x >> k >> d;
  x = abs(x);
 ll ans;
 ll a = x/d;
  if( a > k ) ans = x - k*d;
  else{ if( k%2 == a%2 ) ans = x%d;
        else ans = d - x%d;
      }
  
  cout << ans << endl;
  
      return 0;
}


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

int main() {
  // keyence
   string s;
   cin >> s ;
   int n = s.size();
   
   if (n<=6) cout << "NO"<< endl;
   else {
      for(int i=1;i<=7;i++){
	  		if(s.substr(0,i)+s.substr(n-(7-i),7-i)=="keyence"){
			  cout << "YES" << endl;
			  return 0;
			}  
			
	  }
	  cout << "NO" <<endl;
   }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;


int main() {
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    vector<int> c(n,0);
    rep(i,n){
        c[b[i]-1]=1;
    }
    bool t=true;
    rep(i,n){
        if (c[i]==0) t=false;
    }
    if (t){
        cout << "Yes" << endl;
        return 0;
    }
    vector<int> u(n),y(n);
    cout << "No" << endl;
    rep(i,n){
        if (c[a[i]-1]==1){
            u[i]=1;
            y[i]=1;
        }
        else{
            u[i]=1;
            y[i]=2;
        }
    }
    rep(i,n-1) cout << u[i] << " ";
    cout << u[n-1] << endl;
    rep(i,n-1) cout << y[i] << " ";
    cout << y[n-1] << endl;
}



Measured memory_bytes: 4640
package main

import (
	"fmt"
)

func main() {
	var N int
	var K int
	var X int
	var Y int

	fmt.Scan(&N, &K, &X, &Y)

	if N > K {
		fmt.Println(X*K + Y*(N-K))
	} else {
		fmt.Println(X * N)
	}

}


Measured memory_bytes: 1768
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
const long long MAX = 1e9;


int main(){
    int n, k;
    cin >> n >> k;
    --k;
    vector<long long> v;
    long long h;
    rep(i,n){
        cin >> h; v.push_back(h);
    }
    sort(v.begin(),v.end());
    long long res = MAX;
    rep(i,n-k){
        long long delta = v[i+k]-v[i];
        if (delta < res) res = delta;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1400
#include <algorithm>
#include <cstdio>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;

int main() {
    // input
    int n, m; scanf("%d%d", &n, &m);
    vector<int> a(n); repeat (i, n) scanf("%d", &a[i]);
    // solve
    ll total = 0;
    vector<ll> imos0(2 * m);
    vector<ll> imos1(2 * m);
    repeat (i, n - 1) {
        int l = a[i] - 1;
        int r = a[i + 1] - 1;
        if (r < l) r += m; // [l, r] on [0, 2n)
        total += r - l;
        if (r - l <= 1) continue;
        imos0[l + 2] += 1;
        imos0[r + 1] -= 1;
        imos1[r + 1] -= (r + 1) - (l + 2);
    }
    imos1[0] += imos0[0];
    repeat (i, 2 * m - 1) {
        imos0[i + 1] += imos0[i];
        imos1[i + 1] += imos1[i] + imos0[i + 1];
    }
    vector<ll> reward(m);
    repeat (i, m) reward[i] = imos1[i] + imos1[i + m];
    ll result = total - *whole(max_element, reward);
    // output
    printf("%lld\n", result);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a, cnt_rate[9] = {};
  for (int i=0; i<N; i++) {
    cin >> a;
    cnt_rate[min(a/400, 8)]++;
  }
  int cnt_color = 0;
  for (int i=0; i<8; i++) {
    if (cnt_rate[i]>0)
      cnt_color++;
  }
  cout << max(1, cnt_color) << ' ' << cnt_color+cnt_rate[8] << endl;
  return 0;
}

Measured memory_bytes: 256
#import"bits/stdc++.h"
#define r(n) for(i=0;i<n;i++)
using namespace std;main(int N){cin>>N;int A[2*N],c[N+1]={},n,t,i;r(2*N)cin>>A[i];r(2*N)c[A[i]]++;if(*max_element(c,c+N+1)>N)cout<<"No";else{cout<<"Yes ";queue<int> s;r(N)if(A[i]==A[N+i])s.push(i);while(s.size()){n=s.front(),t=N+rand()%N;s.pop();if(A[n]!=A[t]&A[t-N]!=A[n+N])swap(A[n+N],A[t]);else s.push(n);}r(N)cout<<A[i+N]<<" ";}}

Measured memory_bytes: 6768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cout<<#x<<" = "<<(x)<<endl;

int main(){
  cout<<fixed<<setprecision(10);
  double A,B;
  double H,M;
  cin>>A>>B>>H>>M;
  double h, m;
  
  m=2*M_PI*M/60;
  //分針
  //じしんようにHを変換
  H += M/60;
  h = 2*M_PI*H/12;
  double theta = min(abs(h-m), 2*M_PI-abs(h-m));

  //debug(theta);

  double c = A*A + B*B - 2*A*B*cos(theta);
  //debug(cos(theta));
  c = sqrt(c);

  cout<<c<<endl;
}

Measured memory_bytes: 4228
fn read_spc<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
 
fn main() {
    flip();
}
 
fn flip() {
    let nm: Vec<i64> = read_spc();
    let n = nm[0];
    let m = nm[1];
    let mn = n * m;
    let mut ans = match mn {
        1 => 1,
        2 => 1,
        _ => (n - 2) * (m - 2)
    };
    if ans < 0 {
        ans = -ans;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, m, q, l, r, dp[505][505], res[505][505];

signed main() {
	cin >> n >> m >> q;
	rep(i,m) {
		cin >> l >> r;
		dp[l][r]++;
	}
	rep(i,501) rep(j,501) dp[i][j+1] += dp[i][j];
	rep(j,501) for(int i=500; i>0; --i) dp[i-1][j] += dp[i][j];
	while (q--) {
		cin >> l >> r;
		cout << dp[l][r] << ln;
	}
}

Measured memory_bytes: 1920
import sys
import itertools
input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]

    
def main():
    X = int(input())
    N = [True] * 110000
    N[0] = False
    N[1] = False  

    n = 2
    while n < X:
        if N[n]:
            for s in range(1, 110000 // n):
                N[n * s] = False
            n += 1
            continue
        else:
            n += 1


    while not N[n]:
        n += 1
    
    print(n)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3956
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

////////// Union-Find木 //////////

struct UnionFind{
  vector<int> par,siz;						//par[i]:iの親の番号
  UnionFind(int N):par(N),siz(N,1ll){		//最初は全てが根であるとして初期化
    for(int i=0; i<N; i++) par[i]=i;
  }
  
  int root(int x){						//データxが属する木の根
    if(par[x]==x) return x;
    return par[x]=root(par[x]);
  }
  
  void unite(int x,int y){				//xとyの木を併合
    int rx=root(x);
    int ry=root(y);
    if(rx==ry) return;
    if(siz[rx]<siz[ry]) swap(rx,ry);
    siz[rx]+=siz[ry];
    par[ry]=rx;
  }
  
  bool same(int x,int y){				//x,yが属する木が同じならtrueを返す
    int rx=root(x);
    int ry=root(y);
    return rx==ry;
  }
  
  int size(int x){
    return siz[root(x)];
  }
};

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

int main(){
  ll N,M,ans=0;
  cin>>N>>M;
  ll P[N],POS[N],X[M],Y[M];
  REP(i,N) cin>>P[i],P[i]--,POS[P[i]]=i;
  
  UnionFind U(N);
  REP(i,M){
    cin>>X[i]>>Y[i],X[i]--,Y[i]--;
    U.unite(X[i],Y[i]);
  }
  
  REP(i,N){
    if(U.root(i)==U.root(POS[i])) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 7120
N=int(input())
S=list(input())
nsums=[0]*N

right =0
for s in S:
  if s=='E':right+=1

left =0
min_sum=N
for i in range(N):
  if S[i] == 'E':right-=1
  nsums[i] = right + left
  if S[i]=='W':left+=1

  min_sum = min(min_sum,nsums[i])
print(min_sum)

Measured memory_bytes: 17524
#include<bits/stdc++.h>
using namespace std;
inline int read () {
	int num = 0;
	char c = ' ';
	bool flag = true;
	for (;c > '9' || c < '0';c = getchar())
		if (c == '-')
			flag = false;
	for (;c >= '0' && c <= '9';num = (num << 1) + (num << 3) + c - 48, c = getchar());
	return flag ? num : -num;
}
namespace INIT {
	const int maxn = 200200;
	int n, a[maxn];
	void init () {
		n = read ();
		for (int i = 1;i <= n;i ++)
			a[i] = read ();
	}
} using namespace INIT;
struct node {
	int num, val;
} c1[maxn], c2[maxn];
int which[maxn],cnt1 = 0, cnt2 = 0;
void work1 () {
	memset (which, 0, sizeof which);
	for (int i = 1;i <= n;i += 2) {
		if (which[a[i]] == 0) {
			which[a[i]] = ++ cnt1;
			c1[cnt1].num = a[i];
		}
		c1[which[a[i]]].val ++;
	}
}
void work2 () {
	memset (which, 0, sizeof which);
	for (int i = 2;i <= n;i += 2) {
		if (which[a[i]] == 0) {
			which[a[i]] = ++ cnt2;
			c2[cnt2].num = a[i];
		}
		c2[which[a[i]]].val ++;
	}
}
node a1,a2,b1,b2;
void find () {
	for (int i = 1;i <= cnt1;i ++) {
		if (c1[i].val > a1.val) {
			a2 = a1;
			a1 = c1[i];
		}
		else if (c1[i].val > a2.val)
			a2 = c1[i];
	}
	for (int i = 1;i <= cnt2;i ++) {
		if (c2[i].val > b1.val) {
			b2 = b1;
			b1 = c2[i];
		}
		else if (c2[i].val > b2.val)
			b2 = c2[i];
	}
}
void work () {
	int ans = 0x7fffffff,now;
	if (a1.num != b1.num)
		ans = min (ans,n - a1.val - b1.val);
	if (a1.num != b2.num)
		ans = min (ans,n - a1.val - b2.val);
	if (a2.num != b1.num)
		ans = min (ans,n - a2.val - b1.val);
	cout << ans << endl;
}
int main () {
	init ();
	work1 (); work2 ();
	find (); work ();
	return 0;
}

Measured memory_bytes: 3712
N, M = map(int, input().split())
H = list(map(int, input().split()))
links = [list(map(int, input().split())) for _ in range(M)]
survivors = [True for _ in range(N)]

for a, b in links:
  if H[a-1] <= H[b-1]:
    survivors[a-1] = False
  if H[b-1] <= H[a-1]:
    survivors[b-1] = False

print(sum(survivors))
    

Measured memory_bytes: 101452
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String line = scanner.nextLine().trim();
    String[] fields = line.split("/");
    if (10000 * Integer.parseInt(fields[0]) + 100 * Integer.parseInt(fields[1]) + Integer.parseInt(fields[2]) <= 20190430) {
      System.out.println("Heisei");
    } else {
      System.out.println("TBD");
    }
  }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int a,b,c,d;
int main(){
	a=read();b=read();c=read();d=read();
	b=(c-1)/b+1;d=(a-1)/d+1;
	if(b<=d)puts("Yes");
	else puts("No");
}


Measured memory_bytes: 3604
N = int(input())
dp = [[0]*N for _ in range(2)]
for i in range(2):
  a = list(map(int,input().split()))
  if i == 0:
    dp[0][0]= a[0]
    for j in range(1,N):
      dp[0][j] = dp[0][j-1]+a[j]
  else:
    dp[1][0] = dp[0][0]+a[0]
    for j in range(1,N):
      if dp[1][j-1] > dp[0][j]:
        dp[1][j] = dp[1][j-1]+a[j]
      else:
        dp[1][j] = dp[0][j]+a[j]
#print(dp)
print(dp[1][-1])

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		sc.close();
		char[] array = s.toCharArray();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < array.length; i++) {
			if (i % 2 == 0) {
				sb.append(array[i]);
			}
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 25224
#include<stdio.h>
#include<math.h>

int count = 0;

void merge(int A[],int left,int mid,int right){
  int n1 = mid - left,n2 = right - mid;
  int L[n1],R[n2];
  int i,j,k;

  for(i = 0;i <= n1-1;i++)L[i] = A[left + i];
  for(i = 0;i <= n2-1;i++)R[i] = A[mid + i];

  L[n1] = 1000000000;
  R[n2] = 1000000000;
  i = 0;j = 0;

  for(k=left;k<=right-1;k++){
    if(L[i]<=R[j]){
      A[k] = L[i];
      i++;
    }
    else{
      A[k] = R[j];
      j++;
    }
    count++;
  }
}
void mergeSort(int A[],int left,int right){
  if(left+1<right){
    int mid = (left + right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(){
  int n,S[1000000],i;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&S[i]);

  mergeSort(S,0,n);

  for(i=0;i<n-1;i++)printf("%d ",S[i]);
  printf("%d\n",S[i]);
  printf("%d\n",count);

  return 0;
}

	



Measured memory_bytes: 5764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
int main()
{
	int a=read(),b=read();
	if(a>=13)
		cout<<b<<endl;
	else if(a<=5)
		puts("0");
	else
		cout<<(b>>1)<<endl;
	return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    int ans = 0;
    int count = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            count++;
        } else {
            count = 0;
        }
        ans = max(count, ans);
    }

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

Measured memory_bytes: 256
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n;
    //vector<vector<ll>> v(tate,vector<ll> (yoko));
    vector<ll> v(n);
    rep(i,n)   cin >> v[i];
    rep(i,n-1){
        if(v[i]<v[i+1]) v[i+1]=v[i+1]-1;
        else if(v[i]>v[i+1]) {
            No;
            return 0;
        }
    }
    Yes;
    return 0;
}


Measured memory_bytes: 1024
# solution

x,y,z,k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse = True)
b = sorted(list(map(int, input().split())), reverse = True)
c = sorted(list(map(int, input().split())), reverse = True)
ans = []
for p in range(min(k,len(a))):
  for q in range(min(k,len(b))):
    for r in range(min(k,len(c))):
      if((p+1)*(q+1)*(r+1) > k):
        break
      ans.append(a[p] + b[q] + c[r])
      
ans = sorted(ans, reverse = True)
for i in range(k):
  print(ans[i])

Measured memory_bytes: 9676
s = input()

ans = True

if s[0] != 'A':
  ans = False
  
cnt = 0
for i in range(2, len(s) - 1):
  if s[i] == 'C':
    cnt += 1
    
if cnt != 1:
  ans = False
  
cnt = 0
for c in s:
  if c.isupper():
    cnt += 1
    
if cnt != 2:
  ans = False
  
if ans:
  print("AC")
else:
  print("WA")

Measured memory_bytes: 3064