akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<set>
#include<fstream>
#include<map>
#include<string>
#include <stdio.h>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<climits>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef vector<char>vc;
typedef vector<string>vs;
#define MP make_pair
#define all(v) v.begin(),v.end()
#define EPS 1e-9
const ll mod = 1000000007;
const ll OO = (ll)1e18;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
ll gcd(ll a, ll b){ if (b == 0){ return a; }return gcd(b, a % b); }
ll fast_power(double base, ll power){
	if (power == 1) return base;
	if (power % 2 == 0) return fast_power((base*base), power / 2);
	else return(base*fast_power((base*base), power / 2));
}
//#pragma warning (disable : 4996)
void Qalbaz()
{
#ifndef ONLINE_JUDGE
	
#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(2);
}

int main(){

	Qalbaz();

	char arr[] = { 'M', 'A', 'R', 'C', 'H' };
	sort(arr, arr + 5);
	string str;
	map<string, bool>mp;
	do
	{
		str.push_back(arr[0]);
		str.push_back(arr[1]);
		str.push_back(arr[2]);
		sort(all(str));
		mp[str] = true;
		str.clear();
	} while (next_permutation(arr, arr + 5));
	map<string, bool>::iterator it;
	ll x;
	int n;
	cin >> n;
	vs vec(n);
	map<char, ll>mpp;
	for (int i = 0; i < n; i++)
	{
		cin >> vec[i];
		mpp[vec[i][0]]++;
	}
	ll sum = 0LL;
	for (it = mp.begin(); it != mp.end(); it++)
	{
		str = it->first;
		x = mpp[str[0]] * mpp[str[1]] * mpp[str[2]];
		sum += x;
	}
	cout << sum;
	
	return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int s,a[4],x,y;
int main()
{
	for(int i=1;i<4;i++)
	{
		cin>>a[i];
		if(a[i]%2==0)y++;
		else x++;
	}
	sort(a+1,a+4);
	if(x==2)
	{
		for(int i=1;i<=3;i++)
		{
			if(a[i]%2!=0)a[i]++;
		}s=1;
	}
	if(y==2)
	{
		for(int i=1;i<=3;i++)
		{
			if(a[i]%2==0)a[i]++;
		}s=1;
	}
	for(int i=1;i<=3;i++)
	{
		s+=(a[3]-a[i])/2;
	}cout<<s;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pir;
const int N=100010;
int a[N],b[N],v[N];
map <int,int> s1,s2;
set <pir> w1[N],w2[N];
vector <int> q1[N],q2[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline void init(int t) {
    w1[s1[a[t]]].erase(pir(b[t],t));
    w2[s2[b[t]]].erase(pir(a[t],t));
}
inline void calc(set <pir> &w,ll l,ll r,int &sum) {
    set <pir> :: iterator t=w.lower_bound(pir(l,0));
    int la=sum;
    while(t!=w.end()&&t->first<=r)
	v[++sum]=t->second,++t;
    while(++la<=sum) init(v[la]);
}
inline int query(vector <int> &q,ll x) {
    int l=0,r=q.size()-1;
    while(l<=r) {
	int mid=(l+r)>>1;
	if(q[mid]<=x) l=mid+1;
	else r=mid-1;
    }
    return r;
}
int main() {
    int n,A,B,t1=0,t2=0;
    cin>>n>>A>>B;
    for(int i=1;i<=n;i++) {
	int x=gi(),y=gi(),X=x+y,Y=x-y;
	a[i]=X,b[i]=Y;
	if(!s1[X]) s1[X]=++t1;
	if(!s2[Y]) s2[Y]=++t2;
	w1[s1[X]].insert(pir(Y,i)),w2[s2[Y]].insert(pir(X,i));
	q1[s1[X]].push_back(Y),q2[s2[Y]].push_back(X);
    }
    for(int i=1;i<=t1;i++) sort(q1[i].begin(),q1[i].end());
    for(int i=1;i<=t2;i++) sort(q2[i].begin(),q2[i].end());
    ll d=max(abs(a[A]-a[B]),abs(b[A]-b[B])),ans=0;
    int t=0,sum=1;
    v[1]=A,init(A);
    while(t<sum) {
	int x=v[++t];
	ll f[4]={s1[a[x]-d],s1[a[x]+d],s2[b[x]-d],s2[b[x]+d]};
	for(int i=0;i<4;i++)
	    if(i<2) ans+=query(q1[f[i]],b[x]+d-i)-query(q1[f[i]],b[x]-d-i);
	    else ans+=query(q2[f[i]],a[x]+d+i-3)-query(q2[f[i]],a[x]-d+i-3);
	calc(w1[f[0]],b[x]-d,b[x]+d,sum);
	calc(w1[f[1]],b[x]-d,b[x]+d,sum);
	calc(w2[f[2]],a[x]-d,a[x]+d,sum);
	calc(w2[f[3]],a[x]-d,a[x]+d,sum);
    }
    cout<<ans/2;
    return 0;
}

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

int n,m;
std::vector<char> v;
string dp[10100];

void exclude(std::vector<char> a){
  bool used=0;
  for(int i=0;i<a.size();i++){
    auto it = find(v.begin(), v.end(), a[i]);
    if(it != v.end()){
      if(!used){
        used=1;
      }else{
        v.erase(it);
      }
    }
  }
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  cin>>n>>m;
  for(int i=0;i<m;i++){
    char t;cin>>t;
    v.push_back(t);
  }
  sort(v.begin(), v.end());
  exclude({'1','4'});
  exclude({'5','3','2'});
  exclude({'7','9','6'});
  m = v.size();

  int mp[] = {0,2,5,5,4,5,6,3,7,6};

  // for(int i=0;i<m;i++){
  //   cout<<v[i]<<endl;
  // }

  for(int i=0;i<=n;i++){
    // debug(i);
    if(i&&dp[i]=="")continue;
    for(int j=0;j<m;j++){
      // debug(j);
      char num = v[j];
      int nx = i + mp[num-'0'];
      // cout<<num<<':'<<mp[num-'0']<<endl;
      string new_s = dp[i] + num;
      sort(new_s.rbegin(), new_s.rend());
      // cout<<"A:"<<i<<':'<<j<<':'<<dp[i]<<':'<<nx<<':'<<new_s<<endl;
      if(new_s.size()>dp[nx].size() || (new_s.size()==dp[nx].size() && new_s>dp[nx])){
        dp[nx] = new_s;
      }
      // cout<<"B:"<<i<<':'<<j<<':'<<dp[i]<<':'<<nx<<':'<<new_s<<endl;
    }
  }

  cout<<dp[n]<<endl;

  return 0;
}


Measured memory_bytes: 29312
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=2e5+5;
const int mod=2019;
char s[maxm];
int a[maxm];
int n;
signed main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;i++){
        a[i]=s[i]-'0';
    }
    map<int,int>mark;
    mark[0]=1;
    int sum=0;
    int base=1;
    int ans=0;
    for(int i=n;i>=1;i--){
        sum=(sum+a[i]*base%mod)%mod;
        ans+=mark[sum];
        mark[sum]++;
        base=base*10%mod;
    }
    cout<<ans<<endl;
    return 0;
}
/*
对于s[l,r],如果是2019的倍数,那么满足:
s[l]*10^(n-l)%2019+
*/


Measured memory_bytes: 5560
// in the name of Allah ;
#include<bits/stdc++.h>
using namespace std ;
int main () 
{
	int t[3] , sum = 0 ;
	cin >> t[0] >> t[1] >> t[2] ;
	sort ( t , t+3  ) ;
	for ( int i = 0 ; i < 3 ; i++ ) 
		sum += t[i] ; 
	cout << t[2]*9+sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

int n; string s;

ll num[26];
int main() {
	cin >> n >> s;
	rep(i, n) {
		num[s[i] - 'a']++;
	}
	ll ans = 1;
	rep(i, 26) {
		ans = ans * (num[i]+1) % mod;
	}
	ans = (ans - 1 + mod) % mod;
	cout << ans << endl;
	//stop
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main() {
	int N, M, X[100000];
	int d[100000],ans;
	cin >> N >> M;
	
		for (int i = 0; i < M; i++) {
			cin >> X[i];
		}
		if (N < M) {
			sort(X, X + M);

			for (int i = 0; i < M - 1; i++) {
				d[i] = X[i + 1] - X[i];
			}
			sort(d, d + (M - 1), greater<int>());
			ans = X[M - 1] - X[0];
			for (int i = 0; i < N - 1; i++) {
				ans -= d[i];
			}
		}
		else {
			ans = 0;
		}
		cout << ans << endl;
	
	
	return 0;
}

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

const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  int h[n];
  for(int i=0;i<n;i++) cin>>h[i];

  int cnt=0;
  while(true) {
    bool flag=false;
    for(int i=0;i<n;i++){
      if (h[i]>0) {
        h[i]=h[i]-1;
        flag=true;
      }else if(flag){
        ++cnt;
        flag=false;
      }
    }
    if(flag) ++cnt;
    int sum=0;
    for(int i=0;i<n;i++) sum+= h[i];
    if(sum==0) {
      break;
    }
  }
  cout<<cnt<<endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
 
int main()
{
	int n, i, j, p, sum, t;
	int a[2][105], b[105];
	while(cin >> n)
	{
		t = 1;
		for(i = 0; i < 2; i++)
			for(j = 0; j < n; j++)
				scanf("%d",&a[i][j]);
		for(i = 0,p = 0,sum = 0;; i++)
		{
			p += a[0][i];
			sum = p;
			for(j = i; j < n; j++)
			{
				sum += a[1][j];
				b[i] = sum;
			}
			sum = 0;
			if(i == n - 1) break;
		}
		sort(b,b + n);
		printf("%d\n",b[n - 1]);
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;

typedef long long int ll;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}

ll le[ARRAY_MAX];
ll ri[ARRAY_MAX];

int main() {

	ll n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	le[0] = a[0];
	ri[n - 1] = a[n - 1];

	for (int i = 1; i < n; i++)
	{
		le[i] = gcd(le[i - 1], a[i]);
	}


	for (int i = n - 2; i >= 0; i--)
	{
		ri[i] = gcd(ri[i + 1], a[i]);
	}

	ll maxi = 0;
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
		{
			maxi = max(maxi, ri[i + 1]);
		}
		else if (i == n - 1)
		{
			maxi = max(maxi, le[i - 1]);
		}
		else
		{
			maxi = max(maxi, gcd(ri[i + 1], le[i - 1]));
		}
	}
	cout << maxi << endl;
}





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

int main() {
    string str;
    cin >> str;
    int str_size;
    string di,fi;
    int d,f,m,n=1000;
    str_size=str.size();
    for(int i=0;i<str_size;i++){
        di=str.substr(i,3);
        d=atoi(di.c_str());
        fi=str.substr(i+1,3);
        f=atoi(di.c_str());
        d=abs(753-d);
        f=abs(753-f);
        m=min(d,f);
        n=min(n,m);
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

int main() {
  long long N, M;
  cin >> N >> M;

  long long dog = 1;
  for (int i = 1; i <= N; i++) {
    dog *= i;
    dog %= MOD;
  }

  long long monkey = 1;
  for (int i = 1; i <= M; i++) {
    monkey *= i;
    monkey %= MOD;
  }

  if (abs(N - M) >= 2)
    cout << 0 << endl;
  else if (abs(N - M) == 1)
    cout << (dog * monkey) % MOD << endl;
  else
    cout << (dog * monkey * 2) % MOD << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define rep(i,n) for((i)=1;(i)<=(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define ep emplace_back
#define mp make_pair

typedef long long ll;
typedef pair<int,int> pii;

inline int in() 
{
    int x=0, c;
    while((unsigned int)((c=getchar())-48)>=10) 
		if(c=='-') 
			return -in();
    do 
	{ x=(x<<3)+(x<<1)+(c^48); }
	while((unsigned int)((c=getchar())^48)<10);
    return x;
}

//Simplicity is the ultimate sophistication
//Ò™¤¨¤Æ¤ª¤¤¤Æ¡¢¤³¤ì¤Ï¤Î¾ý¤Îkey¤Ç¤¹¡£
//Kanon Air Clannad LittleBusters  Angelbeats Charlotte Rewrite Horimonia SummerPocket

pair<pii,int> city[100100];
int n;
string ans[100100];

string get_ans(int p,int x){
	string res="";
	string a1="",a2="";
	
	while(p){
		a1=(char)('0'+p%10)+a1;
		p/=10;
	}
	while(x){
		a2=(char)('0'+x%10)+a2;
		x/=10;
	}
	
	int len1=a1.size(),len2=a2.size();
	
	for(int i=0;i<6-len1;i++) a1="0"+a1;
	for(int i=0;i<6-len2;i++) a2="0"+a2;
	
	return a1+a2;
}

int main(){
	int i,j,k=0;
	
	n=in();n=in();
	
	REP(i,n)	scanf("%d%d",&city[i].first.first,&city[i].first.second),city[i].second=i;
	
	sort(city,city+n);
	int prv=0;
	
	REP(i,n){
		if(i==0||city[i].first.first!=city[i-1].first.first) prv=1;
		else prv++;
		ans[city[i].second]=get_ans(city[i].first.first,prv);
	}
	
	REP(i,n) printf("%s\n",ans[i].c_str());
	return 0;
} 

Measured memory_bytes: 8192
//                                               KEEP GRINDING
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>   new_data_set;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define int long long
#define ld long double
#define MOD 1000000007
#define mod 998244353
#define precise(i) fixed << setprecision(10) << i
#define f(i,a,b) for(int i=a;i<b;++i)

#define endl '\n'
#define debug cout<<"\n========================================\n";
#define err1(a) cout<<#a<<" "<<a<<endl;
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl;
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl;
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl;

#define all(a) a.begin(),a.end()
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define PQ priority_queue
#define mx(a) *max_element(a)
#define mn(a) *min_element(a) 
#define LB lower_bound  //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS >= OUR VALUE 
#define UB upper_bound  //THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS > OUR VALUE 

#define fr first
#define sc second

#define MAXN 500000
#define INF 9223372036854775807
signed main(){
    fastio;
    int n;
    cin>>n;
    vector<int> a(n),ans(n,0);
    f(i,0,n){
    	cin>>a[i];
	}
	int MAX=mx(all(a));
	int res=1;
	while(res<=2*MAX){
		int cnt=0;
		vector<int> temp(n);
		f(i,0,n){
			temp[i]=a[i]%2;
			a[i]/=2;
			if( temp[i] )
				cnt++;
		}
		if( cnt&1 ){
			f(i,0,n)
				temp[i]=1-temp[i];
		}
		f(i,0,n)
			ans[i]+=res*temp[i];
		
		res*=2;
	}
	show(ans);
}

Measured memory_bytes: 7924
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
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;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int N,K,R,S,P;string T;cin>>N>>K>>R>>S>>P>>T;
    char myhand[N];
    int ans=0;
    REP(i,N){
        if(i<K){
            if(T[i]=='r'){
                ans+=P;
                myhand[i]='p';
            }
            if(T[i]=='s'){
                ans+=R;
                myhand[i]='r';
            }
            if(T[i]=='p'){
                ans+=S;
                myhand[i]='s';
            }
        }
        else{
            if(T[i]=='r'){
                if(myhand[i-K]=='p'){
                  	myhand[i]='z';
                  	continue;
                }
                ans+=P;
                myhand[i]='p';
            }
            if(T[i]=='s'){
                if(myhand[i-K]=='r'){
                    myhand[i]='z';
                    continue;
                }
                ans+=R;
                myhand[i]='r';
            }
            if(T[i]=='p'){
                if(myhand[i-K]=='s'){
                    myhand[i]='z';
                    continue;
                }
                ans+=S;
                myhand[i]='s';
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
#Aはかかる時間、Bは締め切り時間
AB = sorted(AB,key=lambda x: x[1])

C = [0]*len(AB)
C[0] = AB[0][0]
for i in range(1,len(AB)):
    C[i] += AB[i][0] + C[i-1]

ans = 1
for i in range(len(AB)):
    if AB[i][1] < C[i]:
        ans = 0

print('YNeos'[ans==0::2])

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

int main()
{
    ll n;
    string str;
    cin>>str;
    n = str.length();

    ll dp[n+1][3];
    dp[0][1] = 0;
    dp[0][2] = 0;
    dp[1][2] = 0;

    dp[1][1] = 1;

    for(ll i=1;i<n;i++)
    {
        dp[i+1][1] = dp[i][2]+1;
        if(str[i] != str[i-1])
            dp[i+1][1] = max(dp[i+1][1],dp[i][1]+1);

        dp[i+1][2] = dp[i-1][1]+1;
        if(i>2)
        {
            if(str[i-2] != str[i] || str[i-1] != str[i+1])
                dp[i+1][2] = max(dp[i+1][2],dp[i-1][2]+1);
        }
    }
    cout<<max(dp[n][1],dp[n][2]);


    return 0;
}


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

const int N=1000005;
priority_queue<ll>Q[4];
ll f[4][105],A[4];

int main(){

	ll n,m,mm,a,b;
	cin>>n>>m;

	for(int i=1;i<=n;++i){
		cin>>a>>b;
		if(i==1)mm=a; a-=mm;
		Q[a].push(b);
	}

	for(int i=0;i<4;++i){
		for(int j=1;!Q[i].empty();){
			ll x=Q[i].top(); Q[i].pop();
			f[i][j]=f[i][j-1]+x; A[i]=j++;
		}
	}

	ll ans=0;

	for(ll i=0;i<=A[0];++i){
		if(i*mm>m)break;
		for(ll j=0;j<=A[1];++j){
			if((i+j)*mm+j>m)break;
			for(ll k=0;k<=A[2];++k){
				if((i+j+k)*mm+j+k*2>m)break;
				ll l=(m-(i+j+k)*mm-j-k*2)/(mm+3);
				if(l>A[3])l=A[3];
				ll x=f[0][i]+f[1][j]+f[2][k]+f[3][l];
				if(x>ans)ans=x;
			}
		}
	}

	cout<<ans;

	return 0;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    rep(i,3){
        scanf("%1lld",&n);
        printf("%lld",n==1?9:n==9?1:n);
    }
    printf("\n");
}

Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

struct Node{
public:
 Node* parent;
 Node* left;
 Node* right;
 int value;

 Node(Node* p = 0, Node* l = 0, Node* r = 0, int v = 0) : parent(p), left(l), right(r), value(v){};
private:
protected:
};

class Tree{
private:
 Node* root;
 enum ORDER {PREORDER = 0, INORDER, POSTORDER};
public:
 Tree(){root = 0;};

 void insert(int intz){
  Node* z = new Node(0, 0, 0, intz);
  insert(z);
 };

 void insert(Node* z){
  Node* y = 0;
  Node* x = root;
  while(x != 0){
   y = x;
   if(z->value < x->value){
    x = x->left;
   }else{
    x = x->right;
   }
  }
  z->parent = y;
  if(y == 0){
   root = z;
  }else if(z->value < y->value){
   y->left = z;
  }else{
   y->right = z;
  }
  return ;
 };

 void find(int value){
  Node* x = root;
  
  Node* z = new Node(0, 0, 0, value);

  while(x != 0){
   if(z->value < x->value){
    x = x->left;
   }else if(z->value > x->value){
    x = x->right;
   }else{
    cout << "yes" <<endl;
    return ;
   }
  }
  cout << "no" << endl;
  return ;
 };

 void print(){
  print(INORDER);
  print(PREORDER);
 };
 void print(ORDER order){
  Node* cur = root;
  Node* pre = cur->parent;

  if(root == 0) return;

  while(cur){
   if(pre == cur->parent){
    if(order == PREORDER) cout << " " << cur->value;
    if(cur->left != 0){
     pre = cur;
     cur = cur->left;
     continue;
    }else{
     pre = cur->left;
    }
   }

   if(pre == cur->left){
    if(order == INORDER) cout << " " << cur->value;
    if(cur->right != 0){
     pre = cur;
     cur = cur->right;
     continue;
    }else{
     pre = cur->right;
    }
   }

   if(pre == cur->right){
    if(order == POSTORDER) cout<< " " << cur->value;
    pre = cur;
    cur = cur->parent;
   }
  }
  cout << endl;
  return ;
 };


protected:
};


int main(){
 Tree tree;
 int n = 0; cin >> n;
 for(int i = 0; i < n; i++){
  string str = ""; cin >> str;

  if(str == "insert"){
   int x = 0; cin >> x; 
   tree.insert(x);
  }else if(str == "find"){
   int value = 0; cin >> value;
   tree.find(value);
  }else if(str == "print"){
   tree.print();
  }
 }

 return 0;
}

Measured memory_bytes: 24656
#include <cstdio>
#include <map>
#include <iostream>
#include <cstring>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
using namespace std;
typedef long long ll;


// 最初は右向いてる
// 奇数番目と偶数番目がx軸y軸で云々か。それぞれでPARTITION
// 最初だけは向きが固定なので、進んだところから開始するのが良さそう。
// 

char buf[8010];

vector<int> xs;
vector<int> ys;


bool dp[16010];

bool isOK(vector<int> vs, int target) {
  memset(dp, 0, sizeof dp);
  dp[0] = true;
  // REP(i, 10) {
  //   printf("%d", dp[i]);
  // }
  // printf("\n");
  int sum = 0;
  REP(i, vs.size()) {
    int v = vs[i];
    sum += v;
    if(v) {
      for(int j = 8000-v; j >= 0; --j) {
        dp[j+v] = dp[j+v] || dp[j];
      }
    }
  }
  // REP(i, 10) {
  //   printf("%d", dp[i]);
  // }
  // printf("\n");
  int tt = sum-target;
  if(tt % 2 == 1 || tt < 0) {
    return false;
  }
  return dp[tt/2];
}

int main(void) {
  int x, y;
  scanf("%s%d%d", buf, &x, &y);
  int cur = 0;
  int dir = 0;
  int n = strlen(buf);
  REP(i, n) {
    if(buf[i] == 'F') {
      ++cur;
    } else {
      if(dir == 0) {
        x -= cur;
      } else if(dir % 2 == 0) {
        xs.push_back(cur);
      } else {
        ys.push_back(cur);
      }
      ++dir;
      cur = 0;
    }
  }
  // last
  if(dir == 0) {
    x -= cur;
  } else if(dir % 2 == 0) {
    xs.push_back(cur);
  } else {
    ys.push_back(cur);
  }
  // cerr << "(" << x << "," << y << ")" << endl;
  puts(isOK(xs, abs(x)) && isOK(ys, abs(y)) ? "Yes" : "No");
  
  return 0;
}


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

int main(void){
    int S,h,m,s;
    cin >> S; 
    h=S/60/60;
    m=(S-3600*h)/60;
    s=S%60;
    cout << h;
    cout << ":"; 
    cout << m;
    cout << ":"; 
    cout << s;
    cout << endl;
}



Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

struct choten{
    ll dist = 0;
    vector<pair<ll, ll>> leaf;
};
choten tree[100010];
bool visited[100010];

void search(ll pos){
    visited[pos] = true;
    rep(i, tree[pos].leaf.size()){
        ll a = tree[pos].leaf[i].first;
        ll c = tree[pos].leaf[i].second;
        if(visited[a])continue;
        tree[a].dist = tree[pos].dist + c;
        search(a);
    }
}

int main(){
    ll n;
    cin >> n;
    rep(i, n-1){
        ll a, b, c;
        cin >> a >> b >> c;
        tree[a].leaf.push_back(make_pair(b, c));
        tree[b].leaf.push_back(make_pair(a, c));
    }
    ll q, k;
    cin >> q >> k;
    vector<pair<ll, ll>> qs;
    rep(i, q){
        ll x, y;
        cin >> x >>  y;
        qs.push_back(make_pair(x, y));
    }
    search(k);
    rep(i, q)cout << tree[qs[i].first].dist + tree[qs[i].second].dist << endl;
}

Measured memory_bytes: 14576
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 100100;
int n;
ll a[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	ll l = 2, r = 2;
	for (int i = n - 1; i >= 0; i--) {
		if (l % a[i] != 0)
			l += a[i] - (l % a[i]);
		r -= r % a[i];
		if (l > r) {
			printf("-1\n");
			return 0;
		}
		r += a[i] - 1;
	}
	printf("%lld %lld\n", l, r);

	return 0;
}


Measured memory_bytes: 1024
N=gets.to_i
A=gets.split.map(&:to_i)

cnt=0
(N-1).times do 
  (N-1).times do |i|
    if A[N-1-i-1] > A[N-1-i]
      A[N-1-i], A[N-1-i-1] = A[N-1-i-1], A[N-1-i]
      cnt+=1
    end
  end
end

puts A.join(" ")
p cnt



Measured memory_bytes: 6876
def main():
    N = int(input())
    A = list(map(int, input().split()))
    c = 0
    while True:
        for i in range(N):
            if A[i] % 2 == 1:
                print(c)
                return
            else:
                A[i] = A[i] // 2
        c += 1

main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int cal[110];

int main()
{
    ll n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    ll res = LINF;

    for(ll i=1;i*i<=n;i++){
        if(n%i)continue;
        res = min(res,i+n/i-2);
    }

    cout<<res<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
  int N;
  bool colors[8] = {};
  int m = 0, M = 0;
  std::cin >> N;

  for (int i=0; i<N; i++) {
    int x;
    std::cin >> x;
    if (x>=3200) M++;
    else colors[x/400] = true;
  }
  for (int i=0; i<8; i++) if (colors[i]) m++;
  M += m;
  // 全員が3200以上のとき、最低でも色は1つのはず！
  if (!m) m = 1;
  std::cout << m << ' ' << M;
  return 0;
}


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

int n, m ;
vector<vector<int> > g, rg ;
vector<int> vis, dp ;
vector<int> topo ;

void dfs(int u){
	vis[u] = 1 ;
	for(auto i : g[u])
		if(!vis[i])
			dfs(i) ;
	topo.push_back(u) ;
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	cin >> n >> m ;

	g = rg = vector<vector<int> > (n + 1, vector<int>() ) ;
	
	int x, y ;
	while(m--){
		cin >> x >> y ;
		g[x].push_back(y) ;
		rg[y].push_back(x) ;
	}

	vis = dp = vector<int> (n + 1, 0) ;
	for(int i = 1 ; i <= n ; i++)
		if(!vis[i])
			dfs(i) ;
	
	for(auto i : topo){
		for(auto j : rg[i]){
			dp[j] = max(dp[j], dp[i] + 1) ;
		}
	}

	int ans = 0 ;
	for(auto i : dp)
		ans = max(ans, i) ;
	
	cout << ans << endl ;

	return 0;
}

Measured memory_bytes: 14720
// AOJ DPL_2_A Traveling Salesman Problem
// 2018.5.5 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define INF 0x03030303

#define MAX_V  16
int dp[1<<MAX_V][MAX_V];
int d[MAX_V][MAX_V];

int traveling_salesman(int V)
{
	int s, u, v, x;

	memset(dp, INF, sizeof(dp));
	dp[(1<<V)-1][0] = 0;
	for (s = (1<<V)-2; s >= 0; s--) {
		for (v = 0; v < V; v++) {
			for (u = 0; u < V; u++) {
				if ((s>>u) & 1) continue;
				x = dp[s | (1<<u)][u] + d[v][u];
				if (x < dp[s][v]) dp[s][v] = x;
			}
		}
	}
	return dp[0][0];
}

int main()
{
	int V, E, ans;

	memset(d, INF, sizeof(d));
	V = in(), E = in();
	while (E--) {
		int s = in(), t = in();
		d[s][t] = in();
	}
	ans = traveling_salesman(V);
	if (ans >= INF) puts("-1");
	else printf("%d\n", ans);
	return 0;
}


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


int main(){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    vector<int>a(n);
    vector<int>b(m);
    rep(i,n)cin>>a[i];
    rep(i,m) cin>>b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(max(a[n-1],x)<min(b[0],y))cout<<"No War"<<endl;
    else cout<<"War"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ff first
#define ss second
#define END "\n"
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii> vii;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////


int main()
{
    fast
    #ifdef ANUBHAB
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    long double L;
    cin >> L;
    long double ans = pow(L / 3, 3);
    cout << setprecision(15) << ans;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	auto ans = "YES";
	for (auto i = 0; i < N - 1; ++i)
	{
		if (A[i] == A[i + 1])
		{
			ans = "NO";
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int dp[100010];

int main(){
  int n,k;
  cin >> n >> k;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  dp[0]=0;
  int y=0;
  
  for(int i=0;i<=k;i++){
    int y=0;
    for(int j=0;j<n;j++){
      int x=a[j];
      if(i<a[0]){
        dp[i]=2;
      }else if(i-x>=0&&dp[i-x]==2){
        dp[i]=1;
        y=1;
      }
    }
    //cout << 1 <<endl;
    if(y==0) dp[i]=2;
  }
  string ans;
  if(dp[k]==1){
    ans="First";
  }else{
    ans="Second";
  }
  //cout << dp[k] << endl;
  cout << ans << endl;
}


Measured memory_bytes: 640
n = int(input())
h = list(map(int, input().split()))

dp = [0]*n
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    dp[i] = min( dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
print(dp[n-1])

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

ll mod = 1872000;
ll day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

ll todays(ll y, ll m, ll d) {
    ll ret = (y - 1) * 365 + (y - 1) / 4 - (y - 1) / 100 + (y - 1) / 400 + d;
    if ((y % 4 == 0 && y % 100 != 0) ||( y % 400 == 0)) {
        if (m > 2) ret++;
    }
    for (int i = 0; i < m - 1; i++) {
        ret += day[i];
    }
    return ret;
}

void stom(ll y, ll m, ll d) {
    ll a[5]{};
    a[4] = 1;
    a[3] = 20;
    a[2] = a[3] * 18;
    a[1] = a[2] * 20;
    a[0] = a[1] * 20;
    
    ll t = todays(y, m, d) - todays(2012, 12, 21);
    t %= mod;
    ll c[5]{};
    c[0] = t / a[0];
    c[1] = (t - c[0] * a[0]) / a[1];
    c[2] = (t - c[0] * a[0] - c[1] * a[1]) / a[2];
    c[3] = (t - c[0] * a[0] - c[1] * a[1] - c[2] * a[2]) / a[3];
    c[4] = t - c[0] * a[0] - c[1] * a[1] - c[2] * a[2] - c[3] * a[3];
    for (int i = 0; i < 5; i++) {
        if (i == 4) {
            cout << c[i] << "\n";
        } else {
            cout << c[i] << ".";
        }
    }
}

void mtos(ll b, ll ka, ll t, ll w, ll ki) {
    ll f = b * 20 * 20 * 18 * 20;
    f += ka * 20 * 18 * 20;
    f += t * 20 * 18;
    f += w * 20 + ki;
    f += todays(2012, 12, 21);
    
    ll l = -1;
    ll r = 100000000;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        if (todays(m, 1, 1) <= f) {
            l = m;
        } else {
            r = m;
        }
    }
    
    ll y = l;
    ll m = 1;

    f -= todays(y - 1, 12, 31);
    for (int i = 0; i < 12; i++) {
        int g = day[i];
        if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) {
            if (i == 1) g = 29;
        }
        if (f - g <= 0) {
            m = i + 1;
            break;
        } else {
            f -= g;
        }
    }
    cout << y << "." << m << "." << f << "\n";
}

int main() {
    string s;
    cin >> s;
    while (s != "#") {
        vector<ll> v;
        string t = "";
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == '.') {
                v.push_back(stoi(t));
                t = "";
            } else if (i == s.length() - 1) {
                t += s[i];
                v.push_back(stoi(t));
            } else {
                t += s[i];
            }
        }
        if (v.size() == 3) {
            stom(v[0], v[1], v[2]);
        } else {
            mtos(v[0], v[1], v[2], v[3], v[4]);
        }
        cin >> s;
    }
    return 0;
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<(#x)<<" is "<<(x)<<endl
 int main()
 {
     int n;
     cin>>n;
     int a[n],f[n];
     for(int i=0;i<n;i++)
        cin>>a[i];
     f[0]=0;
     f[1]=abs(a[0]-a[1]);
     for(int i=2;i<n;i++)
     {
         f[i]=min((f[i-1]+abs(a[i]-a[i-1])),(f[i-2]+abs(a[i]-a[i-2])));
     }
     cout<<f[n-1];
 }



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

int main() {
	int h1,m1,h2,m2,k;
	cin >> h1>>m1>>h2>>m2>>k;

	int t1=h1*60+m1;
	int t2=h2*60+m2;

	int ans=t2-k-t1;

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


Measured memory_bytes: 3636
max_W1=0; max_W2=0; max_W3=0; sum_W=0
max_K1=0; max_K2=0; max_K3=0; sum_K=0

for i in range(10):
    W=int(input())
    if max_W1<W:
        max_W3=max_W2
        max_W2=max_W1
        max_W1=W
    elif max_W2<W:
        max_W3=max_W2
        max_W2=W
    elif max_W3<W:
        max_W3=W
    
for j in range(10):
    K=int(input())
    if max_K1<K:
        max_K3=max_K2
        max_K2=max_K1
        max_K1=K
    elif max_K2<K:
        max_K3=max_K2
        max_K2=K
    elif max_K3<K:
        max_K3=K

sum_W=max_W1+max_W2+max_W3
sum_K=max_K1+max_K2+max_K3
print(sum_W, sum_K)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; 
using namespace std;
#define int long long
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define mii map<int,int>
// #define mp make_pair
#define pb push_back
#define rep(i,b) for(ll (i)=0;i<(b);i++)
#define all(c) (c).begin(), (c).end()
#define F first
#define S second
#define CLR(p) memset(p, 0, sizeof(p))
#define SET(p) memset(p, -1, sizeof(p))
#define DEBUG true
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
//typedef long long int ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
tree_order_statistics_node_update> new_data_set; 
const int MAX=1e6+5;
#define MOD 1000000007
/*std::cout << std::fixed;
std::cout << std::setprecision(6);*/
//(a%mod-b%mod+mod)%mod



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


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

vector<vector<ll>>v;
ll T=0;
ll cnt1=0,cnt0=0;
vector<ll>dep;
bool visited[MAX];
vector<ll>par;
vector<ll>tin,tout;
vector<ll>col;

int countDivisibles(int A, int B, int M) 
{ 
    
    if (A % M == 0) 
        return (B / M) - (A / M) + 1; 
  
    // A is not divisible by M 
    return (B / M) - (A / M); 
} 


signed main(){
    int t=1;
    // cin>>t;
    while(t--){
        int n;
        
        cin>>n;
        int a=n%10;
        if(a==3)
        cout<<"bon\n";
        else if(a==0||a==1||a==6||a==8)
        cout<<"pon\n";
        else
        {
            cout<<"hon\n";
        }
        

        // cout<<  <<endl;

    }
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include <stdlib.h>
#include <stdio.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 int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(10) << ans << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n,m;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


signed main(){
    cin >> n;
    PQ(x);
    int a,b;
    int time=0;
    bool ans = true;
    REP(i,n){
        cin >> a >> b;
        x.push(P(b,a));
    }
    REP(i,n){
        P y = x.top();
        x.pop();
        time += y.second;
        if(time>y.first){
            ans = false;
        }
    }
    (ans)? cout << "Yes" << endl : print("No");
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 6512
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<math.h>
using namespace std;
#define MAX 10000005
#define MOD 1000000007
#define EPS 0.00000000001
#define INF 2000000000000000000
int prime[MAX+1];
int ans[MAX+1];
void sieve()
{
    int i,j,k;
    for(i=2; i*i<=MAX; i++)
    {
        if(prime[i]) continue;
        for(j=i; j*i<=MAX; j++)
        {
            if(prime[i*j]==0) prime[i*j]=i;
        }
    }
    ans[1]=1;
    for(i=2;i<=MAX;i++)
    {
        if(prime[i]==0) ans[i]=2;
        else
        {
            j=1;
            k=i;
            while(k%prime[i]==0)
            {
                j++;
                k=k/prime[i];
            }
            ans[i]=ans[k]*j;
        }
    }
}
int main()
{
    sieve();
    int n,i;
    scanf("%d",&n);
    long long temp,a=0;
    for(i=1;i<=n;i++)
    {
        temp=i;
        temp=temp*ans[i];
        a=a+temp;
    }

    printf("%lld",a);
    return 0;
}


Measured memory_bytes: 81948
from collections import Counter

N = int(input())
sticks = list(map(int , input().split()))
ans = []

sticks_counter = Counter(sticks).most_common()
sticks_counter.sort(reverse = True)

for s in sticks_counter:
    if s[1] >=2:
        ans.append(s[0])
        if len(ans) == 2:
            print(ans[0]*ans[1])
            break
    
    if s[1] >= 4:
        print(s[0]**2)
        break

else:
    print(0)

Measured memory_bytes: 21540
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {
	int K;
	cin >> K;

	vector<int>A(32);
	A = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	
	cout << A[K - 1] << endl;

}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using Int = long long unsigned int;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    Int n,wm; cin>>n>>wm; Int w[n],v[n],dp[n+1][wm+1]={};
    for (int i = 0; i < n; i++)cin>>w[i]>>v[i];
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= wm; j++){
            if(j<w[i])dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            else dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
        }
    }
    cout<<dp[n][wm]<<'\n';
}

Measured memory_bytes: 79232
import java.util.*;
public class Main{
	public static void main(String[] args) {
		long mod = 1000000007;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] arr = new long[n];
		for(int i=0;i<n;i++){
			arr[i]=sc.nextLong();
		}
		long[] suf = new long[n];
		suf[n-1]=arr[n-1];
		for(int i=n-2;i>=0;i--){
			suf[i]=(arr[i]+suf[i+1])%mod;
		}
		long ans=0;
		
		for(int i=0;i<n-1;i++){
			ans= (ans+(arr[i]*suf[i+1]))%mod;
		}
		System.out.println(ans%mod);
	}
}

Measured memory_bytes: 60996
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var u = xArray(1,n);
  var e = xArray("[]",n);
  for(var i = 1; i < n; i++){
    var t = o.l().map(a=>a-1);
    e[t[0]].push(t[1]);
    e[t[1]].push(t[0]);
  }
  return treeDia(e)%3 === 1 ? "Second":"First";
}

function treeDia(e){
  var v = 0, l;
  for(var i = 0; i < 2; i++){
    var r = [v];
    var a = Array(e.length).fill(0);
    a[v] = 1;
    l = -1;
    while(r.length){
      var q = r;
      r = [];
      l++;
      v = q[0];
      while(q.length){
        var t = q.pop();
        for(var j = 0; j < e[t].length; j++){
          if(a[e[t][j]])continue;
          r.push(e[t][j]);
          a[e[t][j]] = 1;
        }  
      }
    }
  }
  return l;
}

Measured memory_bytes: 99480
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

map<ll,ll> M;

int main(){
    ll N;
    cin >> N;
    ll C=N/11;
    if(N%11>6){
        cout << 2*C+2 << endl;
    }
    else if(N%11==0){
        cout << 2*C << endl;
    }
    else{
        cout << 2*C+1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <iostream>
// #include <cstdio>
// #include <algorithm>
typedef long long int ll;
using namespace std;
// int gcd(int a,int b){return a%b==0? b : gcd(b,a%b);}
int main(int argc, char const *argv[])
{
	ll n,x;
	cin >> n >> x;
	ll ans=0;
	ans = 3*(n-__gcd(n,x));
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
/*input
8
1 2 1 4 2 1 4 1
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

void run() {
	int n, i;
	cin >> n;
	vector<ll> a(n), freq(n+1, 0);
	for(i=0; i<n; i++) {
		cin >> a[i];
		freq[a[i]]++;
	}
	ll tot = 0;
	for(i=1; i<=n; i++) {
		// cout << "Freq of " << i << ": " << freq[i] << endl;
		tot += max(0ll, freq[i]*(freq[i]-1) / 2ll);
	}
	// cout << tot << endl;
	for(i=0; i<n; i++) {
		ll subtract = freq[a[i]] * (freq[a[i]] - 1) / 2;
		ll x = freq[a[i]] - 1;
		ll add = max(0ll, x * (x-1) / 2);
		cout << tot - subtract + add << endl;
	}

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);		
	int t = 1;
	// cin >> t;
	while(t--) {
		run();
	}
}


Measured memory_bytes: 5760