akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ACはうれCすぎてうれD */

int main(void){ 
    int n;
    cin >> n;
    vector<int> p;
    for(int i=0; i<n; i++){
        int tmp_p;
        cin >> tmp_p;
        p.push_back(tmp_p);
    }
    sort(p.begin(), p.end());
    int ans = 0;
    ans += p[n-1]/2;
    for(int i=0; i<n-1; i++){
        ans += p[i];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
int F[1005][500];
void Fib()
{
	int i,j;
	mem(F);
	F[0][0]=2;
	F[1][0]=1;
	for(i=2;i<1005;i++)
	{
		for(j=0;j<500;j++)
		F[i][j]=F[i-1][j]+F[i-2][j];
		for(j=0;j<500;j++)
		{
			if(F[i][j]>9)
			{
				F[i][j+1]+=F[i][j]/10;
				F[i][j]=F[i][j]%10;
			}
		}
	}
}
int main()
{
	int i,j,flag,N,n;
	Fib();
	
		scanf("%d",&n);
		flag=0;
		for(j=499;j>=0;j--)
		{
			if(flag==1||F[n][j])
			{
				flag=1;
				printf("%d",F[n][j]);
			}
		}
		printf("\n");
	 return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    ll n;
    cin >> n;
    ll cnt=0;
    rep(i,100000) {
        cnt=i;
        if (i*(i+1)/2>=n) break;
    }
    ll d=cnt*(cnt+1)/2-n;
    repr(i,1,cnt+1) {
        if (i!=d) cout << i << endl;
    }
    
    return 0;   
}

Measured memory_bytes: 3532
N, D = map(int, input().split())
D **= 2
A = []
for _ in range(N):
    A.append(tuple(map(int, input().split())))
count = 0

for p in A:
    if p[0] ** 2 + p[1] ** 2 <= D:
        count += 1

print(count)

Measured memory_bytes: 36036
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc117/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    rep(i, m){
        cin >> x[i];
    }
    if(n >= m){
        cout << 0 << "\n";
        return 0;
    }

    sort(x.begin(), x.end());
    
    vector<int> dist(m - 1);
    rep(i, m - 1){
        dist[i] = x[i + 1] - x[i];
    }
    sort(dist.begin(), dist.end());

    ll ans = 0;
    rep(i, m - n){
        ans += dist[i];
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include<cstring>
#include<cstdio>
#include<queue>
#define Re register int
using namespace std;
const int N=1e5+5,M=2e5+5,inf=2e9;
int x,y,z,n,m,o,K,to,st,dis[N],pan[N],head[N];
struct QAQ{int w,to,next;}a[M];
struct QWQ{int x,d;inline bool operator<(QWQ O)const{return d>O.d;}};
priority_queue<QWQ>Q;
inline void in(Re &x){
	Re fu=0;x=0;char ch=getchar();
	while(ch<'0'||ch>'9')fu|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	x=fu?-x:x;
}
inline void add(Re x,Re y,Re z){a[++o].to=y,a[o].w=z,a[o].next=head[x],head[x]=o;}
inline void dijkstra(Re st){
	for(Re i=0;i<K;++i)dis[i]=inf;
	dis[st]=1,Q.push((QWQ){st,0});
	while(!Q.empty()){
		x=Q.top().x,Q.pop();
		if(pan[x])continue;
		pan[x]=1;
		for(Re i=head[x];i;i=a[i].next)
			if(dis[to=a[i].to]>dis[x]+a[i].w){
				dis[to]=dis[x]+a[i].w;
				Q.push((QWQ){to,dis[to]});
			}
	}
}
int main(){
	in(K);
	for(Re i=0;i<K;++i)add(i,(i+1)%K,1),add(i,(i*10)%K,0);
	dijkstra(1),printf("%d\n",dis[0]);
}

Measured memory_bytes: 4348
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        if [k[j:j+m] for k in a[i:i+m]] == b: print('Yes'); exit()
            
print('No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

template<class T>
struct Edge{
	int from,to;
	T cost;
	Edge(int to,T cost) : to(to),cost(cost){}
	Edge(int from,int to,T cost) : from(from),to(to),cost(cost){}
};

template<class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using Graph = vector<vector<int>>;
template<class T>
using Matrix = vector<vector<T>>;

template<class T>
void warshallFloyd(Matrix<T> &G){
	for(int k = 0;k < G.size();k++){
		for(int i = 0;i < G.size();i++){
			for(int j = 0;j < G.size();j++){
				if(G[i][k] == INF || G[k][j] == INF) continue;
				G[i][j] = min(G[i][j],G[i][k] + G[k][j]);
			}
		}
	}
}

signed main(){
	int n,m,l;
	cin >> n >> m >> l;
	Matrix<int> G(n,vector<int>(n,INF)),G2 = G;
	for(int i = 0;i < m;i++){
		int a,b,c;
		cin >> a >> b >> c; a--;b--;
		chmin(G[a][b],c);
		chmin(G[b][a],c);
	}
	warshallFloyd(G);
	for(int i = 0;i < n;i++){
		for(int j = i + 1;j < n;j++){
			if(G[i][j] <= l){
				chmin(G2[i][j],1ll);
				chmin(G2[j][i],1ll);
			}
		}
	}
	warshallFloyd(G2);
	int q;
	cin >> q;
	for(int i = 0;i < q;i++){
		int s,t;
		cin >> s >> t; s--;t--;
		if(G2[s][t] != INF) cout << G2[s][t] - 1 << endl;
		else cout << -1 << endl;
	}
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct prim {
  const int n;
  vector<vector<pair<T, int>>> grh;
  T weight_of_mst;
  prim (
      vector<vector<pair<T, int>>> grh
    ) :
    n(grh.size()),
    grh(grh),
    weight_of_mst(0)
    {
      vector<bool> ckd(n, false);
      priority_queue<
        pair<T, int>,
        vector<pair<T, int>>,
        greater<pair<T, int>>
      > que;
      que.emplace(0, 0);
      while (!que.empty()) {
        T w; int t;
        tie(w, t) = que.top(), que.pop();
        if (ckd[t]) continue;
        weight_of_mst += w, ckd[t] = true;
        for (auto p : grh[t]) que.push(p);
      }
    }
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> grh(n);
  for (int i = 0; i < m; i++) {
    int s, t, w;
    cin >> s >> t >> w;
    grh[s].emplace_back(w, t);
    grh[t].emplace_back(w, s);
  }
  cout << prim<int>(grh).weight_of_mst << endl;
  return 0;
}


Measured memory_bytes: 11396
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
  int f[10], ans;
  char buf[20];

  memset(f, 0, sizeof(int)*10);
  f[0] = 1;
  for (int i=1; i<10; i++) {
    for (int j=i; j; j--) {
      f[j] = f[j] + f[j-1];
    }
  }
  for (int i=0; i<10; i++) f[i]%=10;
  while (fgets(buf, sizeof(buf), stdin)) {
    ans = 0;
    for (int i=0; i<10; i++) {
      ans += (buf[i]-'0') * f[i];
    }
    ans %= 10;
    printf("%d\n", ans);
  }

  return 0;
}

Measured memory_bytes: 944
#include <bits/stdc++.h>
#define N 20
#define ll long long
#define lson l,mid,o<<1
#define rson mid+1,r,o<<1|1
#define Ls(o) t[o].ls
#define Rs(o) t[o].rs
#define For(i,x,y) for(int i=(x);i<=(y);++i)
#define Rof(i,x,y) for(int i=(x);i>=(y);--i)
#define Edge(x) for(int i=head[x];i;i=e[i].nxt)
#define mcpy(x,y) memcpy(x,y,sizeof(x))
#define mset(x,y) memset(x,y,sizeof(x))
using namespace std;
int ans=1e9,t,n,m,fa[N],a[N][N],_;
vector<int> g[N];
bool vis[N],use[N*N],p[N][N];
struct ed{ int u,v,w; }e[N*N],tmp[N*N];
void dfs(int x,int f){
    fa[x]=f;
    for(auto to:g[x]) if(to!=f) dfs(to,x);
}
bool cmp(const ed &x,const ed &y){ return x.w>y.w; }
void dfs2(int rt,int x,int f,int cnt){
    if(cnt<=1 && ~a[x][rt] && !p[x][rt] && !(vis[x] && vis[rt]) && f!=rt) _+=a[x][rt];
    for(auto to:g[x]) if(to!=f) dfs2(rt,to,x,cnt+vis[to]);
}
int find(int x){ return x==fa[x]?x:fa[x]=find(fa[x]); }
int solve(){
    int tot=0;_=0;
    For(i,1,n) fa[i]=i,vis[i]=0;
    For(i,1,n) For(j,1,n) p[i][j]=0;
    For(i,1,m) use[i]=0;
    For(i,1,m){
        int u=find(tmp[i].u),v=find(tmp[i].v);
        if(u==v) continue;
        if(u>v) swap(u,v);fa[v]=u;
        tot+=tmp[i].w,use[i]=1,p[tmp[i].u][tmp[i].v]=p[tmp[i].v][tmp[i].u]=1;
    }
    For(i,1,n) g[i].clear();
    For(i,1,m) if(use[i]) g[tmp[i].u].push_back(tmp[i].v),g[tmp[i].v].push_back(tmp[i].u);
    For(i,1,n) fa[i]=0;
    dfs(1,0);
    for(int i=n;i;i=fa[i]) vis[i]=1;
    For(i,1,n) dfs2(i,i,0,vis[i]);
    tot+=_/2;
    return tot;
}
void Rand(){
    random_shuffle(tmp+1,tmp+m+1);
    ans=max(ans,solve());   
}
int main(){
    int qwq=0,u,v,w;
    srand(20000000);srand(rand());srand(rand());
    scanf("%d%d",&n,&m);
    mset(a,-1);
    For(i,1,m){
        scanf("%d%d%d",&u,&v,&w);
        e[i]=(ed){u,v,w},qwq+=w,a[u][v]=a[v][u]=w;
        tmp[i]=e[i],g[u].push_back(v),g[v].push_back(u);
    }
    sort(e+1,e+m+1,cmp);
    For(i,1,m) tmp[i]=e[i];
    ans=solve();
    For(i,1,500500) Rand();
    printf("%d\n",qwq-ans);
}

Measured memory_bytes: 384
n = int(input())
li = list(map(int, input().split()))
iai = dict()
for i in range(n): 
	if(li[i] + i not in iai):
		iai[li[i] + i] = 1
	else:
		iai[li[i] + i] += 1
ans = 0
for j in range(n):
  if(j - li[j] in iai):
  	ans += iai[j - li[j]]
print(ans)

Measured memory_bytes: 40496
#include <bits/stdc++.h>
#define fastIO ios::sync_with_stdio(NULL); cin.tie(NULL);

using namespace std;
const int N = 1E5+7;
const long long INF = 1E18;

long long f[107][N];
int n,W,V;
long long c[N], w[N];

int main()
{
    fastIO
    cin>>n>>W;
    
    for (int i = 1;i <= n;++i) 
    {
        cin>>w[i]>>c[i];
        V = V + c[i];
    }
    
    for (int i = 0;i < 107;++i)
        for (int j = 0;j <= V;++j) f[i][j] = INF;
    
    for (int i = 0;i <= n;++i) f[i][0] = 0;
    
    int ans = 0;

    for (int i = 1;i <= n; ++i)
        for (int j = 1;j <= V;++j)
        {
            if (c[i] <= j) f[i][j] = min(f[i-1][j], min(f[i-1][j-c[i]]+w[i],f[i][j]));
            else f[i][j] = f[i-1][j];
        }
    
    for (int i = 1;i <= n;++i)
        for (int j = 1;j <= V;++j)
            if (f[i][j] <= W) ans = max(ans,j);

    cout<<ans;
}

Measured memory_bytes: 87188
import sys
sys.setrecursionlimit(2000 * 2)
n = int(input())
a = list(map(int, input().split()))
a = [(i, v) for i, v in enumerate(a)]
a.sort(key=lambda x: x[1], reverse=True)

dp = [[-1] * (m + 1) for m in range(n + 1)]
# m: 何人選んだか, l: 左を選んだ人数
def f(m, l):
    if m == n: return 0
    if dp[m][l] != -1: return dp[m][l]
    r = n - m + l - 1
    i, v = a[m]
    if i >= l: dp[m + 1][l + 1] = f(m + 1, l + 1)
    if i <= r: dp[m + 1][l] = f(m + 1, l)
    return max(dp[m + 1][l + 1] + v * (i - l), dp[m + 1][l] + v * (r - i))
print(f(0, 0))

Measured memory_bytes: 72312
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 


int main()
{
    int A, B;
    cin >> A >> B;

    LL ans = 0;
    ans = ceil((double)(B-1) / (A-1));

    cout << ans << endl;

    return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n; cin >> n;
    vi h(n-1); rep(i,n) cin >> h[i];

    vi dp(112345, inf);
    dp[0] = 0;
    for(int i = 0; i < n; ++i) {
        chmin(dp[i+1], dp[i] + abs(h[i+1]-h[i]));
        chmin(dp[i+2], dp[i] + abs(h[i+2]-h[i]));
    }
    cout << dp[n-1] << '\n';
}

Measured memory_bytes: 1152
tbl = [[0 for j in range(13)] for i in range(4)]
n = int(input())

for k in range(n):
    mark,num = map(str, input().split())
    if mark == 'S': tbl[0][int(num) - 1] = 1
    elif mark == 'H': tbl[1][int(num) - 1] = 1
    elif mark == 'C': tbl[2][int(num) - 1] = 1
    elif mark == 'D': tbl[3][int(num) - 1] = 1
    
for i in range(4):
    for j in range(13):
        if tbl[i][j] == 0:
            if i == 0: print('S', j + 1)
            elif i == 1: print('H', j + 1)
            elif i == 2: print('C', j + 1)
            elif i == 3: print('D', j + 1)


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    string s, t;
    cin >> n >> s >> t;
    for(int i = 0; i < n; i++) cout << s[i] << t[i];

    return 0;
}

Measured memory_bytes: 3608
n, k, c = map(int, input().split())
s = input()
f_list = []
l_list = []

i = 0
while True:
    if s[i] == 'o':
        f_list.append(i)
        if len(f_list) == k:
            break
        i += c + 1
    else:
        i += 1

i = len(s) - 1
while True:
    if s[i] == 'o':
        l_list.append(i)
        if len(l_list) == k:
            break
        i -= c + 1
    else:
        i -= 1

l_list.sort()

for i in range(len(f_list)):
    if f_list[i] == l_list[i]:
        print(f_list[i]+1)


Measured memory_bytes: 20704
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define vvl vector<vector<ll>>
#define vl  vector<ll>
#define rep(i,sta,end) for(ll i=sta;i<end;i++)
//lcm:最小公倍数、gcd:最大公約数
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back 
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
//map<int,int>mp

ll n,l;
//string s;
signed main(){
	acc_io;
	//ll n;
	cin>>n>>l;
	vector<string>s(n);
	rep(i,0,n) cin>>s.at(i);
	sort(all(s));
	string ans=s[0];
	rep(i,1,n) ans+=s[i];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
program prob3
    implicit none
    integer::n, i, j
    integer, allocatable::a(:),b(:)
    read(*,*) n
    allocate(a(n),b(n))
    read(*,*) a

    if(mod(n,2) == 0)then
        do i = n,2,-2
            b(n/2-i/2+1) = a(i)
        end do
        do i = 1, n, 2
            b(n/2+(i+1)/2) = a(i)
        end do
    else
        do i = n, 1, -2
            b(n/2-i/2+1) = a(i)
        end do
        do i = 2, n-1, 2
            b(n/2 + i/2 + 1) = a(i)
        end do
    end if
    write(*,*) b
    stop
end program

Measured memory_bytes: 6088
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class APayToWin {
public:
    const lint INF = 2 * ten(18);
    lint N, D;
    vc<lint> divs = {2, 3, 5}, costs;
    unordered_map<lint, lint> memo;

    lint rec(lint x){
        if(x<0) return -INF;
        if(x==0) return 0;
        if(x==1) return D;
        if(memo.count(x)) return memo[x];
        lint res = INF;
        if(x<INF/D) res = x * D;
        REP(i, 3){
            lint& d = divs[i];
            chmin(res, rec(x/d)+D*(x%d)+costs[i]);
            chmin(res, rec((x+d-1)/d)+D*((d-x%d)%d)+costs[i]);
        }
        return memo[x] = res;
    }

    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int tt;
        in>>tt;
        costs.resize(3);
        while(tt--){
            in>>N>>costs[0]>>costs[1]>>costs[2]>>D;
            out<<rec(N)<<'\n';
            memo.clear();
        }
    }
};


int main() {
	APayToWin solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4132
N, M, Q = map(int, input().split())
num = [[0]*500 for _ in range(500)]

for i in range(M):
  L,R = map(int, input().split())
  num[R-1][L-1] += 1

cum = [[0]*500 for _ in range(500)]
for r in range(500):
  cum[r][r] = num[r][r]
for r in range(1,500):
  for l in range(r-1,-1,-1):
    cum[r][l] = cum[r-1][l]+cum[r][l+1]-cum[r-1][l+1]+num[r][l]
#print(cum)
ans = []
for i in range(Q):
  P,Q = map(int, input().split())
  ans.append(cum[Q-1][P-1])
print(*ans,sep='\n')

Measured memory_bytes: 13992
class Point:
    def __init__(self, x , y):
        self.x = x
        self.y = y
    def __sub__(self, p):
        x_sub = self.x - p.x
        y_sub = self.y - p.y
        return Point(x_sub, y_sub)

class Vector:
    def __init__(self, p):
        self.x = p.x
        self.y = p.y
    def norm(self):
        return (self.x ** 2 + self.y ** 2) ** 0.5

def cross(v1, v2):
    return v1.x * v2.y - v1.y * v2.x

def dot(v1, v2):
    return v1.x * v2.x + v1.y * v2.y

def ccw(p0, p1, p2):
    a = Vector(p1 - p0)
    b = Vector(p2 - p0)
    cross_ab = cross(a, b)
    if cross_ab > 0:
        print("COUNTER_CLOCKWISE")
    elif cross_ab < 0:
        print("CLOCKWISE")
    elif dot(a, b) < 0:
        print("ONLINE_BACK")
    elif a.norm() < b.norm():
        print("ONLINE_FRONT")
    else:
        print("ON_SEGMENT")

import sys

file_input = sys.stdin

x_p0, y_p0, x_p1, y_p1 = map(int, file_input.readline().split())
p0 = Point(x_p0, y_p0)
p1 = Point(x_p1, y_p1)

q = map(int, file_input.readline())

for line in file_input:
    x_p2, y_p2 = map(int, line.split())
    p2 = Point(x_p2, y_p2)
    ccw(p0, p1, p2)

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

ll X, Y;

int main(void) {
  cin >> X >> Y;

  ll n = X, ans = 1;
  while(n * 2 <= Y) {
    n *= 2;
    ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 764
#include<iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

#define LOCAL  1
#define UPLOAD 2

using namespace std;

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;

    for(int i=0;i<S.length() - 1;i++){
        if(S[i] == S[i + 1]){
            cout << "Bad" << endl;
            return 0;
        }
    }    

    cout << "Good" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;


int main(){

    float a,b,c,d,e,f;
    while (scanf("%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f)!=EOF){
        float x,y;
        if (a==0)
            swap(a,d),swap(b,e),swap(c,f);

        float ratio=d/a;

        e-=ratio*b;
        f-=ratio*c;

        y=f/e;
        x=(c-y*b)/a;

        printf("%.3f %.3f\n",x,y);
    }


    return 0;
}


Measured memory_bytes: 2704
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string.h>
using namespace std;
#define maxn 1e6;
int main()
{
	long long n, m;
	long long i, j;
	long long t[110];
	long long x[110];
	long long a[110];
	long long lt, lx;
	long long sum = 0;
	long long *p = &t[0];
	long long temp;
	long long s;
	scanf("%lld", &n);
	for(i = 1; i <= n; i++)
	scanf("%lld", &t[i]);
	scanf("%lld", &m);
	for(i = 1; i <= m; i++)
	scanf("%lld %lld", &x[i], &a[i]);
	for(i = 1; i <= m; i++)
		{
			temp = t[x[i]];
	
			s = *(p + x[i]) = a[i];
		
		
			for(j = 1; j <= n; j++)
				sum = sum + t[j];
				printf("%lld\n", sum);
				sum = 0;
				*(p + x[i]) = temp;
			
		}
		return 0;

}

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

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  int ans=0;
  rep(i,N) cin >> h[i];
  
  rep(i,N-1){
    int temp=0;
    rep(j,N-i-1){
      if(h[i+j] >= h[i+j+1]) temp++;
      else break;
    }
    //cout << temp << endl;
    ans = max(ans,temp);
    if(ans >= N-i-1) break;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

x=I()
sm=0
for i in range(1,10**5):
    sm+=i
    if sm>=x:
        print(i)
        sys.exit()

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int N, D;
	cin >> N >> D;

	int t = 0;
	int ans = 0;
	while(t < N){
		t += 2 * D + 1;
		ans++;
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring>
#include <map>
#include <set>
#define int long long int
using namespace std;
const int MAX = 1000000007;

int dp[4000][4000];

signed main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    
    int n, i, l, r;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    for(l=n-1;l>=0;l--){
        for(r=l;r<n;r++){
            if(l==r)
                dp[l][r]=a[l];
            else
                dp[l][r]=max(a[l] - dp[l+1][r], a[r] - dp[l][r-1]);
        }
    }
    cout<<dp[0][n-1]<<endl;
    
}


Measured memory_bytes: 94208
#include <stdio.h>
int main(){
	int n,k = 1;
	scanf("%d",&n);
	int a[n];
	for (int i = 0;i < n;i++){
		scanf("%d",&a[i]);
	if(a[i] % 2 == 0){
	if ((a[i] % 3 != 0)&&(a[i] % 5 != 0)){
			k = 0;}
	}
	}
	if(k == 1) printf("APPROVED");
	else printf("DENIED");
}
		

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#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 sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
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;}

int main(){
  vector<int> A(5); rep(i,5) cin >> A[i];
  rep(i,5){
    if(A[i]!=i+1)cout << i+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
import sys
input=sys.stdin.readline
while True:
	a=[]
	n,k=map(int,input().split())
	if n==k==0:
		break
	zero=False
	for i in range(k):
		p=int(input())
		if p==0:
			zero=True
			continue
		a.append(p)
	a.sort()
	if zero==False:
		r=a[0]-1
		ans=0
		ans_kari=0
		for i in range(k):
			if a[i]==r+1:
				r=a[i]
				ans_kari+=1
			else:
				ans=max(ans,ans_kari)
				ans_kari=1
				r=a[i]
		print(ans)
	else:
		sa=[]
		for i in range(k-2):
			sa.append(a[i+1]-a[i])
		ans=l=r=0
		for i in range(len(sa)):
			if sa[i]==1:
				r+=1
			elif sa[i]==2:
				l=r
				r=1
			else:
				l=0
				r=1
			ans=max(ans,l+r+1)
		print(ans)



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

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

int main(){
    fast()

    long long N;
	cin >> N;
	
	if(N & 1){
		cout << 0;
		return 0;
	}
	
	N /= 2;
	long long trailing_zero = 0;
	for(long long i = 5; i <= N; i*=5)
		trailing_zero += N / i;
	
	cout << trailing_zero;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
dp = [0]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2, n):
    height = h[i]
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))

print(dp[-1])


Measured memory_bytes: 13800
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 2e9 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

void solve() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int p = 0;
  while(1) {
    if(p) {
      a-=d;
      if(a <= 0) {
        cout << "No\n"; break;
      }
    }
    else {
      c-=b;
      if(c <= 0) {
        cout << "Yes\n"; break;
      }
    }
    p ^= 1;
  }
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif
    int t = 1; //cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }
}    


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

int main() {
	int n,x,t;
	cin>>n>>x>>t;
	if(n%x==0){
	    cout<<(n/x)*t<<endl;
	}else if(x>n){
	    cout<<t<<endl;
	}else{
	    cout<<((n/x)+1)*t<<endl;
	}
	return 0;
}

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

void solver() {
  int n, m;
  cin >> n >> m;

  vector<bool> isAced(n);
  vector<int> nWa(n);
  int nAc = 0;
  int waSum = 0;
  for (int i = 0; i < m; i++) {
    int p;
    string s;
    cin >> p >> s;

    if (!isAced[p - 1]) {
      if (s.compare("AC") == 0) {
        isAced[p - 1] = true;
        nAc++;
        waSum += nWa[p - 1];
      } else {
        nWa[p - 1]++;
      }
    }
  }

  cout << nAc << " " << waSum << "\n";
}

int main() {
  solver();
}


Measured memory_bytes: 640
let (n, a, b) = Scanf.scanf "%d %d %d" (fun a b c -> (a, b, c));;
let hps = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0));;

let rec loop left right =
  if left + 1 >= right then
    right
  else
    let mid = (left + right) / 2 in
    let c = Array.fold_left (fun s e ->
                s + max 0 ((e - mid * b + a - b - 1) / (a - b))
              ) 0 hps
    in
    if c <= mid then loop left mid else loop mid right;;

let () = Printf.printf "%d\n" @@ loop 0 1010101010;;


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

int main(){
    int x,y;
    while(1){
       cin >> x >> y;  
     if(x==0&&y==0)
        break;
     if(x>y){
        cout << y << " "<< x <<endl;
         }
      else{
        cout << x<<" "<< y << endl;
           }
    }
    return 0;
}


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

if a == 0:
	if b == 0:
		print(0)
	elif d > 0:
		print(b * d)
	else:
		print(0)
elif c == 0:
	if d == 0:
		print(0)
	elif b > 0:
		print(d * b)
	else:
		print(0)
elif b == 0:
	if a == 0:
		print(0)
	elif c < 0:
		print(a * c)
	else:
		print(0)
elif d == 0:
	if c == 0:
		print(0)
	elif a < 0:
		print(a * c)
	else:
		print(0)
elif (a > 0 and d > 0) or (b > 0 and c > 0):
	print(b * d)
elif (b < 0 and c < 0) or (a < 0 and d < 0):
	print(a * c)
else:
	print(max([a*c,a*d,b*c,b*d]))



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

namespace cswork
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();

                s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        public static List<long> GeneratePrime(long max)
        {
            long prime;
            double sqrtMax = Math.Sqrt(max);
            var primeList = new List<long>();

            List<long> searchList = new List<long>();
            for (long i = 2; i <= max - 1; i++)
            {
                searchList.Add(i);
            }

            do
            {
                prime = searchList.First();
                primeList.Add(prime);
                searchList.RemoveAll(n => n % prime == 0);
            } while (prime < sqrtMax);

            primeList.AddRange(searchList);

            return primeList;
        }

        void Omame()
        {
            cin = new Scanner();
            long N = cin.nextLong();
            string S = cin.next();
            StringBuilder ans = new StringBuilder();

            for (int i = 0; i < S.Length; i++)
            {
                ans.Append((char)(65 + ((S[i] + N - 65) % 26)));
            }

            Console.WriteLine(ans.ToString());
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 1001
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define REP(i, n) for(int i=0; i<n; i++)
#define RER(i, n) for(int i=n-1; i>=0; i--)
#define ALL(v) v.begin() v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int h, w;
char a[MAX_N][MAX_N];
vector<P> b[2*MAX_N];
int x[4] = {1, -1, 0, 0}, y[4] = {0, 0, 1, -1};


signed main(){
	cin >> h >> w;
	REP(i, h) REP(j, w){
		cin >> a[i][j];
		if(a[i][j] == '#') b[0].pb(P(i, j));
	}
	REP(i, h+w){
		int tmp = 0;	
		for(P e: b[i]){
			int _i = e.first, _j = e.second;
			REP(j, 4){
				if(_i + x[j] >= 0 && _i + x[j] < h && _j + y[j] >= 0 && _j + y[j] < w){
					if(a[_i+x[j]][_j+y[j]] == '.'){
						b[i+1].pb(P(_i+x[j], _j+y[j]));
						a[_i+x[j]][_j+y[j]] = '#';
						tmp++;
					}
				}
			}
		}
		if(tmp == 0){
			cout << i << endl;
			break;
		}
	}
    return 0;
}

Measured memory_bytes: 14696
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<LL,LL> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

vector<pair<LL,LL> > v1,v2;
LL mm[100005];//last part end
LL ma[100005];

int main(){
	LL n,m;
	LL i,j,k;
	LL a,b,c,s;
	cin>>n;
	s=0;
	for(i=0;i<n;i++){
		cin>>a>>b;
		v1.push_back(make_pair(a,b+1));
		v2.push_back(make_pair(-b-1,-a));
		s=max(s,b-a+1);
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	a=-v2[n-1].first-v1[n-1].first;
	if(a>0)s+=a;
	a=(LL)1<<40,b=0;
	for(i=n-1;i>=0;i--){
		if(v1[i].second<a)a=v1[i].second;
		mm[i]=a;
		if(v2[i].second<b)b=v2[i].second;
		ma[i]=b;
	}
	a=(LL)1<<40;
	for(i=0;i<n-1;i++){
		if(v1[i].second<a)a=v1[i].second;
		b=a-v1[i].first,c=mm[i+1]-v1[n-1].first;
		if(b<0)b=0;
		if(c<0)c=0;
		b+=c;
		if(s<b)s=b;
	}
	a=0;
	for(i=0;i<n-1;i++){
		if(v2[i].second<a)a=v2[i].second;
		b=a-v2[i].first,c=ma[i+1]-v2[n-1].first;
		if(b<0)b=0;
		if(c<0)c=0;
		b+=c;
		if(s<b)s=b;
	}
	cout<<s<<endl;
}

Measured memory_bytes: 5092
package main

import (
    "bufio"
    "fmt"
	"os"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var X string
	fmt.Scan(&X)
	if strings.Contains(X, "7") {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 1820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool dbgflag = false;

ll modPow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n-1, p)) % p;
  ll t = modPow(a, n/2, p);
  return (t * t) % p;
}

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

  ll x, y;
  cin >> x >> y;
  if (((2 * y - x) % 3 != 0) || ((2 * x - y) % 3 != 0)) {
    cout << 0 << endl;
    return 0;
  }

  ll a = (2 * y - x) / 3, b = (2 * x - y) / 3;
  if (!((a >= 0) && (b >= 0))) {
    cout << 0 << endl;
    return 0;
  }
  ll n = a + b;
  vector<ll> fact(n+1); //階乗
  vector<ll> fact_inv(n+1); //階乗の逆元
  fact[0] = 1;
  for (int i = 0; i < n; i++) fact[i+1] = (fact[i] * (i+1)) % MOD;
  fact_inv[n] = modPow(fact[n], MOD-2, MOD);
  for (int i = n-1; i >= 0; i--) fact_inv[i] = (fact_inv[i+1] * (i+1)) % MOD;

  auto comb = [&](ll n0, ll r) { //MODで
    return (((fact[n0] * fact_inv[n0-r]) % MOD) * fact_inv[r]) % MOD;
  };

  cout << comb(a+b, a) << endl;
}


Measured memory_bytes: 10624
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-05 17:35:48
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<(x)>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l) {
    if (l > 0) return gcd(l, k%l);
    else return k;
}

ostringstream oss_global;
string s_global = oss_global.str();

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];
    vector<int> x(m), y(m);
    for (int i = 0; i < m; i++)
        cin >> x[i] >> y[i];

    UnionFind tree(n);

    for (int i = 0; i < m; i++) {
        tree.unite(x[i]-1, y[i]-1);
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (tree.same(i, p[i]-1)) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
from collections import deque

process = deque(maxlen=100000)
n, q = [int(x) for x in input().split(' ')]

for i in range(n):
    name, time = input().split(' ')
    process.append([name, int(time)])

total_time = 0

while process:
    p_q = process.popleft()
    if p_q[1] > q:
        total_time += q
        p_q[1] -= q
        process.append(p_q)
    else:
        total_time += p_q[1]
        print('{} {}'.format(p_q[0], total_time))

Measured memory_bytes: 15968
#include<iostream>
using namespace std;
int main(){
    int a,b;
    char op;
    while(1){
        cin >> a >> op >> b;
        if (op == '+'){
            cout << a+b << endl;
        }else if (op == '-'){
            cout << a-b <<endl;
        }else if (op == '*'){
            cout << a*b <<endl;
        }else if (op == '/'){
            cout << a/b << endl;
        }else break;
    }
    return 0;
}


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

int main()
{
    long long int a,b,c;
    cin>>a>>b>>c;
    long long int k;
    cin>>k;
    while(b<=a&&k)
    {
        b=b*2;
        k--;
    }
    while(c<=b&&k)
    {
        c=c*2;
        k--;
    }
    if(c>b&&b>a)
     cout<<"Yes";
    else
     cout<<"No";
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main() {
	int in1, in2;
	int ans1, ans2;
	double ans3;
	scanf("%d %d", &in1, &in2);

	ans2 = in1 % in2;
	ans1 = (in1 - ans2) / in2;
	ans3 = (double)in1 / (double)in2;

	printf("%d %d %lf", ans1, ans2, ans3);

	return 0;
}


Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std ;
int main(){
    long long int N;
    cin >> N;
    long long int A[N];
    for(long long int i=0;i<N;i++)cin >> A[i];
    long long int Sum =0;
    long long int M = A[0];
    for(long long int i=1;i<N;i++){
        if(A[i]<M)Sum+=M-A[i];
        else M = A[i];
    }
    cout << Sum << endl;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    map<int32,int32> d;
    REP(i,n){
        int32 di;
        cin >> di;
        d[di]++;
    }
    int32 m;
    cin >> m;
    bool ans = true;
    REP(i,m){
        int32 t;
        cin >> t;
        if(d[t] > 0){
            d[t]--;
        }else{
            ans = false;
            break;
        }
    }
    YES(ans);
    return 0;
}

Measured memory_bytes: 12800
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  string s;
  cin >> s;
  cout << s.substr(0, 3) << endl;
  return 0;
}


Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, i;
	cin >> N >> i;
	cout << N - i + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

#pragma gcc target ("avx2")
#pragma gcc optimization ("o3")
#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2.0) //等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}
#define nopf(T) [](T a){return a;}
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	ll h, w;
	scanf("%lld%lld", &h, &w);
	if (h == 1 || w == 1)w = h = 1;
	printf("%lld\n", (h * w + 1) / 2);

	Please AC;
}


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

fn main() {
    let a = get!(usize);
    let s = get!(String);
    if 3200 <= a {
        println!("{}", s);
    } else {
        println!("red");
    }
}


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

int main() {
    int a,b,c,d; cin >> a >> b >> c >> d;
    if(a+b > c+d) cout << "Left" << endl;
    else if(a+b < c+d) cout << "Right" << endl; 
    else cout << "Balanced" << endl; 
}

Measured memory_bytes: 256