akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

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

typedef long long ll;
typedef vector<int> VI;

vector<int> vec;
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    REP(i, n) {
        int a; cin >> a;
        vec.push_back(a);
    }
    
    vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
    for(int i=0; i<vec.size(); ++i){
        if(i) cout << " ";
        cout << vec[i];
    }
    cout << endl;
	return 0;
}


Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    ll S;
    cin >> S;
    ll X1 = sqrt(S);
    ll Y2 = X1;
    while (X1 * Y2 < S) {
        if (X1 < 1e9) X1++;
        else Y2++;
    }
    ll X2 = X1 * Y2 - S;
    cout << X1 << ' ' << 1 << ' ' << X2 << ' ' << Y2 << ' ' << 0 << ' ' << 0 << '\n';
}

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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int[] a = { sc.nextInt(), sc.nextInt(), sc.nextInt() };

		Arrays.sort(a);

		int sum = a[2] - a[0] + (a[2] - a[1]);

		if (sum % 2 == 0) {
			System.out.println(sum / 2);
		} else {
			System.out.println(sum / 2 + 2);
		}

		sc.close();
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

using Int = long long;

void solve() {
    Int a,b;
    cin >> a >> b;
    cout << ((abs(a-b) > 1) ? "Alice" : "Brown") << endl;
}

#ifdef DEBUG
#define MAIN hoge
#else
#define MAIN main
#endif

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
signed main()
{
	int n;
	cin>>n;
	vector<int>a(n);
	for (int i=0;i<n;i++)
		cin>>a[i];
	for (int i=0;i<n;i++)
		if (a[i]==0){
			cout<<0;
			re 0;
		}
	long double l=0;
	for (int i=0;i<n;i++)
		l+=log10(a[i]);
	if (l>18.1){
		cout<<-1;
		re 0;
	}
	int k=1;
	for (int i=0;i<n;i++){
		k*=a[i];
		//cout<<k<<endl;
		if (k>1000000000000000000){
			cout<<-1;
			re 0;
		}
	}
	cout<<k;
	re 0;
}

Measured memory_bytes: 4044
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <queue>

using namespace std;

#pragma GCC oprimize("Ofast")
#define rep(i,a,b) for(__typeof(b)i=a;i<b;++i)
#define fs first
#define sc second
#define pb emplace_back

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vl2;
typedef pair<ll,ll> pl;

