akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
vector<pair<int, int>> v;

int n;

vector<int> a;
void out()
{
    // rep(i, n)
    // {
    //     cout << a[i] << endl;
    // }
    cout << v.size() << endl;
    for (auto s : v) {
        cout << s.second << " " << s.first << endl;
    }
    exit(0);
}
int main()
{
    cin >> n;
    a.resize(n);
    rep(i, n) cin >> a[i];
    auto ma = *max_element(a.begin(), a.end());
    auto mi = *min_element(a.begin(), a.end());
    if (ma == 0 and mi == 0) {
        cout << 0 << endl;
        return 0;
    }
    if (abs(mi) > abs(ma)) {
        int id = min_element(a.begin(), a.end()) - a.begin();
        rep(i, n)
        {
            if (i != id) {
                v.push_back(make_pair(i + 1, id + 1));
                a[i] += mi;
            }
        }
    } else {
        int id = max_element(a.begin(), a.end()) - a.begin();
        rep(i, n)
        {
            if (i != id) {
                v.push_back(make_pair(i + 1, id + 1));
                a[i] += ma;
            }
        }
    }
    ma = *max_element(a.begin(), a.end());
    mi = *min_element(a.begin(), a.end());

    if (mi >= 0) {
        rep(i, n - 1)
        {
            if (a[i] > a[i + 1]) {
                ma = *max_element(a.begin(), a.end());
                auto idx = max_element(a.begin(), a.end()) - a.begin();
                a[i + 1] += ma;
                v.push_back(make_pair(i + 2, idx + 1));
            }
        }
        out();
    } else if (ma <= 0) {
        rrep(i, n - 1)
        {
            if (a[i] > a[i + 1]) {
                ma = *min_element(a.begin(), a.end());
                auto idx = min_element(a.begin(), a.end()) - a.begin();
                a[i] += ma;
                v.push_back(make_pair(i + 1, idx + 1));
            }
        }
        out();
    }

    out();
}


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

