akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define forn(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pb push_back
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
const double PI = 2*acos(0.0);

// using cosine rule
void solve(){
	double a,b,h,m; cin >> a >> b >> h >> m;
	// h_loc also moves as m_loc moves
	double m_loc = m/60 * 360,h_loc = h/12 * 360 + m_loc/360 * 360/12;
	double maxx = max(h_loc,m_loc), minn = min(h_loc,m_loc);
	double ang = min(maxx-minn, 360-(maxx-minn));
	double ang_rad = ang * PI/180;
	double ans = sqrt(a*a + b*b - 2*a*b*cos(ang_rad));
	cout << fixed << setprecision(14) << ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 4092
n_max, m_max, l_max = (int(x) for x in input().split())
a = []
b = []
c = []

for n in range(n_max):
    a.append([int(x) for x in input().split()])

for m in range(m_max):
    b.append([int(x) for x in input().split()])

for n in range(n_max):
    c.append( [sum(a[n][m] * b[m][l] for m in range(m_max)) for l in range(l_max)])

for n in range(n_max):
    print(" ".join(str(c[n][l]) for l in range(l_max)))

Measured memory_bytes: 8912
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000005

using namespace std;

ll h,w,k;
ll x1,yy1,x2,y2;
string a[max_n];
vector<vector<ll>> ans;
vector<vector<bool>> vis;
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};

void bfs(ll x,ll y)
{
	ans[x][y]=0;
	vis[x][y]=true;
	queue<pair<ll,ll>> q;
	q.push({x,y});
	while(!q.empty())
	{	
		ll xx=q.front().first,yy=q.front().second;
		// cout<<xx<<" "<<yy<<endl;
		q.pop();
		for (int j = 0; j < 4; ++j)
		{
			for (int i = 1; i <= k; ++i)
			{
				ll nx=xx+dx[j]*i;
				ll ny=yy+dy[j]*i;
				if(nx<0 || ny<0 || nx>=h || ny>=w || a[nx][ny]=='@')break;
				if(vis[nx][ny] && ans[nx][ny]<ans[xx][yy]+1LL)break;
				if(vis[nx][ny])continue;
				vis[nx][ny]=true;
				ans[nx][ny]=ans[xx][yy]+1;
				// deb(ans[nx][ny])
				q.push({nx,ny});
			}
		}
	}
}

void solve()
{
	cin>>h>>w>>k;
	cin>>x1>>yy1>>x2>>y2;
	for (int i = 0; i < h; ++i)
	{
		cin>>a[i];
	}
	x1--;yy1--;x2--;y2--;
	ans= vector<vector<ll>>(h,vector<ll>(w,-1LL));
	vis= vector<vector<bool>>(h,vector<bool>(w,false));
	bfs(x1,yy1);
	cout<<ans[x2][y2]<<endl;
}

int32_t main() 
{
	IOS	
	ll T=1;
	// cin>>T;
	for(ll i=1;i<=T;++i)
	{		
		// cout<<"Case #"<<i<<": ";
    	solve();
	}
	return 0;
}

Measured memory_bytes: 51072
using System;

namespace AOJ.intro
{
    namespace ITP_1_2_D
    {
        public static class CircleInRectangle
        {
            public static void Main()
            {
                // [W, H, x, y, r]
                string[] circleElements = Console.ReadLine().Split();
                int W, H, x, y, r;
                W = int.Parse(circleElements[0]);
                H = int.Parse(circleElements[1]);
                x = int.Parse(circleElements[2]);
                y = int.Parse(circleElements[3]);
                r = int.Parse(circleElements[4]);
                
                // ロジック
                // 水平方向: x - r < 0, x + r > W → OUT
                // 鉛直方向: y - r < 0, y + r > H → OUT
                if(x - r < 0 || x + r > W){
                    Console.WriteLine("No");
                }
                else if(y - r < 0 || y + r > H){
                    Console.WriteLine("No");
                }
                else if (x - r >= 0 &&
                         x + r <= W &&
                         y - r >= 0 &&
                         y + r <= H)
                {
                    Console.WriteLine("Yes");
                }
            }
        }
    }
}


Measured memory_bytes: 9004
from collections import deque
n, q = map(int, input().split())

edge = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    edge[a].append(b)
    edge[b].append(a)

imos = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    imos[p] += x

q = deque([(0, -1)])
while q:
    v, p = q.pop()
    for u in edge[v]:
        if u == p:
            continue
        imos[u] += imos[v]
        q.append((u, v))

print(' '.join([str(x) for x in imos]))


Measured memory_bytes: 124748
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

temp = -100
ans = 0

for i, value in enumerate(A):
    ans += B[value-1]

    if temp == value-1:
        ans += C[value-2]

    temp = value

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n;
    scanf("%d%d",&m,&n);
    for(int i=0;i<=m;i++)
     for(int j=0;j<=m;j++)
      for(int k=0;k<=m,i+j+k<=m;k++)
       {
            if(i+j+k==m && i*1000+j*5000+k*10000==n)
            {
                printf("%d %d %d",k,j,i);
                return 0;   
            }
       }
    printf("-1 -1 -1");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        String s = sc.next();
        int start = 0, end = 0;
        
        for (int i=0; i<s.length(); i++) {
            if (s.charAt(i) == 'A') {
                start = i;
                break;
            }
        }

        for (int i=0; i<s.length(); i++) {
            if (s.charAt(s.length() - 1 - i) == 'Z') {
                end = s.length() - 1 - i;
                break;
            }
        }
        System.out.println(end - start + 1);
    }
}



