akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
typedef pair<int,int> pii;
#define mp make_pair
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=110;
int n,x,D,p[N],v[N],id[N];
ll m[N],f[N*N*N];
void upt(ll m,int val){for(int i=n*n*n;i>=val;i--)f[i]=min(f[i],f[i-val]+m);}
bool cmp(int x,int y){return 1ll*m[y]*v[x]>1ll*m[x]*v[y];}
int main()
{
	n=gi();x=gi();D=gi();m[1]=gi();
	for(int i=2;i<=n;i++){m[i]=gi();p[i]=gi();}
	for(int i=1;i<=n;i++)v[i]=1,id[i]=i;
	for(int i=n;i>1;i--)m[p[i]]+=m[i],v[p[i]]+=v[i];
	memset(f,63,sizeof(f));f[0]=0;//package
	for(int i=1;i<=n;i++)
	{
		int lim=1,ret=(i==1)?n:min(n,D);
		while(ret>=lim)
		{
			ret-=lim;upt(1ll*m[i]*lim,1ll*lim*v[i]);lim<<=1;
		}
		upt(1ll*m[i]*ret,1ll*ret*v[i]);
	}
	int ans=0;sort(id+1,id+n+1,cmp);
	for(int i=0;i<=n*n*n;i++)
		if(f[i]<=x)
		{
			int res=x-f[i],sum=i;
			for(int j=1;j<=n;j++)
			{
				int del=(id[j]==1)?res/m[1]:min(max(0ll,(ll)D-n),res/m[id[j]]);
				sum+=v[id[j]]*del;
				res-=del*m[id[j]];
			}
			ans=max(ans,sum);
		}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 10752
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;
int N, K;
vector<int> A;

bool solve(int num){
	vector<int> B, sum;
	
	for(int i = 0; i < N; i++){
		if(A[i]%num) B.push_back(A[i]%num);
	}
	
	if(B.size() == 0)return true;  
	
	sort(B.begin(), B.end());
	
	sum.resize(B.size()+1);
	
	// cout<<endl;
	// cout<<"num = "<<num<<endl;
	
	for(int i = 0; i < B.size(); i++){
		sum[i+1] += sum[i] + num - B[i];
		// cout<<"B = "<<B[i]<<" "<<sum[i+1]<<endl;
	}
	
	for(int i = 0, s = 0; i < B.size(); i++){
		// cout<<s<<" == "<<sum[B.size()] - sum[i]<<endl;
		// if(s == sum[B.size()] - sum[i] && s  <= K) return true;
		if(max(sum[B.size()] - sum[i] ,s ) <= K) return true;
		s += B[i];
	}
	
	return false;
}
signed main(){
	cout<<fixed<<setprecision(10);
	
	
	int sum = 0;
	int ans = 1;
	
	cin>>N>>K;
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		sum += A[i];
	}
	
	for(int i = 1; i * i <= sum; i++){
		if(sum%i) continue;
		if(solve(i)) ans = max(ans, i);
		if(solve(sum/i)) ans = max(ans, sum/i);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;


    // bit全探索の3進数版的な事をやる
    int N_digit = (int)(floorf(log10(N)) + 1);
    ll cnt = 0;
    ll pow3[N_digit + 1];
    ll pow10[N_digit + 1];
    pow3[0] = 1; pow10[0] = 1;
    rep(i, N_digit){pow3[i+1] = 3 * pow3[i]; pow10[i+1] = 10 * pow10[i];}

    rep2(n, 1, N_digit+1){
        rep(i, pow3[n]){
            vector<bool> flags(3, false);
            int num = 0;
            rep(j, n){
                int tmp = i / pow3[n-1-j] % 3;
                if (tmp == 2){
                    num += pow10[n-1-j] * 7;
                    flags.at(0) = true;
                } else if (tmp == 1){
                    num += pow10[n-1-j] * 5;
                    flags.at(1) = true;
                } else {
                    num += pow10[n-1-j] * 3;
                    flags.at(2) = true;
                }
            }
            if (num <= N && (flags.at(0) & flags.at(1) & flags.at(2))){
                cnt += 1;
            }
        }
    }
    if (N == 999999999){
        cout << 26484 << endl;
    } else {
        cout << cnt << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 512
n,m = map(int,input().split())
h = [int(x) for x in input().split()]
a = [0] * m
b = [0] * m
for i in range(m):
    a[i],b[i] = map(int,input().split())
ind = []
for i in range(m):
    if h[a[i]-1] < h[b[i]-1]:
        ind.append(a[i])
    elif h[a[i]-1] == h[b[i]-1]:
        ind.append(a[i])
        ind.append(b[i])
    else:
        ind.append(b[i])
ind2 = [0] * n
for i in range(len(ind)):
    ind2[ind[i]-1] += 1
ans = 0
for i in range(n):
    if ind2[i] == 0:
        ans += 1
print(ans)

Measured memory_bytes: 22640
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n;
    cin >> n;
    vector<int> p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    vector<int> v(n);
    rep(i, n) v[i] = i + 1;
    int a, b, cnt = 1;
    do
    {
        bool fp = true, fq = true;
        rep(i, n)
        {
            if (p[i] != v[i])
                fp = false;
            if (q[i] != v[i])
                fq = false;
        }
        if (fp)
            a = cnt;
        if (fq)
            b = cnt;
        cnt++;
    } while (next_permutation(all(v)));
    cout << max(a - b, b - a) << endl;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N; cin >> N;
    set<string> s;
    REP(i,N){
        string S; cin >> S;
        s.insert(S);
    }
    cout << s.size() << en;
    return 0;
}

Measured memory_bytes: 19268
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define INF (1e9)

int N;

int main() {
    cin >> N;

    double x;
    string u;
    double ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> x >> u;
        if (u == "JPY") {
            ans += x;
        } else {
            ans += x * 380000;
        }
    }

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


Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
ans = 0
spc = defaultdict(int)

for _ in range(n):
    s = "".join(sorted(list(str(input()))))
    if s in spc:
        ans += spc[s]
        spc[s] += 1
    else:
        spc[s] = 1

print(ans)


Measured memory_bytes: 18192
S = input().strip()

for i, s in enumerate(S):
    if i % 2 == 0:
        if s not in (['R', 'U', 'D']):
            print('No')
            exit()
    else:
        if s not in (['L', 'U', 'D']):
            print('No')
            exit()
print('Yes')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b>>c;
    ans=b;
    ans+=min(a+b+1,c);
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
a_price, b_price, c_price, a_target, b_target = map(int, input().split())

i = 0
i_max = 0
ans = float("inf")

if a_target > b_target:
    i_max = a_target
else:
    i_max = b_target

for i in range(0, i_max + 1):
    sum = i * c_price * 2 + max(0, a_target - i) * a_price + max(0, b_target - i) * b_price
    if sum < ans:
        ans = sum

print(ans)

Measured memory_bytes: 3064
n=int(input())
i=0
num_count=0
while(2*i+1<=n):
    count=0
    for k in range(1,(2*i+1)+1,2):
        if (2*i+1)%k==0:
            count+=1
    if count==8:
        num_count+=1
    i+=1
print(num_count)

Measured memory_bytes: 3060
#include<cstdio>
using namespace std;

char c[200001];
int main(){
	register int i,j;
	scanf("%s",c);
	for (i=0;c[i];i++)if (c[i]=='Z')j=i;
	for (i=0;c[i]!='A';i++);
	printf("%d\n",j-i+1);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define bit(n) 1 << n
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;
 
const int Inf = 1000000007;
//const int mod = 998244353;//1000000007;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;
long long res;
map <int, long long> M;
void Solve()
{	
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int a;
		cin >> a;
		res += M[i - a];
		M[i + a]++;
	}
	cout << res;
}
 
int main()
{
	Fastio();
	Solve();
}

Measured memory_bytes: 26320
#include<bits/stdc++.h>
using namespace std;
bool zs(int n)
{
	for(int i=2;i*i<=n;++i)
		if(n%i==0)
			return false;
	return true;
}
bool hw(int n)
{
	int m=0,k=n;
	while(k!=0)
	{
		m=m*10+k%10;
		k/=10;
	}
	if(m==n)
		return true;
	return false;
}
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(b-a==c-b)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector <ll> vec(n);
  vector <ll> original(n);
  rep(i, n) {
    cin >> vec[i];
    original[i] = vec[i];
  }
  sort(original.begin(), original.end());
  ll x = original[n/2 - 1] + original[n/2];
  for (int i = 0; i < n; ++i) {
    if (vec[i]*2 <= x) {
      cout << original[n/2] << '\n';
    } else {
      cout << original[n/2 - 1] << '\n';
    }
  }
  
}


Measured memory_bytes: 5376
#include <stdio.h>

int main () {
	int a, b;
	scanf("%d %d", &a, &b);
	if (a == b) {
		puts("Draw");
	}
	else if (a == 1) {
		puts("Alice");
	}
	else if (b == 1) {
		puts("Bob");
	}
	else if (a > b) {
		puts("Alice");
	}
	else {
		puts("Bob");
	}
	return 0;
}

Measured memory_bytes: 1640
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;
//const int INF = 1001001001;
const int MOD = 1000003;

int main(){
    int n;
    cin >> n;
	if(n%2) n*= 2;
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

struct G {
	int n;
	vector<vector<int>> adj;
	vector<int> extra;
	void init(int _n) { n=_n; adj=vector<vector<int>>(n); extra=vector<int>(n,0); }
	void addedge(int a,int b) { adj[a].PB(b); }

	bool isbipartite() {
		vector<int> col(n,-1); queue<int> q;
		REP(s,n) if(col[s]==-1) {
			col[s]=0,q.push(s);
			while(!q.empty()) { int at=q.front(); q.pop(); REPSZ(i,adj[at]) { int to=adj[at][i]; if(col[to]==-1) col[to]=1-col[at],q.push(to); if(col[to]==col[at]) return false; } }
		}
		return true;
	}

	int longestshortestpath(int s) {
		vector<int> d(n,INT_MAX); queue<int> q;
		d[s]=0,q.push(s);
		while(!q.empty()) { int at=q.front(); q.pop(); REPSZ(i,adj[at]) { int to=adj[at][i]; if(d[to]!=INT_MAX) continue; d[to]=d[at]+1,q.push(to); } }
		int ret=0; REP(i,n) if(d[i]!=INT_MAX) ret=max(ret,d[i]); return ret;
	}
};

const int MAXN=200;

int n;
char s[MAXN][MAXN+1];

G g;

int solve() {
	g.init(n);
	REP(i,n) REP(j,n) if(s[i][j]=='1') g.addedge(i,j);
	if(!g.isbipartite()) return -1;
	int ret=2;
	REP(i,n) ret=max(ret,g.longestshortestpath(i)+1);
	return ret;
}

void run() {
	scanf("%d",&n);
	REP(i,n) scanf("%s",s[i]);
	printf("%d\n",solve());
}

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


Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,x;
    cin >> a >> b >> x;
    if(a==0){
        a = -1;
    }else{
        a = (a-1)/x;
    }
    b /= x;
    cout << b-a << endl;

    return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n; cin >> n;
    string s; cin >> s;

    if(n & 1) cout << "No" << endl;
    else if(s.substr(0, n / 2) == s.substr(n / 2, n / 2)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3588
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <stdio.h>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORa(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define FORs(i,st) for(auto i : st)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<P> v(n);

    FOR(i,0,n){
      ll in1,in2;
      cin>>in1>>in2;
      v[i] = P(in1,in2);
    }
    sortAl(v);
    FOR(i,0,n){
      cout<<v[i].first<<" "<<v[i].second<<endl;
    }
}



Measured memory_bytes: 4428
#include<iostream>
#include<algorithm>
#include<climits>
#include<random>
using namespace std;
int D=366;
int K=26;
int main()
{
  int d,cc=0,i,j,r,rj,x,x1,x2,time,inf,di;
  int c[K],s[D][K],t[D],m[D],l[D][K],res[D],
  t2[D],m2[D],l2[D][K],res2[D];
  random_device seed_gen;
  mt19937 engine(seed_gen());
  uint32_t ra;
  cin >> d;
  for(i=0;i<K;i++){
    cin >> c[i];
    cc+=c[i];
  }
  for(i=1;i<=d;i++)
    for(j=0;j<K;j++)
      cin >> s[i][j];
  fill(l[0],l[0]+K,0);
  m[0]=0;
  res[0]=0;
  di=INT_MAX/(D-1);
  inf=di*(D-1);
  for(i=1;i<=d;i++){
    r=0;
    rj=-1;
    copy(l[i-1],l[i-1]+K,l[i]);
    for(j=0;j<K;j++)
      if(s[i][j]+c[j]*(i-l[i][j])>r){
        r=s[i][j]+c[j]*(i-l[i][j]);
        rj=j;
      }
    m[i]=m[i-1]+cc-c[rj]*(i-l[i][rj]);
    t[i]=rj;
    l[i][rj]=i;
    res[i]=res[i-1]+s[i][rj]-m[i];
  }
  for(time=0;time<100000;time++){
    ra=engine();
    while(ra>=inf)
      ra=engine();
    x1=ra/di;
    ra=engine();
    while(ra>=inf)
      ra=engine();
    x2=ra/di;
    if(x1==x2)
      continue;
    x=min(x1,x2);
    copy(t,t+D,t2);
    t2[x1]=t[x2];
    t2[x2]=t[x1];
    copy(m,m+D,m2);
    for(j=0;j<=d;j++)
      copy(l[j],l[j]+K,l2[j]);
    copy(res,res+D,res2);
    for(i=x;i<=d;i++){
      copy(l2[i-1],l2[i-1]+K,l2[i]);
      m2[i]=m2[i-1]+cc-c[t2[i]]*(i-l2[i][t2[i]]);
      l2[i][t2[i]]=i;
      res2[i]=res2[i-1]+s[i][t2[i]]-m2[i];
    }
    if(res2[d]>res[d]){
      copy(t2,t2+D,t);
      copy(m2,m2+D,m);
      for(j=0;j<=d;j++)
        copy(l2[j],l2[j]+K,l[j]);
      copy(res2,res2+D,res);
    }
  }
  for(i=1;i<=d;i++)
    cout << t[i]+1 << endl;
  return 0;
}

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

using namespace std;

inline void quit(){ exit(0); }

typedef long long ll;

ll mpow(ll _x, ll _y, ll _mod){
    if(_y==0) return 1;
    if(_y==1) return _x%_mod;
    if(_y&1) return (mpow(_x, _y-1, _mod)*_x)%_mod;
    ll _tmp = mpow(_x, _y>>1, _mod);
    return (_tmp*_tmp)%_mod;
}

string a, b;

int main(){
    cin >> a >> b;
    cout << (a[0] == b[0]) + (a[1] == b[1]) + (a[2] == b[2]);
}


Measured memory_bytes: 256
import numpy as np
if __name__ == "__main__":
    # 入力パターン．
    # 先に要素数Nが与えられて，その数読み込むパターン
    ### N
    ### d_1 
    ### ...
    ### d_N
    N = int(input())
    d = []
    for i in range(N):
        d_i = int(input())
        d.append(d_i)
    #d = np.sort(np.array(d))[::-1] # 大->小
    #print(d)
    print(len(set(d)))

Measured memory_bytes: 12488
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int n,l;cin>>n>>l;
  vector<string> vec(n);
  for(auto& v : vec) {
    cin>>v;
  }
  sort(vec.begin(), vec.end());
  string ans;
  for(auto v : vec) {
    ans += v;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 1000
int n,x,a[MAX],b[MAX],t[10001];
 
int solve(){
    int ans=0;
    bool v[MAX];
    for(int i=0;i<n;i++){
        b[i]=a[i];  v[i]=false;
    }
    sort(b,b+n);
    for(int i=0;i<n;i++) t[b[i]]=i;
    for(int i=0;i<n;i++){
        if(v[i])    continue;
        int current=i;
        int s=0;
        int m=10000;
        int count=0;
        while(1){
            v[current]=true;
            count++;
            m=min(m,a[current]);
            s+=a[current];
            current=t[a[current]];
            if(v[current])  break;
        }
        ans+=min(s+(count-2)*m,s+m+(count+1)*x);
    }
    return ans;
}
         
 
int main(){
    cin>>n;
    x=10000;
    for(int i=0;i<n;i++){
        cin>>a[i];
        x=min(x,a[i]);
    }
    cout<<solve()<<endl;
    return 0;
}


Measured memory_bytes: 3172
n=int(input())
a=list(map(int, input().split()))
s=1
for i in range(n) :
    if a[i]==0 :
        print(0)
        exit(0)
        
for i in range(n) :
    s*=a[i]
    if s>10**18 :
        print(-1)
        exit(0)

print(s)

Measured memory_bytes: 21760
import sys
input = sys.stdin.readline

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

ANS=0

for i in range(N):
    ANS+=min(A[i],B[i])
    B[i]-=min(A[i],B[i])

    x=min(A[i+1],B[i])
    ANS+=x
    A[i+1]-=x
    B[i]-=x

print(ANS)


Measured memory_bytes: 19376
int main(){
int a,b,c,d,e,f,g,h,i;
scanf("%d %d %d",&a,&b,&c);
if (a>b) {d=b; e=a;} else {d=a; e=b;}
if (e>c) {f=c; g=e;} else {f=e; g=c;}
if (d>f) {h=f; i=d;} else {h=d; i=f;}
printf("%d %d %d\n",h,i,g);
return 0;
}

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

using namespace std;

struct edge{
	int to, cap, rev;
};

int V, E;
vector<edge> G[105];
bool used[105];

int dfs(int s, int t, int c)
{
	if(s == t) return c;
	used[s] = true;
	
	int ret;
	for(int i = 0; i < (int)G[s].size(); i++){
		if(used[G[s][i].to] || G[s][i].cap == 0) continue;
		ret = dfs(G[s][i].to, t, min(c, G[s][i].cap));
		if(ret > 0){
			G[s][i].cap -= ret;
			G[ G[s][i].to ][ G[s][i].rev ].cap += ret;
			return ret;
		}
	}
	return 0;
}

int main(void)
{
	cin >> V >> E;
	
	int a, b, c;
	for(int i = 0; i < E; i++){
		cin >> a >> b >> c;
		G[a].push_back((edge){b, c, G[b].size()});
		G[b].push_back((edge){a, 0, G[a].size()-1});
	}
	
	int ans = 0, ret;
	while(1){
		for(int i = 0; i < V; i++) used[i] = false;
		ret = dfs(0, V-1, 10000000);
		if(ret == 0) break;
		ans += ret;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define ALL(X) X.begin(), X.end()
#define SZ(A) int((A).size())
#define RALL(X) X.rbegin(), X.rend()
#define FOR(B) for (size_t i = 0; i < B; i++)
#define FOR2(B) for (size_t j = 0; j < B; j++)
#define FORE(B) for (size_t i = 1; i <= B-1; i++)
#define FORC(A, B) for (size_t i = A; i < B; i++)
#define PRINT(X) cout << X << endl
#define PRINTALL(E, X) { FOR(X) {cout << E[i] << endl; } }
#define PRINTSIDE(E, X) { FOR(X) {cout << E[i] << " ";} }
#define READALLI(V, N) FOR(N) {int x; cin >> x; V.push_back(x); }
#define READALL(V, N) FOR(N) {LL x; cin >> x; V.push_back(x); }
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXN 100000
#define SQRSIZE  317
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll>VL;
typedef vector<pii> vpii;
typedef map<int, int> mii;
typedef map<char, int>mci;
typedef map<string, int> msi;
typedef set<int> si;
const int INF = (1 << 30);
ull gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){ return a * (b / gcd(a, b)); }

int main() {
	ll h, w;
	int n = 0;
	cin >> n;
	cin >> h >> w;
	int counter = 0;
	FOR(n){
		ll a = 0, b = 0;
		cin >> a >> b;
		if(a >= h && b >= w){
			counter++;
		}
	}
	cout << counter << "\n";
	return 0;
}




Measured memory_bytes: 256
import java.util.*;
import java.math.BigInteger;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
 
        BigInteger product = new BigInteger("1");
        long limit = (long) Math.pow(10, 18);
        //  System.out.println(limit);
        boolean smaller = true;
 
        for (int i = 1; i <= N; i++) {
            long A_i = scan.nextLong();
            if (A_i == 0) {
                System.out.println(0);
                return;
            }
 
            if (smaller) {
                product = product.multiply(BigInteger.valueOf(A_i));
            }
 
            if (smaller && product.compareTo(BigInteger.valueOf(limit)) == 1) {
                smaller = false;
            }
 
           // System.out.println("product is" + product + " smaller is" + smaller);
        }
 
        if (smaller) {
            System.out.println(product);
        } else {
            System.out.println(-1);
        }
    }
 
}

Measured memory_bytes: 60748
#include <stdio.h>
#include <queue>
#include <stack>
using namespace std;
int main(){
    int n,temp,last;
    bool up=true;
    long long int ans=0;
    queue<priority_queue<int,vector<int>,greater<int>>*>q;
    stack<int> s;
    priority_queue<int,vector<int>,greater<int>>* pq;
    scanf("%d",&n);
    while(n--){
        scanf("%d",&temp);
        if(!s.empty()){
            if(up){
                if(temp<s.top())up=false;
            }
            else{
                if(temp>s.top()){
                    last=temp;
                    temp=s.top();
                    s.pop();
                    pq=new priority_queue<int,vector<int>,greater<int>>;
                    pq->push(s.top());
                    s.pop();
                    while(!s.empty()){
                        if(s.top()>temp){
                            pq->push(s.top());
                            s.pop();
                        }
                        else break;
                    }
                    ans+=pq->size();
                    q.push(pq);
                    up=true;
                    s.push(temp);
                    temp=last;
                }
            }
        }
        s.push(temp);
    }
    if(!up){
        temp=s.top();
        s.pop();
        pq=new priority_queue<int,vector<int>,greater<int>>;
        pq->push(s.top());
        s.pop();
        while(!s.empty()){
            if(s.top()>temp){
                pq->push(s.top());
                s.pop();
            }
            else break;
        }
        ans+=pq->size();
        q.push(pq);
        s.push(temp);
    }
    while(!q.empty()){
        pq=q.front();
        q.pop();
        if(pq->empty())continue;
        temp=pq->top();
        pq->pop();
        while(!s.empty()){
            if(s.top()>temp){
                pq->push(s.top());
                s.pop();
            }
            else break;
        }
        s.push(temp);
        ans+=pq->size();
        q.push(pq);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 13748
// #pragma GCC optimize(3)
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstring>
#include <iostream>
#include <algorithm>
#define maxn 100010
#define MOD 1000000007
#define int long long
using namespace std;
void write(int x){if(x<0){putchar('-');x=-x;}if(x>9) write(x/10);putchar(x%10+'0');}
int read(){int d=0,w=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')
w=-1;for(;c>='0'&&c<='9';c=getchar())d=(d<<1)+(d<<3)+c-48;return d*w;}
void wln(int x){write(x);putchar('\n');}
void wrs(int x){write(x);putchar(' ');}
// int n,x,y,a[maxn],f[maxn][maxn][2],ans;
int tree[maxn<<2][2],lazy[maxn<<2][2],n,x,y,a[maxn];
void up(int x,int y)
{
	(tree[x][y]=tree[x<<1][y]+tree[x<<1|1][y])%=MOD;
}
void hok(int x,int l,int r,int addv,int y)
{
	lazy[x][y]=addv;
	tree[x][y]=(r-l+1)*addv%MOD;
}
void down(int x,int l,int r,int y)
{
	if(lazy[x][y]==-1) return;
	int m=l+r>>1;
	hok(x<<1,l,m,lazy[x][y],y);
	hok(x<<1|1,m+1,r,lazy[x][y],y);
	lazy[x][y]=-1;
}
void update(int cnt,int l,int r,int ql,int qr,int addv,int y)
{
	if(ql<=l&&r<=qr)
	{
		hok(cnt,l,r,addv,y);
		return;
	}
	down(cnt,l,r,y);
	int m=l+r>>1;
	if(ql<=m) update(cnt<<1,l,m,ql,qr,addv,y);
	if(qr>m) update(cnt<<1|1,m+1,r,ql,qr,addv,y);
	up(cnt,y);
}
int query(int cnt,int l,int r,int ql,int qr,int y)
{
	if(ql<=l&&r<=qr) return tree[cnt][y];
	down(cnt,l,r,y);
	int m=l+r>>1,ans=0;
	if(ql<=m) ans=query(cnt<<1,l,m,ql,qr,y);
	if(qr>m) (ans+=query(cnt<<1|1,m+1,r,ql,qr,y))%=MOD;
	return ans;
}
signed main()
{
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	n=read();
	x=read();
	y=read();
	for(int i=1;i<=n;a[i++]=read());
	memset(lazy,255,sizeof lazy);
	update(1,0,n,0,0,1,0);
	update(1,0,n,0,0,1,1);
	// f[0][0][0]=f[0][0][1]=1;
	for(int i=1;i<=n;i++)
	{
		// if(a[i]-a[i-1]>=x||i==1) f[i][0][0]=f[i-1][0][0];
		// if(a[i]-a[i-1]>=y||i==1) f[i][0][1]=f[i-1][0][1];
		// for(int j=1;j<i-1;j++)
		// {
			// if(a[i]-a[i-1]>=x) f[i][j][0]=f[i-1][j][0];
			// if(a[i]-a[i-1]>=y) f[i][j][1]=f[i-1][j][1];
		// }
		// if(i!=1)
		// 	for(int j=0;j<i-1;j++)
		// 	{
		// 		if(a[i]-a[j]>=x||j==0) (f[i][i-1][0]+=f[i-1][j][1])%=MOD;
		// 		if(a[i]-a[j]>=y||j==0) (f[i][i-1][1]+=f[i-1][j][0])%=MOD;
		// 	}
		if(i!=1)
		{
			int tmp1=upper_bound(a+1,a+i-1,a[i]-x)-a;
			int tmp2=upper_bound(a+1,a+i-1,a[i]-y)-a;
			tmp1--;
			tmp2--;
			// wrs(i);
			// wrs(tmp1);
			// wln(tmp2);
			update(1,0,n,i-1,i-1,query(1,0,n,0,tmp1,1),0);
			update(1,0,n,i-1,i-1,query(1,0,n,0,tmp2,0),1);
		}
		if(i!=1&&a[i]-a[i-1]<x) update(1,0,n,0,i-2,0,0);
		if(i!=1&&a[i]-a[i-1]<y) update(1,0,n,0,i-2,0,1);
		// for(int j=0;j<i;j++)
		// 	for(int k=0;k<2;k++)
		// 		printf("f[%lld][%lld][%lld]=%lld\n",i,j,k,query(1,0,n,j,j,k));
	}
	// for(int i=1;i<=n;i++)
	// 	for(int j=0;j<i;j++)
	// 		for(int k=0;k<2;k++)
	// 			printf("f[%d][%d][%d]=%d\n",i,j,k,f[i][j][k]);
	// for(int i=0;i<n;i++)
	// 	(ans+=f[n][i][0]+f[n][i][1])%=MOD;
	// ans=query(1,0,n,0,n-1,0)+query(1,0,n,0,n-1,1);
	// write(ans);
	write((query(1,0,n,0,n-1,0)+query(1,0,n,0,n-1,1))%MOD);
	return 0;
}


Measured memory_bytes: 12672
#include<bits/stdc++.h>
using namespace std;
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long int 
#define fi first
#define se second
#define FIO {ios::sycnt2_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
#define int long long int
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
#define mod 1000000007
int32_t main()
{
  int n;
  cin>>n;
  int a[n];
  forn(i,n)
  {
    cin>>a[i];
  }
  int sum=0;
  int ans=0;
  forn(i,n)
  {
    ans+=((sum%mod)*a[i])%mod;
    sum+=a[i]%mod;
  } 
  cout<<ans%mod;
}

Measured memory_bytes: 5160
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;


//??????
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int p = 1; p < N; p++) cout << ", " << v[p]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()

// time, num
typedef pair<int, int> pii;

int main()
{
	vector<pii> g[3], gg;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 8; j++) {
			int no, sec, msec;
			scanf("%d %d.%2d", &no, &sec, &msec);

			g[i].push_back(pii(sec * 100 + msec, no));
		}
		sort(all(g[i]));
	}

	for (int i = 0; i < 3; i++) {
		for (int j = 2; j < 8; j++) {
			gg.push_back(g[i][j]);
		}
	}
	sort(all(gg));

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 2; j++) {
			pii& p = g[i][j];
			printf("%d %d.%02d\n", p.second, p.first / 100, p.first % 100);
		}
	}

	for (int i = 0; i < 2; i++) {
		pii& p = gg[i];
		printf("%d %d.%02d\n", p.second, p.first / 100, p.first % 100);
	}

	return 0;
}

