akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
#include <atcoder/all>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
using ll = long long;
using ull = unsigned long long;
#define REP(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); ++i)
#define REP2(i, m, n) for (ll(i) = (ll)(n)-1; i >= (ll)(m); --i)
#define rep(i, n) REP(i, 0, n)
#define rep2(i, n) REP2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T> inline void print(T x) { cout << x << '\n'; }
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;
}

long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }

// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// v ector<long long> v(n), c(n);
// cout << res << endl;
// cout << res << '\n';
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)
// vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(w + 1,
// vector<int>(k+1, 0)));

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, q;
    cin >> n >> q;
    fenwick_tree<ll> fw(n);
    rep(i,n) {
        ll a;
        cin >> a;
        fw.add(i,a);
    }
    rep(i,q) {
        ll t,l,r;
        cin >> t >> l >> r;
        if (t == 0) {
            fw.add(l,r);
        } else {
            printf("%lld\n",fw.sum(l,r));
        }

    }
    return 0;
}


Measured memory_bytes: 8260
<?php
list($n, $m) = ints();
for ($i = 0; $i < $m; ++$i) {
    list($a, $b) = ints();
    $a--;
    $b--;
    $g[$a][] = $b;
    $g[$b][] = $a;
}
$cnt = 0;
dfs();
echo $cnt;
function dfs($v = 0, $used = [])
{
    global $n, $g, $cnt;
    $used[$v] = true;

    if (count($used) === $n) {
        $cnt++;
        return;
    }
    if (is_null($g[$v])) return;
    foreach ($g[$v] as $to) {
        if ($used[$to]) continue;
        dfs($to, $used);
    }
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 4728
n = int(input())
a = list(map(int, input().split()))
def gcd(a, b):
        if a < b:
                return gcd(b, a)
        elif b > 0:
                return gcd(b, a%b)
        else:
                return a
l = [0, a[0]]
r = [0, a[n-1]]

for i in range(1, n):
        l.append(gcd(l[i],a[i]))
        r.append(gcd(r[i],a[n-i-1]))
allgcd = []
for i in range(1, n+1):
        allgcd.append(gcd(l[i-1],r[n-i]))
print(max(allgcd))

Measured memory_bytes: 14400
#include <bits/stdc++.h> 
#define lowbit(x) x&(-x)
using namespace std;
typedef long long ll;
const int N = 1e4+5;
const int M = 2e3;

int num[N];

int main(){
	int n,p;
	ll ans = 0;
	string s;
	scanf("%d%d",&n,&p);
	cin >> s;
	
	if(p == 2 || p == 5){
		for(int i = 0;i < n;++i){
			if((s[i]-'0') % p == 0) ans += i+1;
		}
	}
	else{
		int last = 0,base = 1;num[0]++;
		for(int i = n-1;i >= 0;--i){
			int t = (s[i]-'0')%p*base%p;
			(base *= 10) %= p;
			(last += t) %= p;
			ans += num[last];
			num[last]++;
		}
	}
	printf("%lld\n",ans);
    return 0;
}

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

int a[10005];

int ans[105][105];

int main()
{
    int h, w, n;
    scanf("%d%d%d",&h,&w,&n);
    for (int i = 1; i <= n; i++) scanf("%d",&a[i]);

    int p = 1;

    for (int i = 1; i <= h; i++)
    {
        if (i & 1)
        {
            for (int j = 1; j <= w; j++)
            {
                while (a[p] == 0) ++p;
                ans[i][j] = p;
                a[p]--;
            }
        }
        else
        {
            for (int j = w; j >= 1; j--)
            {  
                while (a[p] == 0) ++p;
                ans[i][j] = p;
                a[p]--;
            }
        }
    }
    for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) printf("%d%c", ans[i][j], j == w ? '\n' : ' ');
}


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