Measured memory_bytes: 26684
//皆さん、第9回シンデレラガール総選挙は、トップでオンリーワンを目指す城ヶ崎美嘉に
//そしてボイスアイドルオーディションは、プログラミングが趣味の才女大石泉に、ぜひ投票をお願いします！
//#城ヶ崎美嘉を009のシンデレラに
//#大石泉の必勝プログラム
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	lint x;cin>>x;
	for(lint a=0;a<1000;a++) for(lint b=-1000;b<1000;b++){
		if(a*a*a*a*a-b*b*b*b*b==x){
			cout<<a<<' '<<b<<endl;return 0;
		}
	}
}


Measured memory_bytes: 3636
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  r=I()
  return (r*2)*math.pi

# main()
print(main())


Measured memory_bytes: 10792
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner in =new Scanner(System.in);
		double r=in.nextDouble();
		double pi = 3.1415926535897932384626433 ;
		System.out.printf("%.8f %.8f", r*r*pi,2*r*pi);
		
	}

}

Measured memory_bytes: 28228
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())

r, d, x = nm()

for i in range(10):
    x = r * x - d
    print(x)


Measured memory_bytes: 3444
def main(N, M, A):
    memo = N - sum(A)
    if memo >= 0:
        return memo
    else:
        return -1

if __name__ == '__main__':
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    # N = 314
    # M = 15
    # A = list(map(int, "9 26 5 35 8 9 79 3 23 8 46 2 6 43 3".split()))
    # print(N, M, A)
    print(main(N, M, A))


Measured memory_bytes: 9876
#include <iostream>
#include <algorithm>
#define INF 10000000

using namespace std;

int cost[21][21];
int m,n;

void W(){

  for(int k = 0 ; k < n ; k++ ){
    for(int i = 0 ; i < n ; i++ ){
      for(int j = 0 ; j < n ; j++ ){
	cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
      }
    }
  }

}