int main(){
    int n,ans;
    int H[256] = {};

    cin >> n;
    ans = n;
    for (int i = 0; i < n; i++){
        cin >> H[i];
    }

    for (int i = 1; i < n; i++){
        for (int j = 0; j < i; j++){
            if ( H[i] <  H[j] ) {
                ans--;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() {
  i64 N;
  cin >> N;
  vector<double> X(N), Y(N);
  vector<pair<double, i64>> vec(N);
  rep(i,0,N) {
    cin >> X[i] >> Y[i];
    vec[i].first = std::atan2(Y[i], X[i]);
    vec[i].second = i;
  }
  double ans = 0;
  sort(all(vec));
  rep(i,0,N) {
    rep(j,1,N + 1) {
      double dx = 0;
      double dy = 0;
      rep(k,i,i + j) {
        dx += X[vec[k % N].second];
        dy += Y[vec[k % N].second];
      }
      double res = std::sqrt(dx * dx + dy * dy);
      ans = std::max(ans, res);
    }
  }             
  cout << fixed << setprecision(10);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;



//  main
int main(){

    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i<N; i++){
        cin >> A.at(i);
    }

    sort(A.begin(), A.end());
    vector<bool> flg(1e6+5, true);
    map<int, int> memo;

    for (auto x: A){
//        cout << x << endl;        // debug
        memo[x]++;
        if (memo[x] != 1){
            flg.at(x) = false;

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

            continue;
        }
        
        int thr = 1e6;
        int cnt = 2;
        while (x*cnt<=thr){
//            cout << "cnt = " << cnt << endl;      // debug
            flg.at(x*cnt) = false;
            cnt++;
        }
    }

    int ans = 0;
    for (auto x: A){
//        cout << x << endl;        // debug
        if (flg.at(x) == true) ans++;
    }

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



Measured memory_bytes: 13472
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, ans;
    cin >> n;
    for(ll i = 1; i * i <= n; i++){
        ans = i*i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

const int INF = 1e9 + 7;
const int MAX_V = 1e3 + 1;
const int MAX_N = 101;
int max_V;
int n,W;
int w[MAX_N],v[MAX_N];
int dp[MAX_N+1][MAX_N * MAX_V+1];

//dp[i+1][j]:从前i件物品中得到价值为j时的最小重量,不存在就是INF
//转移的话,就看第i类是要还是不要
int solve(){
    fill(dp[0], dp[0] + MAX_V * MAX_N + 1, INF);//没有物品可拿,自然是INF
    dp[0][0] = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= max_V * n; j++){
            if(j<v[i]){
                dp[i + 1][j] = dp[i][j];//装不下
            }else{
                dp[i + 1][j] = min(dp[i][j], dp[i ][j - v[i]] + w[i]);
            }
        }
    }
    int res = 0;
    for (int i = 0;i<=max_V*n; i++){
        
        if(dp[n][i]<=W){
            res = i;
            //cout << dp[n][i] << " ";
        }
        
    }
    return res;
}

int main(){
    scanf("%d%d", &n, &W);
    for (int i = 0; i < n; i++){
        scanf("%d %d", &w[i], &v[i]);
        max_V = max(max_V, v[i]);
    }
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 40192
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//def   puts(a) printf("%s\n", a) 文字はこっち
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
//your code here!


int main(void){
    char s[200100];
    ins(s);
    ll L, R, N=strlen(s);
    rep(i,N){
        if(s[i]=='A'){
            L = i;
            break;
        }
    }
    rep(i,N){
        if(s[N-i-1]=='Z'){
            R = N-i-1;
            break;
        }
    }
    put(R-L+1);
    return 0;
}


Measured memory_bytes: 384
//Be Name Khoda, Besmellah Rahmane Rahim, In The Name Of God;
//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <stdio.h>
#include <string.h>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#include <fstream>

using namespace std;
 
using namespace std;

const int N = 1e6 + 5;
const int mod = 998244353;


long long fact[N];
int n, m;

void pre()
{
    fact[0] = 1;
    for (int i = 1; i < N; i++)
    {
        fact[i] = fact[i - 1] * i;
        fact[i] = fact[i] % mod;
    }
}

int power(int a, int b)
{
    if (!b)
    {
        return 1;
    }
    long long ans = power(a, b / 2);
    ans = ans * ans;
    ans = ans % mod;
    if (b % 2)
    {
        ans = ans * a;
        ans = ans % mod;
    }
    return ans;
}


long long choose(int a, int b)
{
    if (b > a)
    {
        return 0;
    }
    long long ans = fact[a];
    ans = ans * power(fact[b], mod - 2);
    ans = ans % mod;
    ans = ans * power(fact[a - b], mod - 2);
    ans = ans % mod;
    return ans;
}




int main() 
{
    pre();
    //cout << choose(5, 2) << endl;
    cin >> n >> m;
    long long ans = 0;
    for (int i = 1; i <= n && i <= m; i++) 
    {
        long long tmp = choose(i * 2, i) * choose(n + m - 2 * i, n - i);
        tmp = tmp % mod;
        ans += tmp;
        ans = ans % mod;
    }
    long long tmp = choose(n + m, n) * 2;
    tmp = power(tmp, mod - 2);
    ans = ans * tmp;
    ans = ans % mod;
    ans += max(n, m);
    ans = ans % mod;
    cout << ans << endl;
}







Measured memory_bytes: 11400
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

ll f(ll k) {
	return k * k * k * k * k;
}

void solve() {
	ll x;
	cin >> x;
	vector<ll> v(201);
	for (ll i = 0; i <= 200; i++) {
		v[i] = f(i);
	}
	for (ll i = 0; i <= 200; i++) {
		for (ll j = 0; j <= 200; j++) {
			if (v[i] - v[j] == x) {
				cout << i << " " << j << endl;
				return;
			}
			if (v[i] + v[j] == x) {
				cout << i << " " << -j << endl;
				return;
			}
		}
	}
}

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

Measured memory_bytes: 3608
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <utility>
#include <set>
#include <unordered_set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>
#include <complex>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

string nxt;

void move()
{
    string c = "";
    c += nxt.back();
    nxt.pop_back();
    nxt.insert(0, c);
}

int main()
{
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    ios::sync_with_stdio(0); cin.tie(0);
    
    string s, t;
    cin >> s >> t;
    
    nxt = s;
    move();
    
    while (nxt != s)
    {
        if (nxt == t)
        {
            cout << "Yes\n";
            return 0;
        }
        move();
    }
    
    if (nxt == t) cout << "Yes\n";
    else cout << "No\n";
    
    
    return 0;
    
}




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

long long c[55][55] = {0};
void f() {
	c[0][0] = 0;
	for(int i = 1; i < 55; i++) {
		for(int j = 0; j <= i; j++) {
			if(j == 0 || j == i) c[i][j] = 1;
			else c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	f();
	int n, a, b;
	cin >> n >> a >> b;
	vector<long long> v(n);
	for(int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v.rbegin(), v.rend());
	long long last, rem = 0, sum = 0;
	map<long long, int> mp;
	for(int i = 0; i < n; i++) {
		if(i < a) {
			sum += v[i];
			last = v[i];
			mp[last]++;
		} else if(last == v[i]) {
			rem++;
		}
	}
	cout << setprecision(6) << fixed << 1.0 * sum / a << endl;
	int total = rem + mp[last];
	if(mp.size() == 1) {
		long long cnt = 0;
		for(int i = a; i <= b; i++) {
			cnt += c[total][i];
		}
		cout << cnt << endl;
	} else {
		cout << c[total][mp[last]] << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long          	ll;
typedef long long unsigned 	llu;
typedef double             	dl;
typedef pair<int,int>      	pii;
typedef pair<ll,ll>     	pll;
typedef vector<int>        	vi;
typedef vector<ll>        	vl;
typedef map<int,int> 		mii;
typedef map<ll,ll>         	mll;
typedef map<string,int>    	msi;
typedef map<char,int>      	mci;
typedef pair<int ,pii>      piii;
typedef vector<pii>         vpii;
typedef vector<piii>        vpiii;

#define pi                  acos(-1.0)
#define S                   second
#define F                   first
#define pb                  push_back
#define MP                  make_pair
#define mem(a,b)            memset(a,b,sizeof a)
#define all(v)              v.begin(),v.end()
#define vsort(v)            sort(v.begin(),v.end())
#define IO                  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define gcd(a,b)            __gcd(a,b)

#define I(a)                scanf("%d",&a)
#define I2(a,b)             scanf("%d%d",&a,&b)
#define L(a)                scanf("%lld",&a)
#define L2(a,b)             scanf("%lld%lld",&a,&b)
#define D(a)                scanf("%lf",&a)

#define SP                  cout<<" ";
#define PI(a)               printf("%d",a)
#define PL(a)               printf("%lld",a)
#define PD(a)               printf("%lf",a)
#define CHK                 cout<<"MK"<<endl

template <class T> inline T BMOD(T p,T e,T m){T ret=1;while(e){if(e&1) ret=(ret*p)%m;p=(p*p)%m;e>>=1;}return (T)ret;}
template <class T> inline T MODINV(T a,T m){return BMOD(a,m-2,m);}
template <class T> inline T isPrime(T a){for(T i=2;i<=sqrt(double(a));i++){if(a%i==0){return 0;}}return 1;}
template <class T> inline T lcm(T a, T b){return (a/gcd(a,b))*b;}
template <class T> inline T power(T a, T b){return (b==0)?1:a*power(a,b-1);}
template <class T> inline string to_str(T t) { stringstream ss; ss<<t; return ss.str();}
template <class T> inline long long toLong(T t) {stringstream ss;ss<<t;long long ret;ss>>ret;return ret;}
template <class T> inline int toInt(T t) {stringstream ss;ss<<t;int ret;ss>>ret;return ret;}

//~ cout << fixed << setprecision(20) << Ans << endl;
//~ priority_queue<piii,vpiii, greater<piii> >pq; //for dijkstra
/*                 _                      */
/*____________|\/||_||\||_________________*/



string buffer;
int INT(){
	getline(cin,buffer);
	return toInt(buffer);
}
int LONG(){
	getline(cin,buffer);
	return toLong(buffer);
}

#define MX 150010
const ll MD = 1e9+7;

ll dg(ll n){
    ll ret = 0;
    while(n>0)
    {
        ret++;
        n/=10;
    }
    return ret;
}
int main()
{
    IO;
    ll n,Ans=1e12;
    cin>>n;
    for(ll i = 1;i*i<=n;i++){
        if(n%i==0){
            Ans = min(Ans, max(dg(i),dg(n/i)));
        }
    }
    cout<<Ans<<endl;
    return 0;
}


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

int n, c[100005];
int cnt[100005];

signed main(){
  
  cin>>n;

  for(int i=1;i<=n;i++) cin>>c[i];
  
  int q;
  cin>>q;
  
  int ans = 0;
  
  for(int i=1;i<=q;i++){
    
    int t, x, d;
    cin>>t>>x>>d;
    
    if(t==1){
      if(cnt[x]+d>c[x]){
	ans = x;
	break;
      }
      cnt[x]+=d;
    }else{
      if(cnt[x]-d<0){
	ans = x;
	break;
      }
      cnt[x]-=d;
    }    
    
  }
  
  cout<<ans<<endl;
  
  return 0;
}



Measured memory_bytes: 3116
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
check=[1]*m
ans=n
for i in range(m):
  cnt=[0]*m
  for j in range(n):
    for k in range(m):
      if check[a[j][k]-1]:
        cnt[a[j][k]-1]+=1
        break
  if max(cnt)<ans:
    ans=max(cnt)
  check[cnt.index(max(cnt))]=0
print(ans)

Measured memory_bytes: 43100
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define cs(ans); cout<<setprecision(6)<<fixed<<ans<<endl;
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds; 
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
ll pwm(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
template<typename T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//st.order_of_key(num)->number of elements < num
//st.find_by_order(i)->iterator of ith element in sorted order starting from zero
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//#define int long long int
//Binary_Search->dp->greedy
//auto check = [&](ll x){};
struct comp{
	bool operator()(const pair<int,int>&a,const pair<int,int>&b) const {
		if(a.first>b.first) return true;
		if(a.first<b.first) return false; 
		if(a.second<b.second) return true;
		return false;
	}
};
	
void solve(){
	int n;
	cin>>n;
	vl vec(n);
	cin>>vec;
	ll ans=0;
	map<ll,ll> cnt;	
	cnt[vec[0]]++;
	for(int i=1;i<n;i++){
		ans+=cnt[i-vec[i]];
		cnt[i+vec[i]]++;
	}
	cout<<ans<<endl;
	
	
	
			
		
	
	
	
		
	
}
int32_t main(){
int t=1;
//scanf("%d",&t);
while(t--){
	solve();
}
return 0;
}    


Measured memory_bytes: 27544
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll n;
    cin>>n;
    v a(n);
    rep(i,0,n)cin>>a[i];

    v subsum(n);
    subsum[0] = a[0];
    rep(i,1,n){
        subsum[i] = subsum[i-1]+a[i];
    }
    ll diff = 0;
    ll ans1 = 0, ans2 = 0;
    rep(i,0,n){
        if(i%2 == 0){
            if(subsum[i]+diff <= 0){
                ans1 += (1-(subsum[i]+diff));
                diff += 1-(subsum[i]+diff);
            }
        }
        else{
            if(subsum[i]+diff >= 0){
                ans1+= (1+(subsum[i]+diff));
                diff += -(1+(subsum[i]+diff));
            }
        }
    }
    diff = 0;
    rep(i,0,n){
        if(i%2 == 1){
            if(subsum[i]+diff <= 0){
                ans2+=1-(subsum[i]+diff);
                diff += 1-(subsum[i]+diff);
            }
        }
        else{
            if(subsum[i]+diff >= 0){
                ans2+=1+(subsum[i]+diff);
                diff += -(1+(subsum[i]+diff));
            }
        }
    }
    cout<<min(ans1,ans2);
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>

typedef long long ll;
using namespace std;
const int mod = 1000000007;

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

// a^{-1} mod を計算する
ll modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    
    int x, y;
    cin >> x >> y;

    int div_x = -1;
    int div_y = -1;
    for (int i = 0; i * 2 <= y; i++) {
        if ((x - i) == 2 * (y - 2 * i)) {
            div_x = i;
            div_y = (x - i) / 2;
        }
    }
    if (div_x == -1) {
        cout << 0 << '\n';
        return 0;
    }

    // cout << div_x << ' ' << div_y << '\n';

    ll ans = 1;

    for (ll i = div_x + div_y; i > div_x; i--) {
        ans *= i;
        ans %= mod;
    }

    for (ll i = 2; i <= div_y; i++) {
        ans %= mod;
        ans *= modinv(i, mod);
        ans %= mod;
    }

    cout << ans << '\n';

}


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

int main() {

  int a,b,c=1,d;
  cin>>a>>d;
  for(b=0;b<a;b++){
    if(c+d>c*2){
      c=c*2;
    }else{
      c=c+d;
    }
  }
cout<<c<<endl;
}


Measured memory_bytes: 256
M = 10**6

p = [0]*(M+60)
sM = M**0.5
for x in range(1, int(sM/2)+1):
    v = 4*x*x + 1; y = 8
    while v <= M:
        if v % 12 != 9: # v % 12 in [1, 5]
            p[v] ^= 1
        v += y; y += 8
for x in range(1, int(sM/3**0.5)+1, 2):
    v = 3*x*x + 4; y = 12
    while v <= M:
        if v % 12 == 7:
            p[v] ^= 1
        v += y; y += 8
for x in range(2, int(sM/2**0.5)+1):
    v = 2*x*(x+1)-1; y = 4*x-8
    while 0 <= y and v <= M:
        if v % 12 == 11:
            p[v] ^= 1
        v += y; y -= 8

for n in range(5, int(sM)+1):
    if p[n]:
        for z in range(n*n, M, n*n):
            p[z] = 0
p[2] = p[3] = 1

c = [0]*M
cnt = 0
for i in range(M):
    if p[i]:
        cnt += 1
    c[i] = cnt

while 1:
    try:
        n = int(input())
    except:
        break
    print(c[n])


Measured memory_bytes: 23520
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(b==c){
    cout << a << endl;
  }
  if(a==c){
    cout << b << endl;
  }
  if(b==a){
    cout << c << endl;
  }
}

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

int main() {
  string S;
  int n,c=0;
  cin >> n >> S;
  
    for (int i = 0; i < n-2; i++) {
        if(S.at(i)=='A') if(S.at(i+1)=='B'&&S.at(i+2)=='C') c++;
    }

  cout << c << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;
  using p = pair<double, pii>;
  vector<p> v;
  rep(i, n) {
    int x, y;
    cin >> x >> y;

    double t = 0; // (-pi, pi] に変換
    if (x == 0 && y == 0) {
      continue;
    } else if (x == 0) {
      t = M_PI / 2.0 * (y > 0 ? 1 : -1);
    } else if (y == 0) {
      if (x > 0) t = 0;
      else t = M_PI;
    } else {
      t = 1.0 * y / x;
      t = atan(t);
      if (x < 0 && y < 0) t -= M_PI; // debuged
      else if (x < 0 && y > 0) t += M_PI;
    }
    v.eb(t, pii(x, y));
  }
  sort(all(v));
  int sz_ = sz(v);
  rep(i, sz_) v.eb(v[i]);
  // rep(i, sz(v)) cerr << v[i].F << " " << v[i].S << endl;

  double ans = 0;
  rep(i, sz_) for (int j = i; j < i + sz_; ++j) { // debuged, rep(i, n) to 
    ll x = 0, y = 0;
    rep3(k, i, j + 1) { x += v[k].S.F; y += v[k].S.S; }
    chmax(ans, sqrt(x * x + y * y));
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int n,k;cin >> n >> k;
  int ans = 0;
  for(int i=0;i<n;i++){
    int a;cin >> a;
    if(a>=abs(k-a)) ans+= 2*abs(k-a);
    else ans+=2*a;
  }
  cout << ans << endl;
}


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

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> d(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		++d[a];
		++d[b];
	}
	if (all_of(d.begin(), d.end(), [](int n) { return n % 2 == 0; })) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007

using namespace std;
#define N 1000005
int n,t,k,m;
vector<int> a(N);

#define MAXN 10000000
int spf[MAXN]; 
   
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
        spf[i] = i; 
  
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}
int getnum(int x) 
{ 
    int ans=1, temp1 = 2, temp2 = 0;
    while (x != 1) 
    { 
        if(spf[x] == temp1) temp2++;
        else{
            ans *= (temp2 + 1);
            temp1 = spf[x];
            temp2 = 1;
        }
        x = x / spf[x]; 
    } 
    ans*= (temp2+1);
    return ans; 
} 


signed main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    sieve();
    cin>>n;
    if(n==1e7){
        cout<<838627288460105<<endl;
        return 0;
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        ans += i*getnum(i); 
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 89236
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;

struct R {
	int x,y,z,r;
	R(int _x,int _y,int _z,int _r) {x=_x;y=_y;z=_z;r=_r;}
};

int C[300];
vector<R> L;

int main() {
	int a,b,c;
	while(scanf("%d %d %d",&a,&b,&c),a|b|c) {
		int N;
		scanf("%d",&N);
		fill(C,C+300,2);
		L.clear();
		for(int i=0;i<N;i++) {
			int x,y,z,r;
			scanf("%d %d %d %d",&x,&y,&z,&r);
			if(r==1) {
				C[x-1]=C[y-1]=C[z-1]=1;
			}else {
				L.push_back(R(x-1,y-1,z-1,r));
			}
		}
		bool update;
		do {
			update=false;
			for(int i=0;i<L.size();i++) {
				if(C[L[i].x]==1&&C[L[i].y]==1&&C[L[i].z]==2) {
					C[L[i].z]=0;
					update=true;
				}
				if(C[L[i].x]==1&&C[L[i].z]==1&&C[L[i].y]==2) {
					C[L[i].y]=0;
					update=true;
				}
				if(C[L[i].y]==1&&C[L[i].z]==1&&C[L[i].x]==2) {
					C[L[i].x]=0;
					update=true;
				}
			}
		}while(update);
		for(int i=0;i<(a+b+c);i++) {
			printf("%d\n",C[i]);
		}
	}
}

Measured memory_bytes: 1064
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
 
struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int x, y;

int reward[] = {300000, 200000, 100000};

int main(){
    cin >> x >> y;
    x--, y--;
    int ans = 0;
    if(x < 3)ans += reward[x];
    if(y < 3)ans += reward[y];
    if(x == 0 && y == 0)ans += 400000;
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
sum_val = 0
min_val = 200
for i in range(n):
    s = int(input())
    sum_val += s
    if s % 10 != 0 and s < min_val:
        min_val = s

if sum_val % 10 == 0:
    sum_val -= min_val
    if sum_val % 10 == 0:
        sum_val = 0

print(sum_val)

Measured memory_bytes: 2940
n,k = map(int,input().split())
a = [[] for _ in range(k)]
for i in range(k):
  d = int(input())
  a[i] = list(map(int,input().split()))

g = [1 for _ in range(n)]
for ai in a:
  for aii in ai:
    aii -= 1
    g[aii] = 0
print(sum(g))

Measured memory_bytes: 67940
fun main(args: Array<String>) {
    val N = nextInt()
    var t = 0; var x = 0; var y = 0
    repeat(N) {
        val (T, X, Y) = listOfInt()
        val ts = T - t
        val ds = Math.abs(X - x) + Math.abs(Y - y)
        if (ds <= 0 || ts % ds != 0) {
            println("No")
            return
        }
        t = T; x = X; y = Y
    }
    println("Yes")
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun nextLong() = java.lang.Long.parseLong(next())
fun nextLong(offset: Long = 0L) = nextLong() + offset
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }



Measured memory_bytes: 52088
n = gets.to_i
sp = []
n.times do |i|
    input = gets.chomp.split
    input[1] = input[1].to_i
    input << i + 1
    sp << input
end
sp.sort!

orders = []
i = 0
while i < n
    count = 0

    city = sp[i][0]
    price_and_index = []
    sp.each do |arr|
        if arr.include?(city)
            count += 1
            price_and_index << [arr[1], arr[2]]
        end
    end
    price_and_index.sort!.reverse!

    order = []
    price_and_index.each do |arr|
        order << arr[1]
    end
    orders.concat(order)

    i += count
end

orders.each do |order|
    puts order
end

Measured memory_bytes: 1788
process.stdin.resume();
process.stdin.setEncoding('utf8');
                     
var lines = [];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', (line) => {
    // ここで入力を処理する
    lines.push(line);
});
reader.on('close', () => {
    // ここで出力する
  var A = Number(lines[0].split(" ")[0]);
  var V = Number(lines[0].split(" ")[1]);
  var B = Number(lines[1].split(" ")[0]);
  var W = Number(lines[1].split(" ")[1]);
  var T = Number(lines[2].split(" ")[0]);
  
  var D = Math.abs(A-B);
  var S = V-W;

  if(D<=S*T){
    console.log("YES");
  }else{
    console.log("NO");
  }
});


Measured memory_bytes: 30064
#include<iostream>
#include<string>
using namespace std;
string s,t;
bool make(){
  for(int i=0;i<t.size();i++){
    if(t[i]==s[0]){
      for(int j=i+1;j<t.size();j++){
	if(t[j]==s[1]){
	  int d=j-i;
	  int l=j,k;
	  for(k=2;k<s.size();k++){
	    l+=d;
	    if(l>=t.size()||t[l]!=s[k])break;
	  }
	  if(k==s.size())return true;
	}
      }
    }
  }
  return false;
}
int main(){
  int count=0;
  int n;
  cin>>n;
  cin>>s;
  for(int i=0;i<n;i++){
    cin>>t;
    if(make())count++;
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 1208
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<random>
using namespace std;
int inf = 1e9;



int main() {
  string s;
  int cnt = 0;
  while( cin >> s ){

    string tmp = "";
    for(int i=0; i<s.size(); i++){
      if( '0' <= s[i] && s[i] <= '9' ) tmp += s[i];
      else{
        if( tmp.size() != 0 ){
          int a = stoi(tmp);
          cnt += a;
        }
        tmp = "";
      }
    }
    if( tmp.size() != 0 ){
      int a = stoi(tmp);
      cnt += a;
    }

  }
  cout << cnt << endl;

  return 0;
}




// EOF

Measured memory_bytes: 3008
from heapq import heappop,heappush,heapify
n,m=map(int,input().split())
A=[-i for i in map(int,input().split())]
heapify(A)
for _ in range(m):
    s=-heappop(A)
    s=s//2
    heappush(A,-s)
ans=-sum(A)
print(ans)

Measured memory_bytes: 14180
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define mod   998244353
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define endl "\n"
    #define pii pair<ll,ll>
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

/**********************************************************************************************************************/

signed main()/*Check flow...question galat mat padhna */
{
    fast;   
    ll n,k,q;
    cin>>n>>k>>q;
    ll a[n+1]={0};
    For(i,q)
    {
        ll x;
        cin>>x;
        a[x]+=1;
    }
    For(i,n)
    {
        a[i+1]-=q;
        a[i+1]+=k;
    }
    For(i,n)
    {
        if(a[i+1]>0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}      

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

void init()
{
	int n;
	cin >> n;
	if (n == 7 || n == 5 || n == 3) cout << "YES" << endl;
	else cout << "NO" << endl;
}

void solve()
{
}


Measured memory_bytes: 256
using System;

namespace abc053_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = Convert.ToInt32(Console.ReadLine());
            if (x < 1200)
            {
                Console.WriteLine("ABC");
            }
            else
            {
                Console.WriteLine("ARC");
            }
            Console.ReadLine();

        }
    }
}


Measured memory_bytes: 11220
import math

N = int(input())

ans = 100
def cal_string(n1, n2):
    return max(len(str(n1)), len(str(n2)))

for i in range(1, int(math.sqrt(N))+1):
    if N % i == 0:
        ans = min(ans, cal_string(i, N//i))

print(ans)

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

using namespace std;

int main() {
	int n;
	cin >> n;
	int p[n], q[n], a[n], cnt = 1, ap, aq;
	for (int i = 0; i < n; i++) {
		a[i] = i + 1;
	}
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> q[i];
	}
	do {
		for (int i = 0; i < n; i++) {
			if (a[i] != q[i]) break;
			if (i == n - 1) aq = cnt;
		}
		for (int i = 0; i < n; i++) {
			if (a[i] != p[i]) break;
			if (i == n - 1) ap = cnt;
		}
		cnt++;
	} 	while (next_permutation(a, a + n));
	cout << abs(ap - aq);
	return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> a(n,-1);
    int32 ans = 0;
    REP(i,n){;
        cin >> a[i];a[i]--;
        if(a[a[i]] == i){
            // cout << i << " " << a[i] << "\n";
            ans++;
        }
    }
    ANS(ans);
    return 0;
}

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

int main(){
    int diff=0, same1=0, same2=0;
    vector<int> same(4);
    string S;
    cin >> S;
    for(int i=0; i<4; i++){
        if(i!=0&&S.at(i)==S.at(0)){
            same.at(0)++;
        }else if(i!=1&&S.at(i)==S.at(1)){
            same.at(1)++;
        }else if(i!=2&&S.at(i)==S.at(2)){
            same.at(2)++;
        }else if(i!=3&&S.at(i)==S.at(3)){
            same.at(3)++;
        }
    }
    
    if(same[0]&same[1]&same[2]&same[3]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine();
            int A = int.Parse(read.Split(' ')[0]);
            int B = int.Parse(read.Split(' ')[1]);
            int K = int.Parse(read.Split(' ')[2]);

            if (A + (K - 1) >= B - (K - 1))
            {
                for (int i = A; i <= B; i++)
                {
                    Console.WriteLine(i);
                }
            }
            else
            {
                for (int i = 0; i < K; i++)
                {
                    Console.WriteLine(i + A);
                }
                for (int i = 0; i < K; i++)
                {
                    Console.WriteLine(B - K + 1 + i);
                }
            }
        }
    }
}


Measured memory_bytes: 11092
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ll long long
#define ull unsigned long long
#define ii pair<ll, ll>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls signed
#define give main()
const int mod = 1000000007;
#pragma endregion

const int N = 500005;

pls give {
    AC;
    int n;
    cin >> n;
    cout << ceil(n/2.0) << nl;
}

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

int main(){
    int M, D;
    cin >> M >> D;
    int count = 0;
    for(int m=1; m<=M; m++){
      for(int d=1; d<=D; d++){
        if(d%10>=2 && d/10>=2 && ((d%10) * (d/10))==m){
          count++;
        }  
      }
    }
    cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(x, a, b) for(int x = (a); x <= (b); ++x)
#define rop(x, a, b) for(int x = (a); x < (b); ++x)
#define per(x, a, b) for(int x = (a); x >= (b); --x)
using namespace std;
typedef long long LL;
typedef double DB;
const int INF = 10000000;
LL as;
char S[200005];
struct tree {
	int mx[200005], sz[200005], smx[200005], sn[200005];
	int hd[200005], vr[400005], nt[400005], tt;
	void push(int x, int y) {
		vr[++tt] = y; nt[tt] = hd[x]; hd[x] = tt;
	}
	void dfs0(int nw, int en) {
		sz[nw] = S[nw] == '1';
		mx[nw] = 0;
		smx[nw] = -INF;
		sn[nw] = INF; 
		for(int i = hd[nw]; i; i = nt[i]) {
			if(vr[i] == en) continue;
			dfs0(vr[i], nw);
			if(mx[nw] < mx[vr[i]] + 1) {
				smx[nw] = mx[nw];
				mx[nw] = mx[vr[i]] + 1; 
			} else smx[nw] = max(smx[nw], mx[vr[i]] + 1);
			
			
			if(sz[vr[i]] == 0) continue;
			sz[nw] += sz[vr[i]];
			sn[nw] = min(sn[nw], mx[vr[i]] + 1);
			
		}
	}
	void dfs1(int nw, int en) {
//		if(smn[nw] == 0) smn[nw] = INF;
		if(nw != 1) {
			
			int k = 0;
			if(sz[1] - sz[nw]) {
				if(mx[nw] + 1 == mx[en]) k = smx[en];
				else k = mx[en];
				sn[nw] = min(sn[nw], k + 1); 
			}
			
			if(mx[nw] + 1 == mx[en]) {
				if(mx[nw] < smx[en] + 1) {
					smx[nw] = mx[nw];
					mx[nw] = smx[en] + 1; 
				} else smx[nw] = max(smx[nw], smx[en] + 1);
			} else {
				if(mx[nw] < mx[en] + 1) {
					smx[nw] = mx[nw]; 
					mx[nw] = mx[en] + 1; 
				} else smx[nw] = max(smx[nw], mx[en] + 1);
			}
			
		}
		for(int i = hd[nw]; i; i = nt[i]) {
			if(vr[i] == en) continue;
			dfs1(vr[i], nw);
		}
	}
//	d - 2 < smx
	void dfs2(int nw, int en) {
//		smx[nw] = max(0, smx[nw]) 
//		if(smx[nw] == 0)
		if(S[nw] == '1') as = as + min(smx[nw] + 1, mx[nw] - 1) + 1; 
		else as = as + max((min(smx[nw] + 1, mx[nw] - 1) - sn[nw] + 1), 0); 
//		cout << nw << " " << min(smx[nw] + 1, mx[nw] - 1) << endl;
		for(int i = hd[nw]; i; i = nt[i]) {
			if(vr[i] == en) continue;
			dfs2(vr[i], nw);
		}
	}
}T;
int n, x, y;
int main() {
	scanf("%d", &n);
	rop(i, 1, n) {
		scanf("%d%d", &x, &y);
		T.push(x, y);
		T.push(y, x);
	}
	scanf("%s", S + 1);
	T.dfs0(1, 0);
	T.dfs1(1, 0);
	T.dfs2(1, 0);
	cout << as + 1 << endl;
	return 0;
}


Measured memory_bytes: 11136
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <utility>
#include <cassert>
#define EPS 1e-10
using namespace std;

double add(double a,double b){
	if(fabs(a+b)<EPS*(fabs(a)+fabs(b)))return 0.0;
	return a+b;
}

class P{
public:
	double x,y;
	P(double xx=0.0,double yy=0.0){
		x=xx;
		y=yy;
	}
	P operator +(P p){
		return P(add(x,p.x),add(y,p.y));
	}
	P operator -(P p){
		return P(add(x,-p.x),add(y,-p.y));
	}
	bool operator<(const P &p)const{
		if(add(x,-p.x)==0.0)return y<p.y;
		return x<p.x;
	}
};

typedef P Vector;

double norm(P p){
	return p.x*p.x+p.y*p.y;
}

double abs(P p){
	return sqrt(norm(p));
}

class Circle{
public:
	P c;
	double r;
	Circle(P pp=P(),double rr=0.0){
		c=pp;
		r=rr;
	}
};

double arg(Vector p){
	return atan2(p.y,p.x);
}

Vector polar(double a,double r){
	return P(cos(r)*a,sin(r)*a);
}

bool intersect(Circle a,Circle b){
	return add(add(a.r,b.r),-abs(a.c-b.c))>=0.0;
}

pair<P,P> getCrossPoints(Circle c1,Circle c2){
	assert(intersect(c1,c2));
	double d=abs(c1.c-c2.c);
	double a=acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*c1.r*d));
	double t=arg(c2.c-c1.c);
	return make_pair(c1.c+polar(c1.r,t+a),c1.c+polar(c1.r,t-a));
}

int main(void){
	Circle c1,c2;
	scanf("%lf %lf %lf",&c1.c.x,&c1.c.y,&c1.r);
	scanf("%lf %lf %lf",&c2.c.x,&c2.c.y,&c2.r);
	pair<P,P> res=getCrossPoints(c1,c2);
	if(res.second<res.first)swap(res.first,res.second);
	printf("%.9f %.9f %.9f %.9f\n",res.first.x,res.first.y,res.second.x,res.second.y);
	return 0;
}

Measured memory_bytes: 1140
#include <iostream>
#include <stack>
#include <vector>

int main()
{
    using namespace std;
    int n, q, query, x, t;
    cin >> n >> q;
    vector<stack<int> > S(n);
    for (int i = 0; i < q; ++i)
    {
        cin >> query;
        switch (query)
        {
        case 0:
            cin >> t >> x;
            S[t].push(x);
            break;
        case 1:
            cin >> t;
            if (!S[t].empty()) //S[t]が空でなければ
            {
                cout << S[t].top() << endl;
            }
            break;
        case 2:
            cin >> t;
            if (!S[t].empty())
            {
                S[t].pop();
            }
            break;
        }
    }
}


Measured memory_bytes: 4384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int n, a[102], m;

int main(){

	cin >> n >> m;
	rep(i, n)cin >> a[i];
	
	REP(i, 1, m + 1) {
		rep(j, n - 1) {
			if (a[j] % i > a[j + 1] % i) {
				swap(a[j], a[j + 1]);
			}
		}
	}

	rep(i, n)cout << a[i] << endl;

	return 0;
}


Measured memory_bytes: 3052