int main(){
  string a;
  cin >> a;

  int x=0;
  int y=0;

  int z;

  int ans=0;

  for(int i =0;i<a.size();i++){
    z=0;
    x=0;
    y=0;
    for(int j =0;j<i;j++){
      x*=10;
      x+=a[j]-'0';
    }
    for(int j =i;j<a.size();j++){
      if(a[i]=='0')z=1;
      y*=10;
      y+=a[j]-'0';
    }
    if(z==0&&(x-y)%2==0){
      if(x<=y)ans++;
      //cout << x<<" "<<y<<endl;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3220
import java.util.Scanner;

public class Main {

	static int n, m;
	static int[] a, b;
	static boolean[][] gragh;
	static boolean[] vis;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		a = new int[m];
		b = new int[m];
		gragh = new boolean[n][n];
		vis = new boolean[n];
		for(int i = 0 ; i < m ; i++) {
			a[i] = sc.nextInt() - 1;
			b[i] = sc.nextInt() - 1;
			gragh[a[i]][b[i]] = gragh[b[i]][a[i]] = true;
		}
		long ans = 0;
		for(int i = 0 ; i < m ; i++) {
			for(int j = 0 ; j < n ; j++) {
				vis[j] = false;
			}
			gragh[a[i]][b[i]] = gragh[b[i]][a[i]] = false;
			dfs(0);
			boolean bridge = false;
			for(int j = 0 ; j < n ; j++) {
				if(!vis[j]) {
					bridge = true;
				}
			}
			if(bridge) ans++;
			gragh[a[i]][b[i]] = gragh[b[i]][a[i]] = true;
		}
		System.out.println(ans);
	}

	public static void dfs(int x) {
		if(vis[x]) return;
		vis[x] = true;
		for(int i = 0 ; i < n ; i++) {
			if(gragh[x][i] == false) continue;
			dfs(i);
		}
	}

}

Measured memory_bytes: 22100
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	string s;
	cin >> s;
	string ans = "";
	for (int i = 0; i < s.size(); i = i + 2) {
		ans = ans + s[i];
	}
	cout << ans;
}


Measured memory_bytes: 640
#include <stdio.h>

void swap (long long int *a, long long int *b) {
  long long int tmp = *a;
  *a = *b;
  *b = tmp;
}

int main(){
  int n;
  scanf("%d", &n);
  long long int a[n];
  long long int sum = 0;
  for(int i = 0; i < n; i++){
    scanf("%lld", &a[i]);
    sum = sum ^ a[i];
  }
  //printf("%lld\n", sum);
  long long int mask = ~sum;
  for (int i = 0; i < n; i++) {
    a[i] = a[i] & mask;
  }
  int rank = 0;
  long long int ans = 0;
  for (int i = 59; i >= 0; i--) {
    if (mask & (1uLL << i)) {
      int p = -1;
      for (int j = rank; j < n; j++) {
        if (a[j] & (1uLL << i)) {
          p = j;
          if (j != rank) {
            swap(&a[j], &a[rank]);
          }
          rank++;
          break;
        }
      }
      if (p >= 0) {
        for (int j = 0; j < n; j++) {
          //printf("%llx %llx\n", a[j], (1uLL << i));
          if ((a[j] & (1uLL << i)) && (j != rank - 1)) {
            a[j] ^= a[rank - 1];
          }
        }
      }
    }
  }
  for(int i = 0; i < n; i++){
    ans = ans ^ a[i];
  }
  ans = (ans << 1) + sum;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 896
#include "bits/stdc++.h"
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define sz(a) int((a).size())
	#define pb push_back
	#define mod 1000000007
	#define inf 1000000000000000001
	#define all(c) (c).begin(),(c).end()
	#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
	#define present(c,x) ((c).find(x) != (c).end())
	#define cpresent(c,x) (find(all(c),x) != (c).end())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	#define FOR(i, a, b) for (int i=a; i<(b); i++)
	#define F0R(i, a) for (int i=0; i<(a); i++)
	
	using namespace std;
	
	int main()
	{
		ios::sync_with_stdio(0);
    	cin.tie(0);
    	cout.tie(0);

		ll n;
		cin >> n;
		ll a[n];
		F0R(i,n) cin>>a[i];
		sort(a,a+n);
		ll ans=0;
		for(ll i=0; i<n-2; i++) {
			ll k=i+2;
			for(ll j=i+1;j<n;++j) {
				while(k<n && a[i]+a[j]>a[k])
					++k;
				if(k>j)
					ans+=(k-j-1);
			}
		}
		cout << ans;
		
		return 0;
	}

Measured memory_bytes: 256
//Never stop chasing!-MdSourav.
#include <bits/stdc++.h>

#define yes            cout<<"YES"<<endl
#define no             cout<<"NO"<<endl
#define sz(x)          x.size()
#define ll                    long long int
#define ls             long int
#define start          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test           int t;cin>>t;while(t--)
#define f(i, a, n)     for(int i=a; i<n;i++)
#define gcd(a,b)7           __gcd(a,b)
#define lcd(a,b)       (a*b)/gcd(a,b)
#define pb             push_back
#define mp(x,y)        make_pair(x,y)
#define rsrt(v)        sort(v.begin(),v.end(),greater<int>())
#define srt(v)         sort(v.begin(),v.end())
#define basrt(a,n)     sort(a,a+n,greater<int>())
#define asrt(a,n)      sort(a,a+n)
#define fact(n)        ll x=1;for(ll i=1;i<=n;i++){x=(x*i);}
#define F              first
#define S              second
#define deb(x)         cout << #x << ": " << x << endl;
#define enter(v,n)     for(ll i=0;i<n;i++){ll x;cin>>x;v.pb(x);}
#define INF 	       1000000007
#define unique(v)      v.erase(unique(v.begin(),v.end()),v.end())
using namespace std;

double pi=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664 ;
typedef vector<ll> vll ;
typedef vector<int> vii ;

template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v)
{
    os << '{';
    for (const auto &x : v) os << " " << x;
        return os << '}';
}

int min(int x, int y)
{
    return (x < y)? x: y;

}

double calcAngle(double h, double m)
{
    if (h <0 || m < 0 || h >12 || m > 60)
        printf("Wrong input");

    if (h == 12) h = 0;
    if (m == 60)
     {
      m = 0;
      h += 1;
       if(h>12)
        h = h-12;
     }
    double hour_angle = 0.5 * (h * 60 + m);
    double minute_angle = 6 * m;

    double angle = abs(hour_angle - minute_angle);
    angle = min(360 - angle, angle);

    return angle;
}
void solve()
{
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      double x=calcAngle(c,d);
      //cout << x << endl;
      long double fou=(a*a)+(b*b);
      x=(x*pi)/180.0;
      //deb(x);
      fou=fou-2*a*b*cos(x);
      fou=sqrt(fou);
      cout << fixed << setprecision(20) << fou << endl;


}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    ll test_case=1;
    //cin>>test_case ;
    while(test_case--)
	{
		 solve();
	}

	return 0;
}