int main(){

  cin >> n >> m;
  n++;

      for(int i = 0 ; i < n ; i++ ){
	for(int j = 0 ; j < n ; j++ ){
	  if(i == j )cost[i][j] = 0;
	  else cost[i][j] = INF;
	}
      }

  char ch;

  for(int i = 0 ; i < m ; i++ ){
    int a,b,c,d;

    cin >> a >> ch >> b >> ch >> c >> ch >> d;
    cost[a][b] = c;
    cost[b][a] = d;

  }

  int s,g,mone,hasira;
  cin >> s >> ch >> g >> ch >> mone >> ch >> hasira;

  W();

  int go = cost[s][g];
  int back = cost[g][s];

  cout << mone - (go+back+hasira) << endl;

  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b)for(int i=a;i<b;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define all(v) v.begin(),v.end()
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*
2d pointer array
int **dp;
in main function
int row,col;
dp=new int*[n];
rep(i,n)dp[i]=new int[m]
*/
int ans=1;
int n,k;
const int mod=1000000007;
const int maxn=100009;
vector<int>adj[maxn];
void dfs(int v,int p)
{
  int avail=k-1;
  if(p!=-1)avail--;
  for(auto u:adj[v])
  {
    if(u==p)continue;
    if(avail<=0){ans=0;return;}
    ans=ans*avail;
    avail--;
    ans%=mod;
    dfs(u,v);
  }
}
int32_t main()
{
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  fastio
  cin>>n>>k;
  ans=k;
  repre(i,1,n-1)
  {
    int u,v;
    cin>>u>>v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  dfs(1,-1);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 10368
#include<iostream>
#include<algorithm>
#include <vector>
#include <set>
using namespace std;
int main(){
	string s;
	cin>>s;
	int data[4];
	for(int i=0;i<4;i++)data[i]=s[i];
	if(s[0]==s[1] && s[2]==s[3] && s[1]!=s[2]){
		cout<<"Yes"<<endl;
	}
	else if(s[0]==s[2] && s[1]==s[3] && s[1]!=s[2]){
		cout<<"Yes"<<endl;
	}
	else if(s[0]==s[3] && s[2]==s[1] && s[1]!=s[3]){
		cout<<"Yes"<<endl;
	}else cout<<"No";
	
	
	
	
		
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod = 1000000007;		


ll f(ll n) {
	if (n % 4 == 0)return n;
	if (n % 4 == 1)return 1;
	if (n % 2 == 0)return n + 1;
	else return 0;
}




int main(){
	
	ll a, b;
	cin >> a >> b;

	int n = 0;

	cout << (f(b) ^ f(a) ^ a) << endl;

	
}

Measured memory_bytes: 256
h,w,m = map(int, input().split())

hl = [0]*(h+1)
wl = [0]*(w+1)

hw_set = set()
for _ in range(m):
    ch,cw = map(int, input().split())
    hl[ch] += 1
    wl[cw] += 1
    hw_set.add((ch,cw))

hl_vi = []
for i, v in enumerate(hl):
    hl_vi.append((v,i))
hl_vi.sort(reverse=True)

wl_vi = []
for i, v in enumerate(wl):
    wl_vi.append((v,i))
wl_vi.sort(reverse=True)

max_h = hl_vi[0][0]
max_hil = []
for v,i in hl_vi:
    if v == max_h:
        max_hil.append(i)

max_w = wl_vi[0][0]
max_wil = []
for v,i in wl_vi:
    if v == max_w:
        max_wil.append(i)


for hi in max_hil:
    for wi in max_wil:
        if not (hi,wi) in hw_set:
            ans = max_h + max_w
            print(ans)
            exit()
            
ans = max_h + max_w
print(ans-1)

# print(max_hil)
# print(max_wil)

# print(hl_vi)
# print(wl_vi)
# ans = hl_vi[0][0] + wl_vi[0][0]
# if (hl_vi[0][1], wl_vi[0][1]) in hw_set:
#     ans-=1

# print(ans)



Measured memory_bytes: 197468
x, y = map(int, input().split())

ans = 0
if abs(y) > abs(x):
    if x < 0: 
        ans += 1
    if y < 0:
        ans += 1
    ans += (abs(y)-abs(x))
else:
    if x > 0:
        ans += 1
    if y > 0:
        ans += 1
    ans += (abs(x)-abs(y))
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
int main(void)
{
    int w, t=0;
    while (1)
    {
        scanf("%d", &w);
        if (w == -1)
            break;
        if (w <= 10)
            t = 4280 - 1150;
        else if (w>10&&w <= 20)
            t = 4280 -( 1150 + 125 * (w - 10));
        else if (w>20&&w <= 30)
            t = 4280 - (1150+1250 + 140 * (w - 20));
        else if (w > 30)
            t = 4280 -( 1150+1250+1400 + 160 * (w - 30));
        printf("%d\n", t);
    }
    return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){if(a < b) a = b;}



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll k;
	cin >> n >>k;
	VL a(n);
	rep(i, n) cin >>a[i];
	sort(all(a));
	
	auto f=[&](ll m){
		ll rt =0;
		rep(i , n){
			if(a[i] == 0){
				if(m >=0 ) rt += n;
			}else if (a[i] < 0) {
				ll  mn = (m / a[i]) - 10;
				while (mn * a[i] > m) mn++;
				int  ps = lower_bound(all(a), mn) - a.begin();
				rt += n - ps;
			}else{
				ll  mx = (m / a[i]) + 10;
				while (mx * a[i] > m) mx--;
				int ps = upper_bound(all(a), mx) - a.begin();
				rt += ps;
			}
			if(a[i]*a[i]<=m) rt--;
		}
		return rt / 2;
	};
	
	const ll INF =  (ll)(1e18) + 111;
	ll l=-INF , r=INF, smz=0;
		while(r - l >1){
		ll md = (r + l) / 2;
		smz = f(md);
		( smz >=k ? r: l) = md; 
		//dbg(md, smz, "w");
	}
	
	cout << r <<"\n";

	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define forn(i,n) for(int i=0; i<(int)n; i++)
ll power(ll x,ll n);
bool isprime(ll n);

vector<ll> primes;

void test_case()
{
    ll n,ans=0;
    cin>>n;
    for(ll i=2;i*i<=n;i++) {
        ll cnt=0;
        while(n%i==0) {
            cnt++;
            n/=i;
        }
        for(ll j=1;;j++) {
            if(j>cnt)
                break;
            cnt-=j;
            ans++;
        }
    }
    if(n>1)
        ans++;
    cout<<ans;
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}
ll power(ll x,ll n)
{
    ll ans=1;
    while(n>0) {
        if(n&1)
            ans*=x;
        n>>=1;
        x*=x;
    }
    return ans;
}

bool isprime(ll n)
{
    if(n==2 || n==3)
        return true;
    if(n<=1 || n%2==0 || (n%6!=1 && n%6!=5))
        return false;
    for(ll i=3;i*i<=n;i+=2) {
        if(n%i==0)
            return false;
    }
    return true;
}


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s=scan.nextLine();
		if(s.contains("RRR")) System.out.println(3);
		else if(s.contains("RR")) System.out.println(2);
		else if(s.contains("R")) System.out.println(1);
		else System.out.println(0);
	}

}


Measured memory_bytes: 26976
n=gets.to_i

a = []
n.times do |i|
    a << gets.to_i
end

memo = {}
c = 1
i = 1
while memo[i] == nil
    if a[i-1] == 2 
        puts c
        exit
    else
        memo[i] = true
        i = a[i-1]
        c += 1
    end
    
end
puts -1

Measured memory_bytes: 9268
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

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

#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007
#define PI acos(-1)

void solve() {
	string s;
	cin >> s;
	int ans = 0;
	for(const auto &ch : s) {
		ans += (ch - '0');
	}
	cout << (ans % 9 == 0 ? "Yes" : "No");
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int tc = 1;
	// cin >> tc;
	while(tc--) {
	    solve();
	}
	return 0;
}


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

int H[500005];
int n;

void maxHeapify(int i) {
    int l = 2 * i;
    int r = 2 * i + 1;
    int largest;

    if (l <= n && H[l] > H[i]) largest = l;
    else largest = i;

    if (r <= n && H[r] > H[largest]) largest = r;

    if (largest != i) {
        swap(H[i], H[largest]);
        maxHeapify(largest);
    }
}

void buildMaxHeap() {
    for (int i = n / 2; i > 0; i--) maxHeapify(i);
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> H[i];
    buildMaxHeap();
    for (int i = 1; i <= n; i++) cout << " " << H[i];
    cout << "\n"; 
}


Measured memory_bytes: 5004
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val a = nextInt()
    val b = nextInt()
    val c = nextInt()
    val d = nextInt()
    val e = nextInt()
    val k = nextInt()
    println(if (e - a > k) ":(" else "Yay!")
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 33476
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    ll x = n % 10;
    if (x == 3) {
        cout << "bon" << endl;
    }
    else if (x == 0 || x == 1 || x == 6 || x == 8) {
        cout << "pon" << endl;
    }
    else {
        cout << "hon" << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;
typedef long long LL;

int main(void) {

	int a, b, result, tower;

	cin >> a >> b;

	tower = (b - a) * ((b - a) + 1) / 2;
	cout << tower - b;
	
	cin >> a;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//大小比較(大)
long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}

main() {
	long long int n, m,k;
	scanf("%lld%lld%lld", &n,&m,&k);

	printf("%lld", big(big(n, m), k) - small(small(n, m), k));
}


Measured memory_bytes: 128
fun main(args:Array<String>?): Unit {
    val (n, k) = readLine()!!.trim().split(' ').map(String::toInt)
    val rabbits = IntArray(n){0}
    repeat(k){i ->
        for (r in readLine()!!.trim().split(' ').map(String::toInt).drop(1))
            rabbits[r - 1] = i
    }
    val hate = BooleanArray(n){false}
    repeat(readLine()!!.trim().toInt()){
        val (p, q) = readLine()!!.trim().split(' ').map(String::toInt)
        if (rabbits[p - 1] == rabbits[q - 1]) {
            hate[p - 1] = true
            hate[q - 1] = true
        }
    }
    println(hate.count{it})
}


Measured memory_bytes: 32876
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define pb push_back
// int gcd(ll a, ll b) 
// { 
//     if (a == 0)  
//       return b; 
      
//     return gcd(b%a, a); 
// }

void solve()
{
    ll n;cin>>n;
    ll ans=0;
    
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            for(ll k=1;k<=n;k++){
                ll x = __gcd(i,j);
                ans += __gcd(x,k);
            }
        }
    }
    
    cout<<ans<<endl;
    
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    // ll t;cin>>t;while(t--)
    {
        solve();
    }
    
	return 0;
}


Measured memory_bytes: 3600
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
using lint = long long;
template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }
inline int bitCount(int x) { return __builtin_popcount(x); }
inline int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int N;
	cin >> N;
	
	Vec< lint > A(N+1), B(N);
	for_(i,0,N+1) cin >> A[i];
	for_(i,0,N) cin >> B[i];
	
	reverse(allof(A));
	reverse(allof(B));
	
	lint ans = 0;
	for_(i,0,N) {
		lint X = min(A[i], B[i]);
		A[i] -= X;
		B[i] -= X;
		ans += X;
		lint Y = min(A[i+1], B[i]);
		A[i+1] -= Y;
		B[i] -= Y;
		ans += Y;
	}
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 1792
n, q = map(int,input().split())
s = input()