const ll inf = ~((ll)1<<(ll)63);

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

    ll p,q,r;
    cin >> p >> q >> r;
    ll ans = inf;
    ans = min(ans, p+q);
    ans = min(ans, p+r);
    ans = min(ans, q+r);

    cout << ans;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll ans=0;
    ll now=0;
    while(now<n){
        if(now==n-1){
            ans++;
            break;
        }else{
            ans++;
            ll k=now+1;
            while(k<n && a[now]==a[k]){
                k++;
            }
            if(k==n){
                break;
            }else{
                if(a[now]<a[k]){
                    ll l=k;
                    while(l+1<n && a[l]<=a[l+1]){
                        l++;
                    }
                    if(l==n-1){
                        break;
                    }else{
                        now=l+1;
                        continue;
                    }
                }else{
                    ll l=k;
                    while(l+1<n && a[l]>=a[l+1]){
                        l++;
                    }
                    if(l==n-1){
                        break;
                    }else{
                        now=l+1;
                        continue;
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}






Measured memory_bytes: 1024
/* compatible with http://kk.kake.info.waseda.ac.jp/~kakehi/lp12/wl/ */
#include <stdio.h>
enum{M=99};
bigint_init(int a[], int x){
	int z;
	z=0;
	while(z<=M){a[z]=0;z=z+1;}
	a[M]=0;
	while(x/10){a[a[M]]=x%10;a[M]=a[M]+1;x=x/10;}
	a[a[M]]=x%10;
	a[M]=a[M]+1;
}
bigint_print(int a[]){
	int i;
	i=a[M]-1;
	while(i>-1){fputc(a[i]+'0',stdout);i=i-1;}
}
bigint_add(int a[], int x[]){
	int i,c;
	i=0;
	c=0;
	while(i<M){
		a[i]=a[i]+x[i]+c;
		c=a[i]/10;
		a[i]=a[i]%10;
		if(a[i])a[M]=i+1;
		i=i+1;
	}
}
bigint_mul(int A[], int x[]){
	int i,j,c;
	int a[M];
	i=A[M]-1;c=0;
	while(c<M){a[c]=0;c=c+1;}
	c=0;
	while(i>-1){
		j=0;
		while(j<x[M]){
			a[i+j]=a[i+j]+A[i]*x[j];
			j=j+1;
		}
		i=i-1;
	}
	i=0;
	while(i<M){
		a[i]=a[i]+c;
		c=a[i]/10;a[i]=a[i]%10;
		if(a[i])A[M]=i+1;
		i=i+1;
	}
	i=0;while(i<M){A[i]=a[i];i=i+1;}
}
int main(){
	int i,n,c;
	int ten[M+1],d1[M+1];
	bigint_init(ten,10);
	n=0;
	c=fgetc(stdin);
	while('0'<=c&&c<='9'){
		n=n*10;n=n+c-'0';
		c=fgetc(stdin);
	}
	while(n>0){
		int f1[M+1],f2[M+1];
		bigint_init(f1,0);
		c=fgetc(stdin);
		while('0'<=c&&c<='9'){
			bigint_mul(f1,ten);
			bigint_init(d1,c-'0');
			bigint_add(f1,d1);
			c=fgetc(stdin);
		}
		bigint_init(f2,0);
		c=fgetc(stdin);
		while('0'<=c&&c<='9'){
			bigint_mul(f2,ten);
			bigint_init(d1,c-'0');
			bigint_add(f2,d1);
			c=fgetc(stdin);
		}
		bigint_add(f1,f2);
		if(f1[M]>80){
			fputc('o',stdout);
			fputc('v',stdout);
			fputc('e',stdout);
			fputc('r',stdout);
			fputc('f',stdout);
			fputc('l',stdout);
			fputc('o',stdout);
			fputc('w',stdout);
		}else{
			bigint_print(f1);
		}
		fputc('\n',stdout);
		n=n-1;
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define all(a)  a.begin(), a.end()
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const double eps = 1e-8;
#define EQ(a,b) (fabs((a)-(b))<eps)
inline int max(int a,int b){return a<b?b:a;}
inline int min(int a,int b){return a>b?b:a;}
inline ll max(ll a,ll b){return a<b?b:a;}
inline ll min(ll a,ll b){return a>b?b:a;}
const int mod = 1e9+7;
const int N = 5e5+10;
const ll inf = 1e18;

ll power(ll a,ll n){
	if(n==0){
		return 1;
	}
	ll b = power(a,n/2);
	b = b*b%mod;
	if(n%2) b= b*a%mod;
	return b;
}

int add(int a,int b){ return (a+b)%mod;}
int mul(int a,int b){ return (ll)a*b%mod;}

int nxt[N], nxtc[N][26], nxtLG[N][20];
char s[N];

int main(){
 // 	freopen("nice.in","r",stdin);
 // freopen("nice.out","w",stdout);	
	scanf("%s",s);
	int n = strlen(s);
	REP(i,26) nxtc[n][i]=-1;
	nxt[n]=-1;

	for(int i=n-1;i>=0;i--){
		nxtc[i][s[i]-'a']=i+1;
		REPP(j,s[i]-'a'+1,26){
			if(nxtc[i][j-1]!=-1) nxtc[i][j] = nxtc[nxtc[i][j-1]][j-1];
			else nxtc[i][j] = -1;
		}
		if(nxtc[i][25]!=-1) nxt[i] = nxtc[nxtc[i][25]][25];
		else nxt[i]=-1;
		REP(j,s[i]-'a'){
			if(nxt[i]!=-1) nxtc[i][j] = nxtc[nxt[i]][j];
			else nxtc[i][j] = -1;
		}
	}

	REP(i,n+1) nxtLG[i][0] = nxt[i];
	REPP(j,1,20) REP(i,n+1)
		if(nxtLG[i][j-1]!=-1) nxtLG[i][j] = nxtLG[nxtLG[i][j-1]][j-1];
		else nxtLG[i][j] = -1;

	int q;
	scanf("%d",&q);
	while(q--){
		int l,r;
		scanf("%d %d",&l,&r); l--;
		int f = 0;
		for(int i=19;i>=0;i--){
			if(nxtLG[l][i]==-1) continue;
			if(nxtLG[l][i]==r){
				f=1;break;
			}else if(nxtLG[l][i]<r){
				l = nxtLG[l][i];
			}
		}
		if(f) printf("Yes\n");
		else printf("No\n");
	}

	return 0;
}




Measured memory_bytes: 92928
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A_sort = sorted(set(A))

bool_list = [True] * (10 ** 6)

duplicate_dic = defaultdict(int)
for a in A:
    duplicate_dic[a] += 1
    if duplicate_dic[a] > 1:
        bool_list[a - 1] = False

for a in A_sort:
    for i in range(2*a, 10 ** 6 + 1, a):
        bool_list[i - 1] = False

print(sum([1 for a in A_sort if bool_list[a - 1]]))


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(c - a + b, 0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int n;
  cin >> n;
  
  vector<string> s(n);
  
  for(int i = 0; i < n; i++){
    cin >> s.at(i);
  }
  
  sort(s.begin(), s.end());
  
  int sn[200000] = {0};
  int j = 0;
  int max = 0;
  
  for(int i = 0; i < n - 1; i++){
    sn[j]++;
    while(s.at(i) == s.at(i + 1)){
      sn[j]++;
      i++;
      if(i == n - 1)
        break;
    }
    if(max < sn[j]){
      max = sn[j];
    }
    j++;
  }
  
  if(s.at(n - 2) != s.at(n - 1)){
    sn[j]++;
  }
  
  j = 0;
  int sum = 0;
  
  while(sn[j] > 0){
    if(sn[j] == max){
      cout << s.at(sum) << endl;
    }
    sum += sn[j];
    j++;
  }
  
  return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    int i;
    for(i = 0; i < 20000; i++){
        if((i * 8) / 100 == a && (i * 10) / 100 == b) break;
    }
    if(i == 20000) cout << -1 << endl;
    else cout << i << endl;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double dd;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<ll, ll> pll;

#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(c) (c).begin(), (c).end()
#define MOD 1000000007
#define MAX 110

int main(){
#ifdef HOME
    freopen("kek.in", "r", stdin);
    freopen("kek.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vi arr(n);
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    map<int, int> ma;
    for(int i = 0; i < n; i++){
        if(!ma.count(arr[i]))
            ma[arr[i]] = 1;
        else
            ma[arr[i]]++;
        if(!ma.count(arr[i] + 1))
            ma[arr[i] + 1] = 1;
        else
            ma[arr[i] + 1]++;
        if(!ma.count(arr[i] - 1))
            ma[arr[i] - 1] = 1;
        else
            ma[arr[i] - 1]++;
    }
    auto x = std::max_element(ma.begin(), ma.end(),
                              [](const pair<ld, int>& p1, const pair<ld, int>& p2) {
                                  return p1.second < p2.second; });
    cout << x -> second;
    return 0;
}

Measured memory_bytes: 5120
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define INF (1LL << 60)

#define MAXN (1 << 20)

ll a[MAXN], f[MAXN];

ll n, k;

bool ok(ll val) {
	ll ret = 0;
	for (int i = 0; i < n; i++) {
		ll t = val - (val % f[i]);	
		ll x = max(0LL, a[i] - (t / f[i]));
		ret += x;
	}
	return (ret <= k);
}

int main() {
	cin >> n >> k;
	ll sum = 0;
	for (int i= 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		cin >> f[i];
	}
	sort(f, f + n, greater<ll>());
	if (k >= sum) {
		cout << 0 << endl;
		return 0;
	}

	ll l = 0, r = INF;

	while (r - l > 1) {
		ll med = (l + r) / 2;
		if (ok(med)) {
			r = med;
		} else {
			l = med;
		}
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 6732
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
#define vv(a,b) vector< vector<int> > v(a,vector<int>(b,0));
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    ll n,x;
    cin>>n>>x;
    ll a=max(n-x,x),b=min(n-x,x);
    ll ans=n;
    while(b)
    {
        ll q=a/b;
        ll r=a%b;
        ans+=(b*2)*q;
        if(r==0)ans-=b;

        a=b,b=r;
    }
    cout<<ans<<endl;
}


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

class CMem {
public :
	CMem() { m_sale = 0; m_rank = 0; m_mill = false; }
	void Idata(long long sale);
	void ONmill() { m_mill = true; }
	bool Irank(int rank);
	int Orank() { return m_rank; }
	bool Omill() { return m_mill; }
private :
	bool m_mill;
	long long m_sale;
	int m_rank;
};

void CMem::Idata(long long sale) {
	if(m_mill == false) {
		m_sale += sale;
		if(m_sale >= 1000000) {
			m_mill = true;
		}
	}
}

bool CMem::Irank(int rank) {
	if(m_rank == 0) {
		m_rank = rank;
		return true;
	}
	else {
		return false;
	}
}

int main(void)
{
	while(1) {
		CMem member[4001];
		bool NA = true;
		int n, id, rank = 1, mrank;
		long long asale, scale, sale;

		cin >> n;
		if(n == 0) break;

		for(int i = 0; i < n; i++) {
			cin >> id >> asale >> scale;
			sale = asale * scale;

			if(member[id].Irank(rank) == true) { rank++; }
			if(sale >= (long long)1000000) { member[id].ONmill(); }
			else { member[id].Idata(sale); }
		}

		mrank = rank - 1;

		for(rank = 1; rank <= mrank; rank++) {
			for(int i = 1; i <= 4000; i++) {
				if(member[i].Orank() == rank && member[i].Omill() == true) {
					cout << i << endl;
					NA = false;
				}
			}
		}

		if(NA == true) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1260
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    string s,t;
    cin >> s >> t;
    ll ans = 10e9;
    if(s.size() == t.size()){
        ll tmp = 0;
        rep(i, s.size()){
            if(s[i] != t[i]){
                tmp++;
            }
        }
        cout << tmp;
        return 0;
    }
    rep(i, s.size()-t.size()){
        ll tmp = 0;
        rep(j, t.size()){
            if(s[i+j] != t[j]){
                tmp++;
            }
        }
        ans = min(tmp, ans);
    }
    cout << ans;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#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 REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll t;
ll ret = 0;
ll A = 0, B = 0, C = 0;
string s;


void input() {
  IN(N);
}

void solve() {
  double pi = 3.141592;
  double l = ((double)N) * pi * 2.0;
  cout << fixed << setprecision(5) << l << endl;
}

int main(void){
  input();
  solve();
}


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

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

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<ll,ll> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

int xs[1<<16][16], ys[1<<16][16];

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	array<ll, 18> x, y, p;
	rep(i, n) cin >>x[i] >>y[i] >>p[i];
	
	rep(i, 1<<n) rep(k, n){
		int dsx = MD,  dsy= MD;
		rep(j, n) if(j !=k &&(i>>j &1)){
			dsx = min<ll>(dsx, abs(x[k] - x[j]));
			dsy = min<ll>(dsy, abs(y[k] - y[j]));
		}
		xs[i][k] = dsx; 
		ys[i][k] = dsy; 
	}
	
	const int pj = 3;
	array<ll, 18> ans;
	ans.fill(1LL<<55);
	int mmx = 1; rep(i, n) mmx*=3;
	rep(i, mmx){
		array<ll, 18> hl, xx, yy;
		int ch=0, cs=0, hx=0, hy=0;
		for(int j=0, wki=i; j<n; j++, wki/=pj){
			int nw = wki%pj;
			if(nw==0) hl[ch++] = j;
			else if(nw==1){ hx |=(1<<j); cs++;}
			else if(nw==2){ hy |=(1<<j); cs++;}
		}
		ll sm = 0;
		rep(j, ch){
			auto z = hl[j];
			ll cnd = min(abs(x[z]), abs(y[z]));
			cnd = min<ll>(cnd, xs[hx][z]);
			cnd = min<ll>(cnd, ys[hy][z]);
			sm += cnd * p[z];
		}
		ans[cs] = min(ans[cs], sm);
	}
	
	rep(i, n+1) cout <<ans[i] <<"\n";
}



Measured memory_bytes: 7764
#include <iostream>
#include<map>
using namespace std;
long long n;
map<long long,long long>q;
map<long long,long long>::iterator it;
long long  modl(long long a, long long b, long long c)        //快速幂取余a^b%c
{
    long long res, t;
    res = 1 % c;
    t = a % c;
    while (b)
    {
        if (b & 1)
        {
            res = res * t % c;
        }
        t = t * t % c;
        b >>= 1;
    }
    return res;
}
long long mod=1e9+7;
int main()
{
    q.clear();
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        long long num;
        cin>>num;
        q[num]++;
    }
    if(q[0]>1)
    {
        cout<<"0"<<endl;
    }
    else if(q[0]==1||q[0]==0)
    {
        int num=0;
        for(it=q.begin();it!=q.end();it++)
        {
            if(it->second==2)
            {
                num++;
            }
            else if(it->second>2)
            {
                cout<<"0"<<endl;
                return 0;
            }
        }
        num%=mod;
        cout<<modl(2,num,mod)%mod<<endl;
    }
    return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong a, b, c, d;
  cin >> a >> b >> c >> d;

  llong ans1 = max({a * c, a * d, b * c, b * d});
  llong ans2 = -inf;
  if ((a <= 0 && 0 <= b) || (c <= 0 && 0 <= d)) {
    ans2 = 0;
  }
  
  cout << max(ans1, ans2) << endl;

  return 0;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int D = Integer.parseInt(sc.next());
    int X = Integer.parseInt(sc.next());
    
    int ans = X+N;
    for(int i = 0; i < N; i++){
      int n = Integer.parseInt(sc.next());
      for(int j = n+1; j <= D; j += n){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23892
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = new String();
		S = sc.next();
		
		switch (S) {
		case "SUN" :
			System.out.print("7");
		    break;
		case "MON" :
			System.out.print("6");
			break;
		case "TUE" :
			System.out.print("5");
			break;
		case "WED" :
			System.out.print("4");
			break;
		case "THU" :
			System.out.print("3");
			break;
		case "FRI" :
			System.out.print("2");
			break;
		case "SAT" :
			System.out.print("1");
			break;
		}
	}
}

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

using ll = long long;
ll modinv(ll a, ll m) {
	assert(m > 0);
	if (m == 1) return 0;
	a %= m;
	if (a < 0) a += m;
	assert(a != 0);
	if (a == 1) return 1;
	return m - modinv(m, a) * m / a;
}

template <int MOD_> struct modnum {
private:
	int v;
public:
	static const int MOD = MOD_;

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int () const { return v; }
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum operator ~ () const {
		modnum res;
		res.v = modinv(v, MOD);
		return res;
	}

	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= (~o);
	}

	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

using num = modnum<998244353>;

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	string X;
	cin >> n >> X;
	reverse(X.begin(), X.end());
	X += "0";
	for(char& r : X){
		if(r == '1'){
			r = '0';
		} else {
			r = '1';
			break;
		}
	}
	reverse(X.begin(), X.end());

	const int N = 2 * n;
	set<int> D;
	map<int, num> ans;
	for(int d = 1; d * d <= N; d++){
		if(N % d == 0){
			D.insert(d);
			D.insert(N/d);
		}
	}
	for(int d : D){
		if((N / d) % 2 == 0) continue;
		num z = 0;
		vector<int> st(d/2, 0);
		num cur = 1;
		for(int i = 0; i < d/2; i++) cur *= 2;
		if(X[0] == '1') z += cur;
		for(int i = 0; i < n; i++){
			int r = i % d;
			int what = 1;
			if(r >= d/2){
				what = 2;
				r -= d/2;
			}
			if(X[i+1] == '1'){
				if(st[r] == 0){
					z += cur / 2;
				} else if(st[r] == what){
					z += cur;
				}
				if(st[r] == 0){
					st[r] = 3 ^ what;
					cur /= 2;
				} else if(st[r] == what){
					st[r] = 3;
					cur = 0;
				}
			} else {
				if(st[r] == 0){
					st[r] = what;
					cur /= 2;
				} else if(st[r] == (3 ^ what)){
					st[r] = 3;
					cur = 0;
				}
			}
			if(cur == 0) break;
		}
		ans[d] = z;
	}

	num A = 0;
	map<int, num> realans;
	for(int d : D){
		num v = ans[d];
		for(auto r : realans){
			if(d % r.first == 0) v -= r.second;
		}
		realans[d] = v;
		A += d * v;
	}
	cout << (int) A << '\n';
}

Measured memory_bytes: 1556
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-12;
const double PI = acos(-1.0);
 
int main() {
    double r;
    cin >> r;
    cout << 2*PI*r << endl;
	return 0;
}

Measured memory_bytes: 3724
#include <iostream>
    #include <string>
    #include <math.h>
    #include <stdio.h>
     
    using namespace std;
     
    int main() {
    int a,b,c;
cin >> a>>b>>c;
    double d,e,f,g;
    d=c*3.141592653/180;
    e=0.5*a*b*sin(d);
    f=a+b+sqrt(a*a+b*b-2*a*b*cos(d));
    g=b*sin(d);
    printf("%.7f\n",e);
    printf("%.7f\n",f);
    printf("%.7f\n",g);
    return 0;
    }

Measured memory_bytes: 1196
#include<iostream>
#include<vector>
#include <cmath>

using namespace std;


int main() {
	string s;
	cin >> s;
	int s_length = s.length();
	int s_half1 = (s_length - 1) / 2;
	int s_half2 = (s_length + 3) / 2;

	for (int i = 0; i < (s_length-1)/2; i++) {
		if (s[i] != s[s_length - i - 1]) {
			cout << "No" << endl;
			return 0;
		}

		if (s[i] != s[s_half1 - i - 1]) {
			cout << "No" << endl;
			return 0;
		}

		if (s[s_length - i - 1] != s[s_half1 + 1 + i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <utility>
#include <queue>

struct pair_hash {
	    inline std::size_t operator()(const std::pair<int,int> & v) const {
		            return v.first*31+v.second;
			        }
};

int main(){
	std::unordered_map<int,std::unordered_set<int>> adj;
	std::unordered_map<std::pair<int,int>, int, pair_hash> weights;
	
	int N,M;
	std::cin >> N >> M;

	for(int i = 0 ; i < M; ++i){
		int a,b;
		std::cin >> a >> b;
		a-=1;
		b-=1;
		if(adj.count(a) == 0)
			adj[a] = {b};
		else
			adj[a].insert(b);

		if(adj.count(b) == 0)
			adj[b] = {a};
		else
			adj[b].insert(a);
	}

	std::vector<int> dist;
	std::vector<int> parent;

	const int mm = 9999999;
	for(int i = 0 ; i < N;++i){
		dist.push_back(mm);
		parent.push_back(-1);
	}

	std::priority_queue<std::pair<int,int>, std::vector<std::pair<int,int>>, std::greater<std::pair<int,int>>> pq;
	dist[0] = 0;
	pq.push(std::make_pair(0,0));

	while(!pq.empty()){
		int min = pq.top().second;
		pq.pop();
	
		for(auto x : adj[min]){
			if(dist[min] + 1 < dist[x]){
				dist[x] = dist[min] + 1;
				parent[x] = min;
				pq.push(std::make_pair(dist[x],x));
			}
		}
	}
	for(int i = 1; i < N; ++i){
		if(parent[i] == -1){
			std::cout << "No" << std::endl;
			return 0;
		}
	}
	std::cout << "Yes\n";
	for(int i = 1; i < N; ++i){
		std::cout << parent[i]+1 << "\n";
	}
}


Measured memory_bytes: 32044
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))

c = [[0 for i in range(w)] for j in range(h)]
fromL = True
x = 0
y = 0

for i in range(1, n+1) :
    for j in range(a[i-1]) :
        c[y][x] = i
        if w == 1 :
            y += 1
        elif fromL :
            if x == w - 1 :
                y += 1
                fromL = False
            else :
                x += 1
        else :
            if x == 0 :
                y += 1
                fromL = True
            else :
                x -= 1

for ci in c :
    print(*ci)

Measured memory_bytes: 3916
from bisect import bisect

s = list(input())
n = len(s)

r_idx = []
l_idx = []
ans = [0 for x in range(n)]

for i in range(n):
    if s[i] == 'R':
        r_idx.append(i)
    else:
        l_idx.append(i)

for r in r_idx:
    idx = bisect(l_idx, r)
    dist = l_idx[idx] - r
    if dist % 2 == 0:
        ans[l_idx[idx]] += 1
    else:
        ans[l_idx[idx]-1] += 1

for l in l_idx:
    idx = bisect(r_idx, l) - 1
    dist = l - r_idx[idx]
    if dist % 2 == 0:
        ans[r_idx[idx]] += 1
    else:
        ans[r_idx[idx]+1] += 1

print(*ans)


Measured memory_bytes: 15464
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
using namespace std;
const int INF = 1e18;

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    cout << min(n % k, abs(n % k - k)) << endl;
}

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


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "Heisei";
            if (sS.CompareTo("2019/04/30") > 0) { sOut = "TBD"; }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13408
N = int(input())
H = list(map(int,input().split()))
H[0] -= 1
for i in range(1, N):
    if H[i] > H[i - 1]:
        H[i] -= 1
    elif H[i] < H[i - 1]:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 14396
N = int(input())
srimes = input().split(" ")

result = 0
before_srime = 0

# 右隣にあるものが同じかどうかを判定
for i, srime in enumerate(srimes):
    
    # if i > 1:
    # print("i : {}, srime : {}, before_srime : {}".format(i, srime, before_srime))
    if before_srime == srime:
        # print("HIT!!!!!!!!!")
        result += 1
        before_srime = int(before_srime) + 10001
        continue
    before_srime = srime

print(result)

Measured memory_bytes: 2940
#include<cstdio>
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
int a,b;
int mp[402][402];
int main()
{
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	scanf("%d%d",&a,&b);
	--a; --b;
	printf("100 100\n");
	for (int i=1;i<=50;++i)
		for (int j=1;j<=100;++j)
			mp[i][j]=1;
	for (int i=51;i<=100;++i)
		for (int j=1;j<=100;++j)
			mp[i][j]=0;
	
	for (int i=2;i<=48;i+=2)
		for (int j=2;j<=98;j+=2)
			if (a>0)
			{
				--a;
				mp[i][j]=0;
			}
	for (int i=52;i<=98;i+=2)
		for (int j=2;j<=98;j+=2)
			if (b>0)
			{
				--b;
				mp[i][j]=1;
			}

	for (int i=1;i<=100;++i)
	{
		for (int j=1;j<=100;++j)
		{
			if (mp[i][j]) printf("#");
			else printf(".");
		}
		printf("\n");
	}
	return 0;
}

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

int main(){
	int n;
  	bool flag=false;
  	cin >> n;
  	vector<char> str(n);
  	for(int i=0;i<str.size();i++){
      cin >> str.at(i);
      if(str.at(i) == 'Y'){
        flag = true;
      }

    }
    
  	if(flag){
      cout << "Four" << endl;
    }else{
      cout << "Three" << endl;
    }
  	
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  map<char, ll> num;
  ll N;
  cin >> N;
  rep(i, N){
    string s;
    cin >> s;
    num[s[0]]++;
  }

  ll ans = 0;
  ll A[] = {num['M'],num['A'],num['R'],num['C'],num['H']};
  FOR(i, 0, 5){
    FOR(j, i+1, 5){
      FOR(k, j+1, 5){
        ans += A[i]*A[j]*A[k];
      }
    }
  }

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


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll K;
    cin >> K;

    ll count = 0;
    unordered_map<ll, ll> m;
    ll n = 1;
    ll ord = 1;
    ll last = 0;
    while(true){
        if(n>=ord*10) ord *= 10;
        ll sub = n % ord;
        ll valid = true;
        if(sub<ord/10){
            ll msd = sub;
            while(msd/10>0) msd /= 10;
            if(msd>=2) valid = false;
        }
        if(valid){
            if(n<10){
                ++count;
                m[last] = n;
                last = n;
            }
            else{
                ll d1 = n/ord, d2 = sub%ord*10/ord;
                if(abs(d1-d2)<=1){
                    ++count;
                    m[last] = n;
                    m[n] = -1;
                    last = n;
                }
            }
        }
        if(count==K){
            cout << n << endl;
            return 0;
        }
        if(m.find(sub)==m.end()) ++n;
        else if(m[sub]==-1) n = 10*ord;
        else n = n/ord*ord + m[sub];
    }
}


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

typedef long long LL;

char s[1000];
int ans=0;
int main()
{
    scanf("%s",s+1);
    int len=strlen(s+1);
    for(int i=1;i<=len;i++)
    {
        if(i>len/2) break;
        ans+=(s[i]==s[len+1-i]?0:1);
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

const int MOD = 1000000007;

int main(){
	vector<long long> inv(1001);
	vector<long long> fact(1001);
	vector<long long> factInv(1001);
	for(int i=0;i<2;i++) inv[i] = fact[i] = factInv[i] = 1;
	for(int i=2;i<inv.size();i++){
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		fact[i] = fact[i-1] * i % MOD;
		factInv[i] = factInv[i-1] * inv[i] % MOD;
	}
	auto comb = [&](int n, int r){
		if(n < r || r < 0) return 0LL;
		return fact[n] * factInv[n-r] % MOD * factInv[r] % MOD;
	};
    int N, K;
    while(cin >> N >> K){
        vector<int> a(K);
        for(auto& t : a) cin >> t;
        vector<long long > dp(N+1, 0);
        dp[0] = fact[N];
        for(auto t : a){
            vector<long long> next(N+1, 0);
            for(int i=0;i<=N;i++){
                for(int j=0;j+i<=N;j++){
                    next[i+j] += dp[i] * comb(N-j, t-j) % MOD * factInv[j];
                    next[i+j] %= MOD;
                }
            }
            dp = next;
        }
        cout << dp.back() << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
    public static int Main()
    {
        UInt32 bits = 0;
        string w = Console.ReadLine();

        for (int i = 0; i < w.Length; ++i)
        {
            char c = w[i];
            bits = bits ^ (1u << (c - 'a'));
        }

        if (bits == 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
        return 0;
    }
}


Measured memory_bytes: 2648
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str


def solve(N: int, p: "List[int]"):
    count = 0

    for i, count_down in enumerate(range(1, N)):

        if not count_down == p[i]:
            count += 1

    if count <= 2:
        print(YES)
    else:
        print(NO)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, p)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
n = int(input())
a = [int(x)-1 for x in input().split()]

b = []
c = []
for i in range(n):
	b.append((i, a[i]))
	c.append((a[i], i))

c = set(c)
b = set(b)

ans = len(b & c)
print(ans//2)
	

Measured memory_bytes: 39008
#include <iostream>
#include <vector>
#include <iomanip>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(int argc, char const *argv[])
{
  int n; cin >> n;
  /*
  vector<ull> a(n);
  ull numer=1uLL, denom=0uLL;
  rep(i,n) {
    cin >> a[i];
    numer *= a[i];
  }
  rep(i,n) {
    denom += numer/a[i];
  }
  cout << ((long double)numer) / ((long double)denom) << endl;
  */
  long double denom = 0.;
  int a;
  rep(i,n) {
    cin >> a;
    denom += ((long double)1.0) / a;
  }
  cout << setprecision(15) << ((long double)1.0) / denom << endl;


  return 0;
}

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

long long max(int a, int b){
    if(a>=b) return a;
    else return b;
}

long long min(int a, int b){
    if(a<=b) return a;
    else return b;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a.at(i);
    
    long long mi = a.at(0), ma = a.at(0), su = a.at(0);
    for(int i=1; i<n; i++){
        mi = min(mi, a.at(i));
        ma = max(ma, a.at(i));
        su += a.at(i);
    }
    cout << mi << " " << ma << " " << su << endl;
    return 0;
    
    
}


Measured memory_bytes: 3152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int[] arr = fs.nextIntArray(3);
        Arrays.sort(arr);
        System.out.println(arr[2] * 10 + arr[1] + arr[0]);
    }

    static final class Utils {
        public static void shuffleSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffleSort(long[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void shuffle(long[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            final int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        public static void swap(long[] x, int i, int j) {
            final long t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Utils() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


Measured memory_bytes: 32776
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
using ll = long long;
using namespace std;
using P = pair<int, int>;


int main() {
  int K;
  cin >> K;
  queue<ll> q;
  rep(i, 9) q.push(i+1);
  while (true){
      ll now = q.front(); q.pop();
      K--;
      if (K == 0){
          cout << now << endl;
          return 0;
      }
      int d = now % 10;
      for (int i = d-1; i <= d+1; i++){
          if((i < 0) || (i >= 10)) continue;
          else q.push(now*10 + i);
      }
  }
}


Measured memory_bytes: 5132
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;
const ll N = 2e5 + 2;
ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}

ll vis[N] = {}, ans = 0, c = 0;


void dfs(vlli v[], ll x){
    if(!vis[x]){
        c++;
        // cout<<x<<" "<<c<<endl;
        ans = max(ans, c);
        vis[x] = 1;
        forn(i, 0, v[x].size()){
            dfs(v, v[x][i]);
        }
    }
    
}

int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
    ll n, m;
    cin>>n>>m;
    vlli v[n+1];
    ll x, y;
    forn(i, 0, m){
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    
    forn(i, 1, n+1){
        if(!vis[i]){
            // cout<<i<<":--"<<endl;
            c = 0;
            dfs(v, i);
            
        }
    }
    cout<<ans<<endl;
}

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

typedef long long ll;

template <class T>
void printArray(vector<T> arr) {
	for (T a: arr) cout << a << " ";
	cout << '\n';
}

void printVerdict(bool verdict) {
	cout << (verdict ? "YES": "NO") << '\n';
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int h, w, k;
	cin >> h >> w >> k;
	
	char grid[h][w];
	vector<int> rows(h, 0);
	vector<int> cols(w, 0);
	int count_black = 0;
	
	for (int i = 0; i<h; i++) {
		string input; cin >> input;
		for (int j = 0; j<w; j++) {
			grid[i][j] = input[j];
			if (grid[i][j] == '#') {
				count_black++;
				rows[i]++;
				cols[j]++;
			}
		}
	}
	
	int ret = 0;
	
	for (int mask_row = 0; mask_row < (1<<h); mask_row++) {
		vector<int> r;
		int row_cnt = 0;
		for (int i = 0; i<h; i++) {
			if (mask_row & (1<<i)) {
				r.push_back(i);
				row_cnt += rows[i];
			}
		}
		for (int mask_col = 0; mask_col < (1<<w); mask_col++) {
			vector<int> c;
			int total_cnt = row_cnt; 
			for (int i = 0; i<w; i++) {
				if (mask_col & (1<<i)) {
					c.push_back(i);
					total_cnt += cols[i];
				}
			}
			for (int val1: r) {
				for (int val2 : c) {
					total_cnt -= (grid[val1][val2] == '#');
				}
			}
			if (total_cnt == count_black - k) ret++;
		}
	}
	
	cout << ret << '\n';
}



Measured memory_bytes: 3668
n=int(input())
kakko=input()
openk=0
closek=0
for i in range(n):
    if kakko[i]=="(":
        openk+=1
    else:
        if openk>0:
            openk-=1
        else:
            closek+=1
mae="("*closek
ushiro=")"*openk
ans=mae+kakko+ushiro
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;

int main(){
	int N,a[2][110];
	cin >> N;

	rep(k,2){
		cin >> a[k][0];
		REP(i,1,N) {
			int tmp;
			cin >> tmp;
			a[k][i] = a[k][i-1]+tmp;
		}
	}

	int sum = a[1][N-1];
	for(int i = N-1; i>0 ; i--){
		a[1][i] = sum - a[1][i-1];
	}
	a[1][0]=sum;

	int ma = 0;
	
	rep(i,N){
		ma = max(ma,a[0][i]+a[1][i]);
	}

	cout << ma << endl;

	return 0;
}

Measured memory_bytes: 256