Measured memory_bytes: 4188
#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define rt0 return 0
using namespace std;
int main()
{
	vector <int> a(3); 
	cin>>a[0]>>a[1]>>a[2];
	sort(a.begin(),a.end());
	if(((a[2]-a[0])+(a[2]-a[1]))%2==0) cout<<((a[2]-a[0])+(a[2]-a[1]))/2;
	else cout<<((a[2]-a[0])+(a[2]-a[1])+3)/2;
    rt0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector <pair <int ,int>> wv;
int dp[110][100010];
signed main()
{
	//freopen("out.txt","w", stdout);
	int n, w;
	cin >> n >> w;
	for (int i = 1; i <= n; i++){
		int w, v;
		cin >> w >> v;
		wv.emplace_back(w, v); 
	}
	//sort(wv.begin(), wv.end());
	for (int item = 1; item <= n; item++){
		for (int remain_w = 1; remain_w <= w; remain_w++){
			if (wv[item-1].first > remain_w){
				dp[item][remain_w] = dp[item-1][remain_w];
			}else{
				dp[item][remain_w] = max(dp[item-1][remain_w - wv[item-1].first] + wv[item-1].second, dp[item-1][remain_w] );
			}
		}
	}
	cout << dp[n][w];
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int a, b; cin >> a >> b;

    int ma = max(a, b);

    if (a == b) {
        cout << ma + ma << endl;
    } else {
        cout << ma + ma - 1 << endl;
    }
}

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

int main()
{
    ll n, p;
    cin >> n >> p;

    if (n == 1)
    {
        cout << p << endl;
        return 0;
    }


    ll ans = 1;
    for (ll i = 2; i * i <= p; ++i)
    if (p % i == 0)
    {
        int cnt = 0;
        while (p % i == 0) 
        {
            p /= i;
            ++cnt;
        }

        rep(j, 0, cnt / n)
            ans *= i;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> fruits;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        fruits.push_back(tmp);
    }
    sort(fruits.begin(), fruits.end());
    int val = 0;
    for (int i = 0; i < k; i++) {
        val += fruits[i];
    }
    cout << val;
    return 0;
}


Measured memory_bytes: 3628
n,a,b,c = map(int,input().split())
li = [int(input()) for _ in range(n)]

inf = 1000000
def cost(N,x,y,z):
  if N == n:
    if x*y*z == 0:
      return inf
    return abs(x-a) + abs(y-b) + abs(z-c)
  
  cost1 = cost(N+1,x,y,z)
  cost2 = cost(N+1,x+li[N],y,z) + 10
  cost3 = cost(N+1,x,y+li[N],z) + 10
  cost4 = cost(N+1,x,y,z+li[N]) + 10
  return min(cost1,cost2,cost3,cost4)

print(cost(0,0,0,0)-30)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    int a, b, c;
    ll k;
    cin >> a >> b >> c >> k;
    if (k % 2) {
        cout << b - a << "\n";
    } else {
        cout << a - b << "\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

int main()
{
    std::size_t n;
    std::cin >> n;

    int max = -1000000000;
    int buy = - 1;
    for (std::size_t i = 0; i < n; ++i) {
        int r;
        std::cin >> r;
        if (buy < 0) {
            buy = r;
            continue;
        }

        if (max < (r - buy)) {
            max = r - buy;
        }

        if (r < buy) {
            buy = r;
        }
    }

    std::cout << max << std::endl;

    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll n, m, x;
    cin >> n >> m >> x;

    vector<ll> cost(n);
    vector<vector<ll>> v(n, vector<ll>(m));
    REP(i, n){
        cin >> cost[i];
        REP(j, m){
            cin >> v[i][j];
        }
    }

    ll ans = INF;

    REP(bit, 1 << n){
        vector<ll> score(m, 0LL);
        ll cs = 0;
        REP(j, n){
            if((bit >> j) & 1){
                cs += cost[j];
                REP(k, m) score[k] += v[j][k];
            }
        }
        bool ok = true;
        REP(i, m){
            ok &= score[i] >= x;
        }
        if(ok){
            chmin(ans, cs);
        }
    }

    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll

int n;
int ans=0;

void f(int m){
  if(m>n) return;

  int a=m;
  bool b[3]={};
  while(a){
    if(a%10==3) b[0]=true;
    if(a%10==5) b[1]=true;
    if(a%10==7) b[2]=true;
    a/=10;
  }

  if(b[0]&&b[1]&&b[2]) ans++;
  f(m*10+3);
  f(m*10+5);
  f(m*10+7);
}



signed main(){
  cin>>n;


  f(3);
  f(5);
  f(7);

  cout<<ans<<endl;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int a, b;

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

  if (a % 2 == b % 2) printf("%d\n", (a + b) / 2);
  else printf("%d\n", (a + b) / 2 + 1);
}


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

int main() {
  long n;
  cin >> n;
  vector<long> a(n);
  vector<long> b;
  for(long i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  for(long i=1;i*i<=a[0];i++) {
    if(a[0]%i==0) {
      b.push_back(i);
      if(i*i!=a[0]) b.push_back(a[0]/i);
    }
  }
  for(long i=1;i<n;i++) {
    long j=0;
    while(j<b.size()) {
      if(a[i]%b[j]==0) j++;
      else b.erase(b.begin()+j);
    }
  }
  sort(b.begin(),b.end());
  cout << b[b.size()-1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <numeric>
#include <iterator>
#include <stdio.h>
#define ll long long
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define sz(a) int((a).size())
#define all(a) (a).begin(),(a).end()
#define fr(i,p,n) for(int i=p;i<n;i++)
#define precise cout << std::setprecision(10) << std::fixed;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
//ll M=1000000007;
//double pi=3.1415926535898;
ll M=  998244353;
typedef pair<int, int> pairs;
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main()
{
    fastio; //precise;

    int T=1;
    //cin>>T;
    while(T--){
        int n,k;
        cin>>n>>k;
        int h[n],dp[n]={0};
        //multimap<int,int> m;
        fr(i,0,n){
            cin>>h[i];
        }
        fr(i,1,n){
            dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
            fr(j,1,k)
        if(i>=j+1) dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]));
        }
        cout<<dp[n-1]<<endl;


    }
     return 0;
}
//cout<<"YES"<<endl;
//cout<<"NO"<<endl;


Measured memory_bytes: 4424
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(lcm(a,b));
    }
    static long gcd(long m, long n) {
        long r;
        if(m < n) {
            long tmp = m;
            m = n;
            n = tmp;
        }
        while(n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
    static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
}


Measured memory_bytes: 21844
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)

string S;

bool isKaibun(string S){
	bool ret = true;
	rep(i, S.size()/2){
		ret &= (S[i] == S[S.size()-1-i]);
	}
	return ret;
}

signed main(){
	cin >> S;
	if(isKaibun(S) 
		&& isKaibun(S.substr(0, S.size()/2))
		&& isKaibun(S.substr(S.size()/2+1, S.size()/2))) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ri rd<int>
#define rl rd<LL>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
using namespace std;
typedef long long LL;
const LL O = 1e9 + 7;
const int maxN = 107;

template<class T> T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

LL _f[maxN], *f = _f+1;
LL A, B;

LL calc1(LL a, LL b) {
	if (a > A || b > B) return 0;
	return 1 + (B - b) / a;
}

LL calc2(LL a, LL b) {
	if (a > A || b > B) return 0;
	return 1 + (A - a) / b;
}

LL calc(LL a, LL b) {
	return (calc1(a, b) + calc2(b, a)) % O;
}

int main() {

	f[-1] = f[0] = 1;
	rep (i, 1, 100) f[i] = f[i-1] + f[i-2];

	rep (tcas, 1, ri()) {
		A = rl(), B = rl();
		if (A > B) swap(A, B);

		if (B == 1) {
			puts("1 1");
			continue;
		}

		int K;
		for (K = 0; f[K] <= A && f[K+1] <= B; ++K);

		if (K == 1) {
			printf("1 %lld\n", A * B % O);
			continue;
		}

		LL res = calc(f[K-1], f[K]);
		For (k, 1, K) {
			res += calc(f[K-1] + f[K-k-2] * f[k-1], f[K] + f[K-k-1] * f[k-1]);
		}
		printf("%d %lld\n", K, (res % O + O) % O);
	}

	return 0;
}


Measured memory_bytes: 3968
// In the name of Allah.
// We're nothing and you're everything.
// Ya Ali!

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 14;

int n, m;
char s[maxn], nxt[maxn];
int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> s;
    for(int i = 0; i < n; i++)
        s[i] -= '0';
    for(int i = 0; i < n - 1; ){
        int len = n - i;
        if(*max_element(s, s + len) == 0)
            break;
        if(count(s, s + len, 0) + count(s, s + len, *max_element(s, s + len)) == len){
            int rem = n - i - 1;
            while(__builtin_popcount(rem) > 1)
                rem--;
            i += rem;
            for(int j = 0; j < n - i; j++){
                // cerr << "f " << s[j] << ' ' << s[j + rem] << '\n';
                nxt[j] = s[j] ^ s[j + rem];
            }
        }
        else{
            for(int j = 0; j < len - 1; j++)
                nxt[j] = abs(s[j] - s[j + 1]);
            i++;
        }
        memcpy(s, nxt, maxn);
        // for(int j = 0; j < n - i - 1; j++)
        //     cerr << char(s[j] + '0');
        // cerr << '\n';
    }
    cout << char(s[0] + '0') << '\n';
}

Measured memory_bytes: 2176
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long int ll;

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

    if (K <= A) {
        A -= K;
        cout << A << ' ' << B << endl;
        return 0;
    }
    else if (K > A&& K <= A + B) {
        B -= K - A;
        cout << 0 << ' ' << B << endl;
    }
    else {
        cout << 0 << ' ' << 0 << endl;
    }
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll x,k,d;cin>>x>>k>>d;

  if(x<0)x*=-1;

  ll num=x/d;

  if(k<=num){
    cout<<abs(x-k*d)<<ENDL;
  }else{
    if(num%2==k%2){
      cout<<x%d<<ENDL;
    }else{
      cout<<abs(x%d-d)<<ENDL;
    }
  }
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<min(a,b)+min(c,d)<<endl;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, m, q, l[200000], r[200000], sum[501], ans[501][501];
vector<int> v[501];

int main() {
	cin >> n >> m >> q;
	inc(i, m) { cin >> l[i] >> r[i]; l[i]--; }
	
	inc(i, m) {
		v[l[i]].PB(r[i]);
		sum[r[i]]++;
	}
	inc(i, n) {
		int ss = 0;
		incII(j, i, n) { ss += sum[j]; ans[i][j] = ss; }
		for(auto && e: v[i]) { sum[e]--; }
	}
	
	inc(i, q) {
		int p, q;
		cin >> p >> q;
		p--;
		
		cout << ans[p][q] << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int N, K;
vector<int> H;

void input_init(void) {
	cin >> N >> K;
	H.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> H[i];
}

int solve(void) {
	sort(H.begin(), H.end());
	vector<int>::iterator itr;
	itr = lower_bound(H.begin(), H.end(), K);
	int idx = (int)distance(H.begin(), itr);
	return N - idx;
}

int main(void) {
	input_init();
	int ans = solve();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int dp[55][(1<<20)],n,m;
V<int> v[55],g[55];
int fa[55],de[55];
int er[25];
void dfs(int p){
	for(int i=0;i<v[p].size();i++){
		if(fa[p]!=v[p][i]){
			fa[v[p][i]]=p;
			de[v[p][i]]=de[p]+1;
			dfs(v[p][i]);
		}
	}
}
void get(int l,int r,int s){
	if(de[l]>de[r])swap(l,r);
	while(de[r]>de[l]){
		g[r].PB(s);r=fa[r];
	}
	while(l!=r){
		g[l].PB(s);l=fa[l];
		g[r].PB(s);r=fa[r];
	}
} 
signed main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	int x,y;
	cin>>n;
	FOR(i,2,n){
		cin>>x>>y;v[x].PB(y);v[y].PB(x);
	}
	fa[1]=-1;de[1]=1;
	dfs(1);
	cin>>m;
	er[0]=1;
	FOR(i,1,m)er[i]=er[i-1]*2;
	FOR(i,1,m){
		cin>>x>>y;get(x,y,i);
	}
//	FOR(i,1,n){
//		for(int j=0;j<g[i].size();j++)cout<<g[i][j]<<' ';
//		cout<<'\n';
//	}
	dp[1][0]=1;
	FOR(i,2,n){
		FOR(j,0,er[m]-1){
			dp[i][j]=dp[i][j]+dp[i-1][j];
			int t=j;
			for(int k=0;k<g[i].size();k++)t=t|(er[g[i][k]-1]);
			dp[i][t]=dp[i][t]+dp[i-1][j];
		}
	}
	cout<<dp[n][er[m]-1];
	RE 0;
}




Measured memory_bytes: 405760
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  string S;
  cin >> N >> S;
  int num = 0;
  int num2 = -1e9;
  
  for(int i = 0;i < N;++i){
    if(S[i] == 'I'){
      num++;
    }
    else{
      num--;
    }
    
    num2 = max(num2,num);
  }
  
  if(num2 < 0){
  cout << '0' << endl;
  }
  else{
    cout << num2 << endl;
  }
    
    
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int N = 1e5;
typedef long long ll;

int n, k;
ll t[N];

//! k辆最大运载量为p的卡车能装多少货物
int check(ll p)
{
    int i = 0;
    for(int j = 0; j < k; j++)
    {
        ll s = 0;
        while(s + t[i] <= p)
        {
            s += t[i++];
            if(i == n) return n;
        }
    }
    return i;
}

int solve()
{
    ll l = 0, r = 1e5 * 1e4;
    ll mid;
    while(r - l > 1)
    {
        mid = (l + r) >> 1;
        int v = check(mid);
        if(v >= n)
            r = mid;
        else
            l = mid;
    }
    return r;
}

int main(void)
{
    scanf("%d%d", &n, &k);
    for(int i = 0; i < n; i++) scanf("%d", &t[i]);
    ll ans = solve();
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 3988
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-10;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define Max(a,b) a=max(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
vector<pii> v[100010];
bool used[100010];
int r=0;
void dfs(int now,int s,int t){
    rep(i,0,v[now].size()){
        int ne=v[now][i].first,num=v[now][i].second;
        if(used[num])continue;
        if(ne==t)continue;
        if(ne==s){
            r=1;
            return;
        }
        used[num]=true;
        dfs(ne,s,t);
        used[num]=false;
    }
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m;cin>>n>>m;
    int cnt[n+1];
    fill(cnt,cnt+n+1,0);
    
    rep(i,0,m){
        int a,b;cin>>a>>b;
        cnt[a]++;cnt[b]++;
        v[a].push_back({b,i});
        v[b].push_back({a,i});
    }
    int ma=0;
    rep(i,1,n+1){
        if(cnt[i]%2){
            cout<<"No"<<endl;
            return 0;
        }
        Max(ma,cnt[i]);
    }
    if(ma>=6){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(ma==2){
        cout<<"No"<<endl;
        return 0;
    }
    vector<int> w;
    rep(i,1,n+1){
        if(cnt[i]==4)w.push_back(i);
    }
    if(w.size()==1){
        cout<<"No"<<endl;
        return 0;
    }
    if(w.size()>=3){
        cout<<"Yes"<<endl;
        return 0;
    }
    fill(used,used+m,false);
    dfs(w[0],w[0],w[1]);
    if(r)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}






Measured memory_bytes: 7808
#import 
n=input()
#=int(input())
#=map(int,input().split())
#=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

sum = 0
for i in range(len(n)):
    sum += int(n[i])
    sum %= 9
if sum == 0:
    print('Yes')
else:
    print('No')

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

#define ll long long int
#define Mod 1000000007

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    cout<<fixed<<setprecision(8)<<double(((n+1)/2)/(double)n);
    return 0;
}


Measured memory_bytes: 256
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,k=n1()

c=1
while True:
    if n<k**c:
        print(c)
        break
    else:
        c+=1

Measured memory_bytes: 3060
import sys

a, b, c, d = map(int, sys.stdin.readline().split())

def main():
  dx = c - a
  dy = d - b
  res = 'U' * dy + 'R' * (dx + 1) + 'D' * (dy + 1) + 'L' * (dx + 1)
  res += 'UL'
  res += 'U' * (dy + 1) + 'R' * (dx + 1) + 'D' * (dy + 1) + 'L' * dx
  print(res)
   
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
program prediction_and_restriction
  implicit none
  integer :: n, k, r, s, p, i, x = 0
  character(100000) :: t
  read(*,*) n, k
  read(*,*) r, s, p
  read(*,*) t
  do i = k+1, n
    if (t(i:i) == t(i-k:i-k)) then
      t(i:i) = 'x'
    end if
  end do
  do i = 1, n
    select case (t(i:i))
    case ('r')
      x = x+p
    case ('s')
      x = x+r
    case ('p')
      x = x+s
    end select
  end do
  write(*,'(i0)') x
end program prediction_and_restriction

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

//begin( Union-Find )//

const int MAX_N = 10000000;


//親の番号
int par[MAX_N];
//ノードの高さ
int rk[MAX_N];

//n要素で初期化
void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    rk[i] = 0;
  }
}

//木の根を求める
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

//xとyの属する集合を併合
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  
  if (rk[x] < rk[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rk[x] == rk[y]) rk[x]++;
  }
}

//xとyが同じ集合に属するか否か
bool same(int x, int y) {
  return find(x) == find(y);
}

//end( Union-Find )//


int main() {
  int N, M;
  cin >> N >> M;
  int p[N];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    p[i]--;
  }
  
  init(N);
  
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    unite(x, y);
  }
  
  vector<int> v[N];
  set<int> sp[N];
  set<int> f;
  
  for (int i = 0; i < N; i++) {
    v[find(i)].push_back(i);
    sp[find(i)].insert(p[i]);
    f.insert(find(i));
    
  }
  
  int ans = 0;
  for (auto it = f.begin(); it != f.end(); it++) {
    for (int i = 0; i < v[*it].size(); i++) {
      if (sp[*it].find(v[*it].at(i)) != sp[*it].end()) {
        ans++;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 22656
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
long long A[100000];
long long MOD = 1000000007;
const int MAX = 200001;
long long fac[MAX];
long long finv[MAX];
long long inv[MAX];
 
void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  comb_init();
  int N;
  int K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  sort(A, A + N);
  long long ans = 0;
  for(int i = 0; i < N - K + 1; i++){
    ans = (ans - (comb(N - 1 - i, K - 1) * ((A[i] + MOD) % MOD)) % MOD + MOD) % MOD;
  }
  for(int i = N - 1; i >= K - 1; i--){
    ans = (ans + (comb(i, K - 1) * ((A[i] + MOD) % MOD) % MOD)) % MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct SCC {
public:
    int num;

    SCC(vector<vector<int>>& G) : G(G), comp(G.size(), -1), visited(G.size()), G_rev(G.size()) {
        for (int u = 0; u < G.size(); u++) {
            for (int v : G[u]) G_rev[v].push_back(u);
        }

        for (int v = 0; v < G.size(); v++) dfs(v);
        reverse(order.begin(), order.end());
        num = 0;
        for (int v : order) if (comp[v] == -1) rdfs(v, num++);
    }

    int operator[](int k) const {
        return comp[k];
    }

private:
    vector<vector<int>> G, G_rev;
    vector<int> comp, order;
    vector<bool> visited;

    void dfs(int u) {
        if (visited[u]) return;
        visited[u] = true;
        for (int v : G[u]) dfs(v);
        order.push_back(u);
    }

    void rdfs(int u, int c) {
        if (comp[u] != -1) return;
        comp[u] = c;
        for (int v : G_rev[u]) rdfs(v, c);
    }
};

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

    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
    }
    SCC scc(G);
    cout << scc.num << "\n";
    vector<vector<int>> v(scc.num);
    for (int i = 0; i < N; i++) v[scc[i]].push_back(i);
    for (int i = 0; i < scc.num; i++) {
        cout << v[i].size();
        for (int j : v[i]) cout << " " << j;
        cout << "\n";
    }
}

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


const int N=1e5+1;
int dp[N];
vector<int>graph[N];
bool visited[N];
int v,e;

void dfs(int x){

 visited[x]=true;

 for(int i=0;i<graph[x].size();i++){
    if(!visited[graph[x][i]])
        dfs(graph[x][i]);
      dp[x]=max(dp[x],1+ dp[graph[x][i]]);
 }
}



int main(){
cin>>v>>e;
for(int i=0;i<e;i++){
    int x,y;
    cin>>x>>y;
    graph[x].push_back(y);
}

for(int i=1;i<=v;i++){
    if(!visited[i]){
        dfs(i);
    }
}

int ans=INT_MIN;
for(int i=1;i<=v;i++){
ans=max(ans,dp[i]);
}

cout<<ans<<endl;

return 0;
}


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

int main() {
	int N, Q;
	cin >> N >> Q;
	vector<tuple<int, int, int>>stx(N);
	for (int n = 0;n<N;++n) {
		cin >> get<1>(stx[n]) >> get<2>(stx[n]) >> get<0>(stx[n]);
	}
	sort(stx.begin(), stx.end());

	set<pair<int, int>> d;
	for (int i = 0, x; i < Q; ++i) {
		cin >> x;
		d.emplace(x, i);
	}

	vector<long long>tm(Q, -1);
	for (int i = 0;i<N;++i) {
		auto first = d.lower_bound(make_pair(get<1>(stx[i]) - get<0>(stx[i]), 0));
		auto end = d.upper_bound(make_pair(get<2>(stx[i]) - get<0>(stx[i]) - 1, Q));

		for (auto it = first; it != end; ++it) {
			tm[it->second] = get<0>(stx[i]);
		}
		d.erase(first, end);
	}
	for (int i = 0; i < Q; ++i) cout << tm[i] << '\n';
	return 0;
}

Measured memory_bytes: 16348
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int main(void)
{
	int H,W,h,w,i,j;
	scanf("%d%d%d%d",&H,&W,&h,&w);
	if(H%h==0&&W%w==0){
		puts("No");
		return 0;
	}
	puts("Yes");
	FOR(i,0,H){
		FOR(j,0,W){
			if(i%h==0&&j%w==0) printf("%d",INF-1);
			else if((i+1)%h==0&&(j+1)%w==0) printf("%d",-INF);
			else putchar('0');
			printf("%c",j==W-1?'\n':' ');
		}
	}
	return 0;
}

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

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)round(x))<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

bool isFinished(vector<int> v) {
  for (int i = 0; i < v.size(); i++) {
    if (v[i] != 0) {
      return false;
    }
  }
  return true;
}

int solve(int n, vector<int> v) {
  if (isFinished(v)) {
    return 0;
  }

  int res = 0;
  for (int i = 1; i < (1 << n); i++) {
    vector<int> nv = v;
    bool isNG = false;
    for (int j = 0; j < n; j++) {
      if ((i & (1 << j)) > 0) {
        if (nv[j] == 0) {
          isNG = true;
          break;
        }
        nv[j]--;
      }
    }
    if (isNG) {
      continue;
    }

    int tmp = solve(n, nv);
    if (tmp == 0) {
      res = 1;
      break;
    }
  }

  return res;
}

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

  /*
  int n = 3;
  int m = 8;
  vector<int> v(n);
  
  for (int i = 1; i <= m; i++) {
    v[0] = i;
    cout<<"i="<<i<<endl;
    for (int j = i; j <= m; j++) {
      cout<<j<<": ";
      v[1] = j;
      for (int k = j; k <= m; k++) {
        v[2] = k;
        cout << solve(n, v);
      }
      cout << endl;
    }
    cout << endl;
  }
  */

  int n;
  while (cin >> n) {
    bool isFirst = false;
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      if (a % 2 != 0) {
        isFirst = true;
      }
    }
    cout << (isFirst ? "first" : "second") << endl;
  }
}


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