t = [0]*(n+1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == 'AC' else 0)

for i in range(q):
    l,r = map(int,input().split())
    print(t[r-1] - t[l-1])

Measured memory_bytes: 9412
A, B, C, X, Y = map(int, input().split())

ans = 10000000000
for i in range(2 * max(X, Y) + 1):
    A_half = i
    B_half = i
    cur_cost = i * C
    
    left_A_half = 2 * X - A_half
    left_B_half = 2 * Y - B_half
    if left_A_half > 0 :
        if left_A_half % 2 == 0:
            cur_cost += left_A_half // 2 * A
        else:
            cur_cost += (left_A_half // 2 + 1) * A
    
    if left_B_half >= 0:
        if left_B_half % 2 == 0:
            cur_cost += left_B_half // 2 * B
        else:
            cur_cost += (left_B_half // 2 + 1) * B
    
    ans = min(ans, cur_cost)
    
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
  int a, b, c, d, flag = 0;

  scanf("%d%d%d%d", &a, &b, &c, &d);

  while(a > 0 && c > 0){
    if(flag == 0){
      c -= b;
      flag = 1;
    }else{
      a -= d;
      flag = 0;
    }
  }

  if(flag == 0){
    printf("No");
  }else{
    printf("Yes");
  }

  return 0;
}


Measured memory_bytes: 1708
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<double> x(n), y(n);
	double div = 1;
	rep(i,n){
		cin >> x[i] >> y[i];
		div *= (i+1);
	}
	vector<int> v(n);
	rep(i,n) v[i] = i;
	double ans = 0;
	do{
		double dist = 0;
		rep(i,n-1){
			dist += sqrt((x[v[i]]-x[v[i+1]])*(x[v[i]]-x[v[i+1]]) + (y[v[i]]-y[v[i+1]])*(y[v[i]]-y[v[i+1]]));
		}
		ans += dist;
	} while(next_permutation(v.begin(), v.end()));
	ans /= div;
	cout << fixed << setprecision(12) << ans << endl;
	return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

struct Edge{
  int to, cost;

  Edge(int t, int c = 0): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }

};
using Graph =  vector< vector<Edge> >;