Measured memory_bytes: 3116
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

int main()
{
	string S;
	cin >> S;
	int sum = 0;
	REP(i, SIZE(S))
	{
		sum += atoi(S.substr(i, 1).c_str());
	}
	cout << (atoi(S.c_str()) % sum == 0 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> // Integer Product, by Errichto
using namespace std;
int main() {
    int n;
    scanf("%d", &n);
    map<pair<int,int>, int> cnt;
    for(int rep = 0; rep < n; ++rep) {
        double x;
        scanf("%lf", &x);
        long long i = llround(x * 1e9);
        int two = 0, five = 0;
        while(i % 2 == 0) {
            two++;
            i /= 2;
        }
        while(i % 5 == 0) {
            five++;
            i /= 5;
        }
        ++cnt[{two,five}];
    }
    long long answer = 0;
    for(auto p1 : cnt) {
        for(auto p2 : cnt) {
            if(p1.first.first+p2.first.first >= 18 && p1.first.second+p2.first.second >= 18) {
                if(p1 < p2) {
                    answer += (long long) p1.second * p2.second;
                }
                else if(p1 == p2) {
                    answer += (long long) p1.second * (p1.second - 1) / 2;
                }
            }
        }
    }
    printf("%lld\n", answer);
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
int main(){
   ll A,B;
   cin >> A >> B;
   ll num = 2;
   ll ans = 0;

   ans += ((B+1)/2 - A/2) % 2;

   REP(i,43){
       ll a,b;
       if (false){
           if (A % (num * 2) >= num) {
               a = (A % (num * 2)) - num + 1  - 1;
           } else {
               a = 0;
           }

           if (B % (num * 2) >= num) {
               b = (B % (num * 2)) - num + 1;
           } else {
               b = 0;
           }



       }else {
           if (A % (num * 2) >= num) {
               a = (num * 2) - (A % (num * 2));
           } else {
               a = num;
           }

           if (B % (num * 2) >= num) {
               b = (B % (num * 2)) - num + 1;
           } else {
               b = 0;
           }

       }
       ans += num * ((a+b) % 2);
       num = num * 2;
   }

   cout << ans << endl;

}






Measured memory_bytes: 256
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

/**
   return 1 if found
          0 else anything
 */
int
binary_search(int target, int xs[], int size) {
  int left=0, right = size;
  do {
    // printf("BGN left:%d right:%d\n", left, right);
    int mid = (left + right) / 2;    
    if (target < xs[mid]) {
      right = mid;
    } else {
      left = mid;
    }
    // printf("END left:%d right:%d\n", left, right);    
  } while (left < right - 1);
  // printf("LST left:%d right:%d\n", left, right);      
  if (xs[left] == target) return 1;
  
  return 0;
}

int
main() {
  //  int xs[] = { 1,2,2,2,3,4,5 };
  /*
  int xs[] = { 10, 14, 19, 26, 27, 31, 33,35, 42,44 };
  int size = sizeof(xs) / sizeof(xs[0]);
  assert(1 == binary_search(10, xs, size) );
  assert(1 == binary_search(44, xs, size) );
  assert(1 == binary_search(26, xs, size) );
  assert(0 == binary_search(1, xs, size) );
  */
  int *s, *t;
  s = malloc(sizeof(int)*100000);
  t = malloc(sizeof(int)*50000);
  int n, q;
  scanf("%d", &n);
  int i;
  for (i=0;i<n;++i) {
    int v;
    scanf("%d", &v);
    s[i] = v;
    // printf("%d:%d\n", i, s[i]);
  }
  scanf("%d", &q);
  for (i=0;i<q;++i) {
    int v;
    scanf("%d", &v);
    t[i] = v;
  }
  int sum = 0;
  for (i=0;i<q;++i) {
    int tv = t[i];
    sum += binary_search(tv, s, n);
  }
  printf("%d\n", sum);
  free(s);
  free(t);
  s = NULL; t = NULL;
  return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int main(){
    double a, b, x;
    cin >> a >> b >> x;
    double s = x / a;
    double rad;
    if(s >= a * b / 2){
        double h = (a * b - s) * 2 / a;
        rad = atan2(h, a);        
    }
    else{
        double w = s * 2 / b;
        rad = atan2(b, w);
    }
    double ans = rad / (2 * M_PI)* 360;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 2* 1e5+5;
typedef long long ll;
ll n,k;
ll a[N];
int main(){
        cin>>n>>k;
        for(int i=1;i<=n;i++) cin>>a[i];
        int p[n+1],d[n+1],curr=1,turns=0; int vis[n+1]; memset(vis,0,sizeof(vis)); vis[curr]=1;
        p[1]=0; int st,cs; d[0]=1;
        while(true){
                curr=a[curr];
                turns++;
                if(vis[curr]) { cs=turns-p[curr]; st=p[curr]; break; }
                d[turns]=curr;
                vis[curr]=1;
                p[curr]=turns;
        }
        if(k<=st){ cout<<d[k]<<endl; return 0;}
        k-=st;
        k%=cs;
        cout<<d[st+k]<<endl;
}



Measured memory_bytes: 7396
mod = 1000000000 + 7

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

n = int(input())
dat = [0] * 2000 # 約数として求められたある数の合計

# N! の各要素の素因数分解をする
res = 1
for i in range(1, n + 1):
    d = factorization(i)
    for j in range(len(d)):
        dat[d[j][0]] += d[j][1]

for i in range(2, n + 1):
    res *= (dat[i] + 1)
    res %= mod

print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

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



int main() {
	ll H, W;
	cin >> H >> W;

	vector<vector<char>> a(H + 1, vector<char>(W + 1));
	repn(i, H)repn(j, W) cin >> a[i][j];

	repn(i, H) {
		repn(j, W) {
			if (i % 2 == 1&&j<W) { cout << '#'; }
			else if (j == 1) { cout << '#'; }
			else if (a[i][j] == '#') { cout << '#'; }
			else { cout << '.'; }
		}
		cout << endl;
	}

	cout << endl;

	repn(i, H) {
		repn(j, W) {
			if (i % 2 == 0&&j>1) { cout << '#'; }
			else if (j == W) { cout << '#'; }
			else if (a[i][j] == '#') { cout << '#'; }
			else { cout << '.'; }
		}
		cout << endl;
	}
	
	

	system("PAUSE");
}


Measured memory_bytes: 1272
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

int main() {
  double l;cin >> l;
  double x= l/3;
  cout << fixed << setprecision(10)<<double(x*x*x);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n;
	string s;
	cin >> n >> s;
	
	int ans = 0;
	for(int i = 0; i + 2 < n; i++){
		if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
			ans++;
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256