akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 998244353;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

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

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}



int main(){
  nCrprep();
  
  ll n,m,k; cin >> n >> m >> k;
  vl mpow(n+1); mpow[0] = 1;
  
  rep(i,n){
    mpow[i+1] = mod(mpow[i]*(m-1));
  }

  
  ll sum = 0;
  
  rep(i,k+1){
    sum += mod(mod(m*mpow[n-i-1])*nCr(n-1,i));
    sum = mod(sum);
  }
  
  cout << sum << endl;
  
}


Measured memory_bytes: 51848
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n+1); rep(i, n+1) cin >> A[i];
  auto no = [&]() {
    cout << -1 << "\n";
    exit(0);
  };
  vector<ll> mn(n+2), mx(n+2);
  mn[0] = 1, mx[0] = 1;
  rep(i, n+1) {
    if(i==n) {
      if(mn[i]<=A[i] && A[i]<=mx[i]) {
        break;
      } else {
        no();
      }
    }
    if(mx[i]-A[i]<0) no();
    mn[i+1] = max(mn[i]-A[i], 0LL);
    mx[i+1] = min((mx[i]-A[i])*2, longinf);
  }
  ll ans = 0;
  ll tmp = A[n];
  rrep(i, n+1) {
    ans += tmp;
    if(i) tmp = min(mx[i-1], tmp+A[i-1]);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 5752
N = int(input())
A=list(map(int, input().split()))
ls = [0]*9
for i in range(N):
    if 1 <= A[i] <= 399:
        ls[0] += 1
    elif 400 <= A[i] <= 799:
        ls[1] += 1
    elif 800 <= A[i] <= 1199:
        ls[2] += 1
    elif 1200 <= A[i] <= 1599:
        ls[3] += 1
    elif 1600 <= A[i] <= 1999:
        ls[4] += 1
    elif 2000 <= A[i] <= 2399:
        ls[5] += 1
    elif 2400 <= A[i] <= 2799:
        ls[6] += 1
    elif 2800 <= A[i] <= 3199:
        ls[7] += 1
    else:
        ls[8] += 1
c = 0
for i in range(8):
    if ls[i]:
        c += 1
m = c if c > 0 else int(ls[-1]>0)
M = c + ls[-1]
print(m, M)

Measured memory_bytes: 62068
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR(i,k,n) for(ll i=(k);(k)<(n)?i<(n):i>(n);(k)<(n)?i+=1:i-=1)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int INF = 1<<29;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< ll > vi;
typedef vector< vi > vvi;
typedef pair< ll,ll > ii;
#define F first
#define S second
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define sz(a) ll((a).size())
#define all(o) (o).begin(), (o).end()
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
#define TR(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
template<class T> T** arr2D(int n,int m,T init){
    T** mat=new T*[n];
    FOR(i,0,n){
        mat[i]=new T[m];
        FOR(j,0,m){
            mat[i][j]=init;
        }
    }
    return mat;
}
template<class T> void initialise(T** mat,T init,int n,int m){
    FOR(i,0,n){
        FOR(j,0,m){
            mat[i][j]=init;
        }
    }
}
template<class T> void destroy(T** mat,int n,int m){
    FOR(i,0,n){
        delete[] mat[i];
    }delete[] mat;
}
const int MOD = 1000000007;
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }

/////////////////////////////////////////////////////////////////////
void solve(){
    int N,M;
    cin>>N>>M;
    vector<string> mat(N);
    vector<vector<ll>> ways(N,vector<ll>(M,0));
    ways[0][0]=1;
    FOR(i,0,N){
        cin>>mat[i];
    }
    FOR(i,0,N){
        FOR(j,0,M){
            if(mat[i][j]=='#')continue;
            else if(mat[i][j]=='.'){
                if(i-1>=0){
                    ways[i][j]+=ways[i-1][j];
                    if(ways[i][j]>=MOD) ways[i][j]-=MOD;
                }
                if(j-1>=0){
                    ways[i][j]+=ways[i][j-1];
                    if(ways[i][j]>=MOD) ways[i][j]-=MOD;
                }
            }
        }
    }
    cout<<ways[N-1][M-1];
}
int main()
{
    fastio
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
    #endif
    solve();
    return 0;
}