// calc topological sort
// O(V+E)
bool topo_sort(const Graph& G, VI& order){
  int N = G.size();
  VI color(N, 0);
  
  function<bool(int)> visit = [&](int v)->bool{
	color[v] = 1;
	for(const auto& e: G[v]){
	  if(color[e.to] == 2) continue;
	  if(color[e.to] == 1) return false;
	  if(!visit(e.to)) return false;
	}
	order.push_back(v);
	color[v] = 2;
	return true;
  };

  for(int u=0;u<N;++u)
	if(!color[u] && !visit(u))
	  return false;
  reverse(begin(order), end(order));
  return true;
}

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

  int V, E;
  cin >> V >> E;
  Graph G(V);
  REP(i,E){
	int s, t;
	cin >> s >> t;
	G[s].EB(t);
  }
  VI order(V);
  topo_sort(G, order);
  REP(i,V) cout << order[i] << endl;

  return 0;
}

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

// 插入此處

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    string s; cin >> s;
    int R = 0, G = 0, B = 0;
    for (int i = 0; i < N; ++i) {
        switch(s[i]) {
        case 'R':
            ++R;
            break;
        case 'G':
            ++G;
            break;
        case 'B':
            ++B;
            break;
        }
    }
    LL ans = 1LL*R*B*G;
    for (int i = 0; i < N; ++i) {
        for (int j = 1; ; ++j) {
            if (i-j < 0 || i+j == N)  break;
            if (s[i-j] != s[i] && s[i+j] != s[i] && s[i-j] != s[i+j])  --ans;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    vector<ll> pos;
    vector<ll> neg;
    vector<pair<int, int>> his;

    ll N, tmp;
    cin >> N;
    for (int i=0; i<N; i++){
        cin >> tmp;
        if (tmp <= 0) neg.push_back(tmp);
        else pos.push_back(tmp);
    }
    int x, y;
    while (pos.size() + neg.size() > 1){
		//cout << "size: " << pos.size() << " " << neg.size() << endl;
        if (pos.size() == 1 && neg.size() == 1){
            x = pos.front();
            y = neg.front();
            pos[0] = x - y;
            neg.erase(neg.begin());
        }
        else if (pos.size() == 1 && neg.size() > 1){
            y = neg.back();
            x = pos.front();
            pos[0] = x - y;
            neg.pop_back();
        }
        else if (neg.size() == 1 && pos.size() > 1){
            y = pos.back();
            x = neg.front();
            neg[0] = x - y;
            pos.pop_back();
        }
        else if (neg.size() == 0){
            sort(pos.begin(), pos.end());
            x = pos[0];
            y = pos[1];
            neg.push_back(x - y);
            pos.erase(pos.begin(), pos.begin() + 2);
        }
        else if (pos.size() == 0){
            sort(neg.begin(), neg.end());
            x = neg.back();
            y = neg[neg.size() - 2];
            pos.push_back(x - y);
            neg.erase(neg.end() - 2, neg.end());
        }
        else{
            x = neg.back();
            y = pos.back();
            neg.pop_back();
            pos.pop_back();
            neg.push_back(x - y);
            
        }
        his.emplace_back(pair<int, int>(x, y));
    }
    cout << pos[0] << endl;
    for (auto e : his){
        cout << e.first << " " << e.second << endl;
    }
    return 0;
}

Measured memory_bytes: 4340
import sys
input=sys.stdin.readline
h,w,n=map(int,input().split())
ans=[(h-2)*(w-2)]+[0]*9
s1=set()
s2=set()
for i in range(n):
  a,b=map(int,input().split())
  s2.add(a*(10**10)+b)
  for j in range(3):
    for k in range(3):
      if 0<a-j<h-1 and 0<b-k<w-1:
        s1.add((a-j)*(10**10)+b-k)
for x in s1:
  now=0
  for i in range(3):
    for j in range(3):
      if (x+i*(10**10)+j) in s2:
        now+=1
  ans[now]+=1
ans[0]-=sum(ans[1:])
[print(x) for x in ans]


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

const int maxn = 1e5+3;
int row, col, n, que[maxn<<1];
pair<int, int> arr[maxn<<1];

bool check(int a, int b)
{
    if(a==0 || a==row || b==0 || b==col) return true;
    return false;
}

int cal(int a, int b)
{
    if(a==0) return b;
    else if(b==col) return col + a;
    else if(a==row) return col + row + col - b;
    else return col + col + row + row - a;
}

int main()
{
    int a, b, c, d, cnt = 0, icount = 0;
    scanf("%d%d%d",&row,&col,&n);
    {
        while(n--)
        {
            scanf("%d%d%d%d",&a,&b,&c,&d);
            if(check(a, b) && check(c, d))
            {
                arr[cnt++] = make_pair(cal(a, b), icount);
                arr[cnt++] = make_pair(cal(c, d), icount++);
            }
        }
        sort(arr, arr+cnt);
        int r=0;
        for(int i=0; i<cnt; ++i)
        {
            if(!r)
                que[++r] = arr[i].second;
            else if(arr[i].second == que[r])
                --r;
            else
            que[++r] = arr[i].second;
        }
        if(!r) puts("YES");
        else puts("NO");
    }
    return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;

int main(){
    int N;cin>>N;
    int K;cin>>K;
    int h[100010];
    for(int i=1;i<=N;i++)cin>>h[i];

    int dp[100010];
    dp[1]=0;

    //漸化式
    for(int i=2;i<=N;i++){
        dp[i]=pow(10,9);
        for(int k=1;k<=K;k++){
            if(i-k>0)
                dp[i]=min(dp[i],dp[i-k]+abs(h[i]-h[i-k]));
            else break;
        }
    }

    cout<<dp[N]<<endl;
    return 0;

}

Measured memory_bytes: 1024
sent = input()
nsent = ""
for c in sent:
    if ord("a") <= ord(c) and ord(c) <= ord("z"):
        nsent += chr(ord(c) + ord("A") - ord("a"))
    elif ord("A") <= ord(c) and ord(c) <= ord("Z"):
        nsent += chr(ord(c) + ord("a") - ord("A"))
    else:
        nsent += c

print(nsent)


Measured memory_bytes: 5552
//kruskal tree
#include <cstdio>
#include <algorithm>
using namespace std;
#define M 99999
int parent[M],a[M],b[M];
pair<int,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,s,n,m;
	for(;scanf("%d%d",&n,&m)>1;printf("%d\n",s/100-n+1)){
		for(i=0;i<m;i++)scanf("%d,%d,%d",a+i,b+i,&node[i].first),node[i].second=i;
		sort(node,node+m);
		for(i=0;i<n;i++)parent[i]=i;
		for(s=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))s+=node[i].first;
	}
}