int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
	float n, t, a;
	cin>>n>>t>>a;
	vector<float> ele(n);
	float closestTemp = 1e5+9;
	float avgTemp = 0;
	int ans = 0;
	for(int i =0; i < n; i++) {
		cin>>ele[i];
		avgTemp = t - (ele[i] * 0.006);
		if(abs(avgTemp - a) < closestTemp) {
			ans = i;
			closestTemp = abs(avgTemp - a);
		}
	}

	cout<<ans + 1;



	return 0;		
}


//1011




Measured memory_bytes: 3760
#n , m , l = map(int , input().split())

# list_n = list(map(int , inpuut().split()))<Paste>

#n = input()
# list = [input() for i in range(N)

#list = [[i for i in range(N)] for _ in range(M)]

A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())

for i in range(N):
    B = int(input())
    for j in range(3):
        if A1[j] == B:
            A1[j] = 0
        if A2[j] == B:
            A2[j] = 0
        if A3[j] == B:
            A3[j] = 0

if sum(A1) == 0:
    print("Yes")
    exit()
if sum(A2) == 0:
    print("Yes")
    exit()
if sum(A3) == 0:
    print("Yes")
    exit()
for i in range(3):
    if A1[i]+A2[i]+A3[i] == 0:
        print("Yes")
        exit()
if A1[0] + A2[1] + A3[2] == 0:
    print("Yes")
    exit()
if A1[2] + A2[1] + A3[0] == 0:
    print("Yes")
    exit()
print("No")


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

int main() {
	int N, M, C;
	int answer = 0;
	cin >> N >> M >> C;
	vector<int>B(M);
	rep(i, M) {
		cin >> B.at(i);
	}
	vector<vector<int>>A(N, vector<int>(M));
	rep(i, N) {
		rep(j, M) {
			cin >> A.at(i).at(j);
		}
	}
	int count = 0;
	rep(i, N) {
		count = 0;
		rep(j, M) {
			count += A.at(i).at(j) * B.at(j);
		}
		if (count + C > 0) {
			answer++;
		}
	}
	cout << answer << endl;
}

Measured memory_bytes: 256