Measured memory_bytes: 12472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<string> s(N);
    vector<ll> t(N);
    rep(i,N) cin >> s[i] >> t[i];
    string X; cin >> X;
    bool ok=false;
    ll ans=0;
    rep(i,N){
        if (ok) ans+=t[i];
        if (s[i]==X) ok=true;
    }
    cout << ans << endl;
}

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

public class Main {

    int H, W;

    void run() {
        Scanner sc = new Scanner(System.in);
        H = sc.nextInt();
        W = sc.nextInt();
        int[][] var = new int[H + 1][W + 1];
        int[][] hol = new int[W + 1][H + 1];
        boolean[][] ng = new boolean[H + 1][W + 1];
        for (int i = 1; i <= H; i++) {
            String s = sc.next();
            for (int j = 1; j <= W; j++) {
                var[i][j] = s.charAt(j - 1) == '#' ? 1 : 0;
                hol[j][i] = s.charAt(j - 1) == '#' ? 1 : 0;
                ng[i][j] = s.charAt(j - 1) == '#';
            }
        }
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <=W; j++) var[i][j] += var[i][j - 1];
        }
        for (int i = 1; i <= W; i++) {
            for (int j = 1; j <=H; j++) hol[i][j] += hol[i][j - 1];
        }

        int ans = 0;
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) if (!ng[i][j]){
                int lv = lowerBound(var[i], var[i][j]);
                int uv = upperBound(var[i], var[i][j]);
                int lh = lowerBound(hol[j], hol[j][i]);
                int uh = upperBound(hol[j], hol[j][i]);
                ans = Math.max(ans, uv - lv + 1 + uh - lh - 4);
//                debug(i, j, uv - lv + 1, uh - lh + 1);
            }
        }