Measured memory_bytes: 1852
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;


int main(){

	ll N, M;
	cin >> N >> M;
	ll path[55][55] = {};
	vector<ll>A(M), B(M);
	for(ll i = 0; i < M; i++){
		cin >> A[i] >> B[i];
		path[A[i]][B[i]] = 1;
		path[B[i]][A[i]] = 1;
	}
	ll ans = 0;
	for(ll i = 0; i < M; i++){
		ll f = 0;
		ll flg[55] = {};
		queue<ll>Q;
		flg[1] = 1;
		Q.push(1);
		while(!Q.empty()){
			ll q = Q.front();
			Q.pop();
			for(ll j = 1; j <= N; j++){
				if(path[q][j] == 0)continue;
				if(flg[j])continue;
				if(min(q, j) == A[i] && max(q, j) == B[i])continue;
				flg[j] = 1;
				Q.push(j);
			}
		}
		for(ll j = 1; j <= N; j++)if(flg[j] == 0)f = 1;
		if(f)ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int fib3(int fib[], int n)
{
	int i;
	
	for (i = 3; i < n; i++){
		fib[i] = fib[i - 1] + fib[i - 2] + fib[i - 3];
	}
	
	return (fib[n - 1]);
}

int main(void)
{
	int n;
	
	scanf("%d", &n);
	while (n != 0){
		int i, j;
		int step[30] = {1, 2, 4};
		int way;
		
		way = fib3(step, n);
		if (!(way / 3650)){
			puts("1");
		}
		else if (way % 3650){
			printf("%d\n", way / 3650 + 1);
		}
		else {
			printf("%d\n", way / 3650);
		}
		
		scanf("%d", &n);
	}
	
	return (0);
}

Measured memory_bytes: 612
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	int n=sc.nextInt();
	int a[]=new int[n];
	for(int i=0;i<=n-1;i++){
		a[i]=sc.nextInt();
	}
Arrays.sort(a);
int sam=0;
for(int i=0;i<=n-2;i++){
if(a[i]==a[i+1]){
	sam++;
}
}System.out.println(n-sam);
	}}

Measured memory_bytes: 21844
S=list(input())
S_re=list(reversed(S))
N=len(S)

if N%2==0:
    start=2
else:
    start=1

ans=0
for i in range(start,N,1):
    S_=S[i:]
    S_re_=S_re[i:]
    l_S=len(S_)
    if S_[l_S//2:]==S_[:l_S//2] and ans<l_S:
        ans=l_S
    if S_re_[l_S//2:]==S_re_[:l_S//2] and ans<l_S:
        ans=l_S

print(ans)

Measured memory_bytes: 3064
# include <iostream>
# include <cstdio>
# include <queue>
# include <vector>
# include <set>
# include <cstring>
# include <algorithm>
# define LL long long
using namespace std;
struct p
{
    int x,y;
}c[100005];
bool comp (const p &a, const p &b)
    {

        return a.x<b.x;
    }
int main()
{
    int n,a,b,i,j;j=0;
    LL k,s;s=0;
    memset(c,0,sizeof(c));
    scanf("%d%lld",&n,&k);
    vector<int> v;
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&a,&b);
        c[i].x=a;
        c[i].y=b;
    }
    sort(c,c+n,comp);
    for(i=0;i<n;i++)
    {
        s=s+c[i].y;
        if(k<=s)
        {
            j=i;
            break;
        }
    }
    printf("%d",c[j].x);
    return 0;

}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
 int n;
 cin>>n;
 vector<int> p(n);
 int maxi=0,sum=0;
 r(i,n){
   cin>>p.at(i);
   maxi=max(maxi,p.at(i));
   sum+=p.at(i);
 }
 cout<<sum-maxi/2<<endl;



return 0;}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
//const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

template< int mod >
struct ModInt {
	int x;

	ModInt() : x(0) {}

	ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

	ModInt &operator+=(const ModInt &p) {
		if ((x += p.x) >= mod) x -= mod;
		return *this;
	}

	ModInt &operator-=(const ModInt &p) {
		if ((x += mod - p.x) >= mod) x -= mod;
		return *this;
	}

	ModInt &operator*=(const ModInt &p) {
		x = (int)(1LL * x * p.x % mod);
		return *this;
	}

	ModInt &operator/=(const ModInt &p) {
		*this *= p.inverse();
		return *this;
	}

	ModInt operator-() const { return ModInt(-x); }

	ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

	ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

	ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

	ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

	bool operator==(const ModInt &p) const { return x == p.x; }

	bool operator!=(const ModInt &p) const { return x != p.x; }

	ModInt inverse() const {
		int a = x, b = mod, u = 1, v = 0, t;
		while (b > 0) {
			t = a / b;
			a -= t * b;
			swap(a, b);
			u -= t * v;
			swap(u, v);
		}
		return ModInt(u);
	}

	friend ostream &operator<<(ostream &os, const ModInt< mod > &p) {
		return os << p.x;
	}

	friend istream &operator>>(istream &is, ModInt< mod > &a) {
		long long x;
		is >> x;
		a = ModInt< mod >(x);
		return (is);
	}

};

const int mod = 1e9 + 7;
using modint = ModInt< mod >;

modint c[4030][4030];
void init() {
	c[0][0] = 1;
	for (int i = 0; i <= 4000; i++) {
		for (int j = 0; j <= i; j++) {
			c[i + 1][j] += c[i][j];
			c[i + 1][j + 1] += c[i][j];
		}
	}
}