//        debug(var);
//        debug(hol);
        System.out.println(ans);
    }

    public static int lowerBound(int[] array, int value) {
        int left = -1;
        int right = array.length;
        while (right - left > 1) {
            int middle = (right + left) / 2;
            if (array[middle] >= value) {
                right = middle;
            } else {
                left = middle;
            }
        }
        return right;
    }

    public static int upperBound(int[] array, int value) {
        int left = -1;
        int right = array.length;
        while (right - left > 1) {
            int middle = (right + left) / 2;
            if (array[middle] > value) {
                right = middle;
            } else {
                left = middle;
            }
        }
        return right;
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 91792
text = list(input())

text_1, text_2 = list(text), list(text)
for i in range(int(len(text)/2)):
    text_1.pop(i)
    text_2.pop(i+1)
if len(text) % 2 == 1:
    text_1.pop(len(text_1)-1)

str_1, str_2 = "", ""
for i in range(len(text_1)):
    str_1 += str(text_1[i])
for i in range(len(text_2)):
    str_2 += str(text_2[i])

if str_2.find('L') == -1 and str_1.find('R') == -1:
    print('Yes')
else:
    print('No')

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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/




signed main()
{
	int h,w; cin >> h >> w;
	string s;
	while(cin >> s){
		cout << s << endl;
		cout << s << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define se second
#define fi first
#define pb push_back
#define cn cout<<"\n"
#define rep(i,a,b) for(int i = a; i < b; i++)
#define repr(i,a,b) for(int i = a; i >= b; i--)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

#define _ ios::sync_with_stdio(0); cin.tie(0);

#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>
#define flush fflush(stdout)

const int INF = 1e8;
const ll MOD = 1e9 + 7;

using namespace std;

int l[100005], r[100005], v[100005];

int main(){
	_

	int t = 1, n;

	cin>>n;

	rep(i, 1, n + 1){
		cin>>v[i];
		l[i] = __gcd(v[i], l[i - 1]);
	}

	repr(i, n, 1)
		r[i] = __gcd(v[i], r[i + 1]);

	ll ans = 0;
	rep(i, 1, n + 1){
		//cout<<l[i - 1]<<" - "<<r[i+1]; cn;
		ll aux = __gcd(l[i - 1], r[i + 1]);
		ans = max({aux, ans});
	}

	cout<<ans; cn;

	return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	map<int, int> dmap;
	int N, M;
	cin >> N >> M;
	int s, c;
	bool ok = true;
	rep(i, 0, M)
	{
		cin >> s >> c;
		s = N - s + 1;
		if (dmap.find(s) != dmap.end() && dmap[s] != c || N!=1&&s == N && c == 0)ok = false;
		dmap[s] = c;
	}
	if (N!=1&&dmap[N] == 0)dmap[N] = 1;

	if (ok)
	{
		int ans = 0;
		for (auto p : dmap)
		{
			int d = p.second;
			rep(i, 0, p.first - 1)
			{
				d *= 10;
			}
			ans += d;
		}
		cout << ans << endl;
	}
	else
	{
		cout << "-1" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000007
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;


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

int ans =1;

while(n--)
{
    ans = min(2*ans,ans+k);
}
cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

struct UnionFind {
	std::vector<int> data;
	
	UnionFind(int n) {
		data.assign(n, -1);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if(x == y) return false;
		if(data[x] > data[y]) std::swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	int find(int k) {
		if(data[k] < 0) return k;
		return find(data[k]);
	}
	int size(int k) {
		return -data[find(k)];
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main() {
	i64 n, m; scanf("%lld%lld", &n, &m);
	std::vector<std::pair<int, int>> vec(m);
	for(int i = 0; i < m; i++) scanf("%d%d", &vec[i].first, &vec[i].second);
	reverse(begin(vec), end(vec));
	
	UnionFind uf(n);
	i64 ans = n * (n - 1) / 2LL;
	std::vector<i64> latte;
	for(int i = 0; i < m; i++) {
		int x = vec[i].first, y = vec[i].second; x--; y--;
		
		if(uf.same(x, y)) latte.push_back(ans);
		else {
			i64 A = uf.size(x), B = uf.size(y);
			latte.push_back(ans);
			ans -= A * B;
			uf.unite(x, y);
		}
	}
	reverse(begin(latte), end(latte));
	for(auto v: latte) printf("%lld\n", v);
	return 0;
}


Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <math.h>
using namespace std;

class Summation {
public:
	void set_string(string S);
	void plusminus(int cnt, string ans_str, unsigned long long ans_ull);
	string get_inistr();
	unsigned long long get_iniull();
	vector<string> get_ans();
private:
	string num[4];
	string ini_str;
	unsigned long long ini_ull = 0;
	vector<string> ans;
};

void Summation::set_string(string S) {
	for (int i = 0; i < 4; i++) {
		num[i] = S.substr(i, 1);
	}
	ini_str = num[0];
	ini_ull = stoull(num[0]);
}

void Summation::plusminus(int cnt, string ans_str, unsigned long long ans_ull) {

	if (cnt <= 3) {
		// + �̏ꍇ
		string str = ans_str;
		unsigned long long ull = ans_ull;
		str += "+";
		str += num[cnt];
		ull += stoull(num[cnt]);
		plusminus(cnt + 1, str, ull);

		// - �̏ꍇ
		str = ans_str;
		ull = ans_ull;
		str += "-";
		str += num[cnt];
		ull -= stoull(num[cnt]);
		plusminus(cnt + 1, str, ull);
	}
	else {
		if (ans_ull == 7) {
			string str = ans_str;
			str += "=";
			str += "7";
			ans.push_back(str);
		}
	}
}

string Summation::get_inistr() {
	return ini_str;
}

unsigned long long Summation::get_iniull() {
	return ini_ull;
}

vector<string> Summation::get_ans() {
	return ans;
}

int main() {

	string S;
	cin >> S;

	Summation sm;
	sm.set_string(S);
	sm.plusminus(1, sm.get_inistr(), sm.get_iniull());

	vector<string> ans = sm.get_ans();

	cout << ans[0] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long long MIN (long long x, long long y) {
  if (x > y) return y;
  else return x;
}
 
int main() {
  
  long long INF = 100000000 + 100;
  
  // 情報を取り込む
  
  int N, M;
  cin >> N >> M;
  
  vector<int> a(M);
  vector<int> b(M);
  vector<vector<int>> c(M);
  
  for (int i = 0; i < M; i++) {
    cin >> a[i];
    cin >> b[i];
    
    for (int j = 0; j < b[i]; j++) {
      int p;
      cin >> p;
      c[i].push_back(p - 1);
    }
  }
  
  // dp
  
  vector<vector<long long>> dp(M + 1, vector<long long>( (1 << N) ) );
  
  // 0個のカギで開けることができる箱は存在しない
  
  for (long long bit = 1; bit < (1<<N); bit++) {
    dp[0][bit] = INF;
  }
  
  // 漸化式部分
  
  for (int i = 0; i < M; i++) {
    
    for (long long bit = 0; bit < (1<<N); bit++) {
      
      long long BIT = bit;
      for (int j = 0; j < b[i]; j++) {
        BIT &= ~(1 << c[i][j]);
      }
      
      dp[i + 1][bit] = MIN(dp[i][bit], dp[i][BIT] + a[i]);
      
    }
    
  }
  
  // 出力
  
  if (dp[M][(1 << N) - 1] == INF) cout << -1 << endl;
  
  else cout << dp[M][(1 << N) - 1] << endl;
}

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

const int MAX_N = 1e5;
int e[MAX_N+5], ss[MAX_N+5];

int main(){
    int q; cin >> q;

    for(int i=2;i<=MAX_N;i++){
        if(e[i] != 0) continue;
        for(int j=2*i;j<=MAX_N;j+=i) e[j]++;
    }

    for(int i=3;i<=MAX_N;i++){
        ss[i+1] = ss[i];
        if(i % 2 && e[i] == 0 && e[(i+1)/2] == 0) ss[i+1]++;
    }

    for(int i=0;i<q;i++){
        int l, r; cin >> l >> r;
        printf("%d\n", ss[r+1]-ss[l]);
    }

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, k;
    cin >> n >> k;
    int p;
    REP(i,n){
        if (in() == 1){
            p = i;
        }
    }
    k--;
    int ans = (n - 1 + k - 1) / k;
    cout << ans << endl;
    return 0;
}


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

//Union Find
struct UnionFind {
  vector<int> par; // 親ノード
  vector<int> rank; // ランク

  UnionFind(int n = 1) {
    init(n);
  }
  void init(int n = 1) {
    par.resize(n); rank.resize(n);
    for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
  }
  int root(int x) {
    if (par[x] == x) {
    return x;
  }
    else {
      int r = root(par[x]);
      return par[x] = r;
    }
  }
  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) ++rank[x];
    par[y] = x;
    return true;
  }
};

int main() {
  int N,M,x,y;
  cin >> N >> M;
  vector<int> p(N);
  rep(i,N) cin >> p[i];
  UnionFind uf(N+1);
  rep(i,M) {
    cin >> x >> y;
    uf.merge(x,y);
  }

  int ans=0;
  rep2(i,1,N+1) {
    int t = p[i-1];
    if (uf.issame(t,i)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

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

      int min = Math.min(b,a*n);

      System.out.println(min);
  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

bool equal(vector <ll> a, vector <ll> b){
    REP(i, a.size()){
        if (a[i] != b[i]){
            return 0;
        }
    }
    return 1;
}


int main(void){
    ll n; cin >> n;
    vector <ll> as;
    REP(i, n){
        ll a; cin >> a;
        as.push_back(a);
    }
    vector <ll> bs;
    REP(i, n){
        ll b; cin >> b;
        bs.push_back(b);
    }
    vector <ll> su;
    REP(i, n){
        su.push_back(i+1);
    }
    ll cnt_a;
    ll cnt_b;
    ll cnt = 0;
    if (equal(su, as)){
        cnt_a = cnt;
    }
    if (equal(su, bs)){
        cnt_b = cnt;
    }
    while (next_permutation(su.begin(), su.end())){
        cnt++;
        if (equal(su, as)){
            cnt_a = cnt;
        }
        if (equal(su, bs)){
            cnt_b = cnt;
        }
    }
    cout << abs(cnt_b-cnt_a) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF ((ll)1<<31)-1
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int gcd(int a,int b){
	if(!a)return b;
	return gcd(b%a,a);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
int n,m,a,b,suma,sumb;
signed main(){
	cin>>n>>m;
	rep(i,n){
		cin>>a;
		suma+=a;
	}
	rep(i,m){
		cin>>b;
		sumb+=b;
	}
	cout<<suma*sumb<<endl;
    return 0;
}




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

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let w: String = sc.read();
    let w = w.to_uppercase();
    let mut cnt = 0;
    loop {
        let s: String = sc.read();
        if &s == "END_OF_TEXT" {
            break;
        }
        let s = s.to_uppercase();
        if w == s {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}



Measured memory_bytes: 5044
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	int ans = 0;
	while (n--) {
		int a;
		scanf("%d", &a);
		while (a % 2 == 0) {
			a /= 2;
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define Nmax 105
#define Kmax 100005

const ll MOD = 1e9 + 7;

using namespace std;

ll n, k, dp[Kmax], a[Nmax], sum[Kmax], nextSum[Kmax];

void read()
{
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
}

void solve()
{
    for (int j = 0; j <= k; ++j) {
        sum[j] = 1;
    }

    nextSum[0] = 1;
    dp[0] = 1;

    for (ll nr = 1; nr <= n; ++nr) {
        for (ll j = 1; j <= k; ++j) {
            if (j <= a[nr]) {
                dp[j] = sum[j];
            }
            else {
                dp[j] = sum[j] - sum[j - a[nr] - 1];
                if (dp[j] < 0)
                    dp[j] += MOD;
            }
            nextSum[j] = (nextSum[j - 1] + dp[j]) % MOD;
        }

        for (int j = 0; j <= k; ++j) {
            sum[j] = nextSum[j];
        }
    }

    cout << dp[k] << "\n";
}


int main()
{
    read();
    solve();
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if ((B - 1) % (A - 1) == 0) {
    cout << (B - 1) / (A - 1) << endl;
  }
  else {
  cout << (B - 1) / (A - 1) + 1 << endl;
  }
}

Measured memory_bytes: 256
sx,sy,gx,gy=map(int,input().split())
s,t,u,v='','','DR','UL'
for i in range(gx-sx):
  s+='R'
  t+='L'
  u+='R'
  v+='L'
u+='U'
v+='D'
for i in range(gy-sy):
  s+='U'
  t+='D'
  u+='U'
  v+='D'
print(s+t+u+'L'+v+'R')

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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define fi first
#define se second
#define pb push_back
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 1e5 + 10;
const int oo = 1e18;

int n, a, b;

signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false); cout.tie(0);
    string x, y, z;
    cin >> n >> x >> y >> z;

    int sum = 0;
    FOR(i, 0, n - 1)    {
        set<char> st;
        st.insert((char)(x[i]));
        st.insert((char)(z[i]));
        st.insert((char)(y[i]));
        if(st.size() == 3) sum += 2;
        if(st.size() == 2) sum += 1;
    }
    return cout << sum, 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
    using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

ll n,a;
ll x[51]={};
ll dp[51][51][2503];

ll dfs(int i, int cnt, int sum){
    if(dp[i][cnt][sum]!=-1)return dp[i][cnt][sum];
    ll res=0;
    if (i == n){
        if(cnt != 0){
            return (double)sum/cnt == (double)a;
        }else{
            return 0;
        }
    }else{
        res = dfs(i + 1, cnt, sum) + dfs(i + 1, cnt + 1, sum + x[i]);
    }

    return dp[i][cnt][sum] = res;
}

int main(){
    memset(dp, -1, sizeof(dp));
    cin>>n>>a;
    for(int i=0; i<n; i++)cin>>x[i];
    cout<<dfs(0,0,0)<<endl;
}

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

int main() {
  int64_t n,a,b;
  cin>>n>>a>>b;
  int64_t c=0;
  if(a!=0){
  if(n%(a+b)<=a){
    c=n%(a+b);
  }
  else{
    c=a;
  }
  cout<<((n/(a+b))*a)+c<<endl;
  }
  else{
    cout<<"0"<<endl;
  }
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;





int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);


	int N, M;

	cin >> N >> M;

	cout << (N == M ? "Yes\n" : "No\n");


	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/foreach.hpp>
using namespace std;
//#define pi 2*asin(1.0)
#define MAX 10000000
#define MOD 1000000007
#define _GLIBCXX_DEBUG
 
vector<long> fac(MAX);
vector<long> finv(MAX);
vector<long> inv(MAX);
vector<long> Primelist;
//template functions
/////////////////////////
void Prinit(){
long PR=10000001;
vector<long> P(PR,0);
for(long i=2;i*i<PR;i++){
    if(P.at(i)==0){
        long j=i;
      j+=i;
        while(j<PR){
            P.at(j)=1;
             j+=i;         
        }
    }

}
for(long i=2;i*i<PR;i++){//Primelist.size()=446
    if(P.at(i)==0){
        Primelist.push_back(i);
    }
}
}

void Cominit(){
  fac.at(0)=fac.at(1)=1;
  finv.at(0)=finv.at(1)=1;
  inv.at(1)=1;
  for(long i=2;i<MAX;i++){
      fac.at(i)=(fac.at(i-1)*i)%MOD;
      inv.at(i)=MOD-inv.at(MOD%i)*(MOD/i)%MOD;
      finv.at(i)=finv.at(i-1)*inv.at(i)%MOD;
  }
}

long facComb(long N,long M){// nCm%
if(N<M) return 0;
if(N<0||M<0) return 0;
return fac.at(N)*(finv.at(M)*finv.at(N-M)%MOD)%MOD;
}

long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}

long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}

long GCM(long A,long B){
            long W,r;
    if(A<B){

        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}

long upDiv(long a,long b){
  return (a+b-1)/b;
}

long strtolong(string str){
istringstream ss;
ss=istringstream(str);
long num;
ss>>num;
return num;
}

long chartolong(char ch){
long num;
num=ch-'0';
return num;
}

string longtostr(long N){
    string str;
    str=to_string(N);
    return str;
}









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


//Answer


int main() {
double pi=2*asin(1.0);
double a,b,x,s,ans;
cin>>a>>b>>x;
if(x>=a*a*b/2){
s=2*(a*a*b-x)/(a*a);
ans=(atan2(s,a)*180);
cout<< fixed << setprecision(10) << ans/pi<<endl;
}else{
s=2*x/(b*a);
ans=90-(atan2(s,b)*180/pi);
cout<< fixed << setprecision(10) << ans<<endl;;
}
}




Measured memory_bytes: 237532
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n, a, b;
    cin >> n >> a >> b;
    if((b - a) % 2) {
        cout << min(a, n - b + 1) + (b - a - 1) / 2 << endl;
    }
    else {
        cout << (b - a) / 2 << endl;
    }
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

using namespace std;

int main(){
	long long n, k;
	double resp = 0;
	double cont2[64];
	cont2[0] = 1;
	for(int i = 1; i < 64; i++)
		cont2[i] = cont2[i - 1] / 2.0;
	scanf("%lld %lld", &n, &k);
	for(int i = 1; i <= n; i++){
		int cont = 0;
		long long curr = i;
		while(curr < k){
			cont++;
			curr *= 2;
		}
		resp += (1.0 / n) * cont2[cont];
	}
	printf("%.17lf\n", resp);
	return 0;
}

Measured memory_bytes: 256
mes = {11:"a",12:"b",13:"c",14:"d",15:"e"
    ,21:"f",22:"g",23:"h",24:"i",25:"j"
    ,31:"k",32:"l",33:"m",34:"n",35:"o"
    ,41:"p",42:"q",43:"r",44:"s",45:"t"
    ,51:"u",52:"v",53:"w",54:"x",55:"y"
    ,61:"z",62:".",63:"?",64:"!",65:" "}

while True:
    try:
        s = input()
    except:
        break
    ss = ""
    for i in range(0, len(s), 2):
        if len(s) % 2 == 1:
            ss = "NA"
            break
        if int(s[i:i+2]) in mes:
            ss+=mes[int(s[i:i+2])]
        else:
            ss = "NA"
            break
    print(ss)


Measured memory_bytes: 5604
a = map(int,raw_input().split())
#a = raw_input()

if a[0]*a[1] == a[2]*a[3]:
        print a[0]*a[1]
elif a[0]*a[1] > a[2]*a[3]:
        print a[0]*a[1]
else:
        print a[2]*a[3]

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

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


ll pw(ll a, ll b, ll MOD) {
	ll ans = 1;
	a %= MOD;
	while (b) {
		while (!(b & 1))
			a = (a * a) % MOD, b >>= 1;
		ans = (ans * a) % MOD, --b;
	}
	return ans;
}


ll getphi(ll m) {
	ll ans = 1;
	for (ll i = 2; i * i <= m; ++i) {
		if (m % i != 0)
			continue;
		ans *= (i - 1);
		m /= i;
		while (m % i == 0)
			m /= i, ans *= i;
	}
	if (m != 1)
		ans *= (m - 1);
	return ans;
}

ll gcd(ll a, ll b) {
	while (b) {
		ll q = a % b;
		a = b;
		b = q;
	}
	return a;
}

void egcd(ll a, ll b, ll &x, ll &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return;
	}
	ll x1 = 0, y1 = 0;
	egcd(b, a % b, x1, y1);
	x = y1;
	y = x1 - (a / b) * y1;
}

ll get(ll a, ll m) {
	if (m == 1) {
		return 100;
	}
	ll phi = getphi(m);
	ll d = gcd(phi, m);
	ll x = get(a, d);
	ll go = pw(a, x, m) - x;
	go %= m;
	if (go < 0)
		go += m;
	ll a1 = 0, b = 0;
	egcd(m, phi, a1, b);
	b *= (go / d);
	b %= m;
	if (b < 0)
		b += m;
	x += b * phi;
	if (x - phi * m >= 100)
		x -= phi * m;
	return x;
}

void solve() {
	ll a, m;
	cin >> a >> m;
	ll x = get(a, m);
	assert(pw(a, x, m) == (x % m));
	cout << get(a, m) << "\n";
}

int main() {
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		solve();
	}
	return 0;
}




Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

X, K, D = map(int, input().split())
X = abs(X)

if X >= K * D:
    print(X - (K * D))
else:
    K -= X // D
    X %= D
    if K % 2 == 0:
        print(X)
    else:
        print(abs(X - D))



# left = -1
# right = 10 ** 15 + 1
# while right - left > 1:
#     mid = (left + right) // 2
#     if check(mid):
#         right = mid
#     else:
#         left = mid

Measured memory_bytes: 9364
n = int(input())

def digitsum(a):
    s = 0
    while True:
        if a <= 0:
            break
        s += a % 10
        a //= 10
    return s

min = 1e6

for a in range(1, (n + 1) - 1):
    b = n - a
    s = digitsum(a) + digitsum(b)
    if s < min:
        min = s

print(min)

Measured memory_bytes: 3060