modint comb(int n, int k) {
	return c[n][k];
}

modint f2(int n, int k) {
	return comb(n + k - 1, k - 1);
}
modint f(int n, int k) {
	if (n < k) return 0;
	if (n == 0 && k == 0) return 1;
	if (k < 1) return 0;
	return f2(n - k, k);
}

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

	init();
	int n, k;
	cin >> n >> k;

	for (int i = 1; i <= k; i++) {
		modint blue = f(k, i);
		modint red = 0;
		red += f(n - k, i - 1);
		red += f(n - k, i);
		red += f(n - k, i);
		red += f(n - k, i + 1);
		modint ans = blue * red;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 63744
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; cin>>n;
	VI a(n); rep(i,n) cin>>a[i], a[i]--;
	int ans = 0;
	rep(i,n){
		if(i<a[i]&&a[a[i]]==i) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
/**
*	created: 05.09.2020 22:56:00
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using ll = long long;
using P = pair<int,int>;
// #define endl '\n'
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rrep(i,n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;
template<typename T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
template<typename T> T pow(T a, ll n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
struct faster_io {faster_io() {cin.tie(0); ios_base::sync_with_stdio(false);}} faster_io_;

// UnionFind
struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n,-1) {}
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x,y);
        par[x] += par[y]; par[y] = x;
        return true;
    }
    bool issame(int x, int y) {return root(x) == root(y);}
    int size(int x) {return -par[root(x)];}
};

signed main() {
    int n, q; cin >> n >> q;
    UnionFind uf(n);
    rep(i,q) {
        int t, u, v; cin >> t >> u >> v;
        if(t) cout << uf.issame(u,v) << endl;
        else uf.merge(u,v);
    }
    return 0;
}

Measured memory_bytes: 4688
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include <math.h>
#define Read_Fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
using namespace std;
using ll=long long;
const int N=2e5+5;


int main()
{
    int a, b, h, m;
    scanf("%d %d %d %d", &a, &b, &h, &m);

    long double rad = PI * 2 * (
                          (long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long
                                  double)m / 60.0);

    long double rsq = (long double)(a * a + b * b) - (long double)(2 * a *
                      b) * cosl(rad);

    printf("%20.20Lf\n", sqrtl(rsq));

    return 0;
}


Measured memory_bytes: 4128
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;
/* class */
class DisjointSet {
public:
    // d[i] is root => d[i] < 0 & d[i] is the size of tree
    // d[i] is child => d[i] >= 0 & d[i] = i.parent
    vector<int> d;

    DisjointSet() {}
    DisjointSet(int size) : d(size, -1) {}

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if ( d[x] > d[y] ) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};
/* global variables */
/* function */
/* main */
int main(){
    int n, m;
    cin >> n >> m;
    DisjointSet ds = DisjointSet(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        ds.unite(a, b);
    }

    set<int> st;
    for (int i = 0; i < n; i++) st.insert(ds.find(i));
    cout << st.size() - 1 << '\n';
}


Measured memory_bytes: 7496
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define ll long long
#define bit(x) (x >> bt & 1)
using namespace std;

const int maxn = 2e5 + 5;
int n;
int a[maxn], b[maxn << 1];
int nxt[maxn], cnt[maxn << 1];
void getnxt(int bt) {
	memset(nxt, 0, sizeof(nxt));
	for(int i = 2, j = 0; i <= n; ++i) {
		while(j && bit(a[j + 1]) != bit(a[i]))
			j = nxt[j];
		if(bit(a[j + 1]) == bit(a[i])) j++;
		nxt[i] = j;
	}
}
void kmp(int bt) {
	getnxt(bt);
	for(int i = 1, j = 0; i < 2 * n; ++i) {
		while(j && bit(b[i]) != bit(a[j + 1]))
			j = nxt[j];
		if(bit(b[i]) == bit(a[j + 1])) j++;
		if(j == n) {
			cnt[i - n + 1]++;
			j = nxt[j];
		}
	}
	for(int i = 1, j = 0; i < 2 * n; ++i) {
		while(j && bit(b[i]) != !bit(a[j + 1]))
			j = nxt[j];
		if(bit(b[i]) == !bit(a[j + 1])) j++;
		if(j == n) {
			cnt[i - n + 1]++;
			j = nxt[j];
		}
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i];
	for(int i = 1; i <= n; ++i) cin >> b[i], b[i + n] = b[i];
	for(int i = 0; i < 30; ++i) kmp(i);
	if(cnt[1] == 30) cout << 0 << " " << (b[1] ^ a[1]) << '\n';
	for(int i = n; i > 1; --i)
		if(cnt[i] == 30) cout << n - i + 1 << " " << (b[i] ^ a[1]) << '\n';
	return 0;
}

Measured memory_bytes: 7688