akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, C, K): (usize, usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let mut T: Vec<usize> = (0..N)
        .map(|_| {
                let mut line: String = String::new();
                std::io::stdin().read_line(&mut line).unwrap();
                line.trim().parse().unwrap()
        })
        .collect();

    T.sort();
    const INF: usize = 1_000_000_000_000_000;
    let (ans, _, _) = T.iter().fold((1, INF, 0), |(res, x, y), &t| {
        if t > x + K || y == C { (res + 1, t, 1) } else if x == INF { (res, t, y + 1) } else { (res, x, y + 1) }
    });

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

const int max_n = 101010;
int n;
vector<string> v;

string ans[max_n];

void dfs(int i, int a, int b, int c){
	if(a < 0 || b < 0 || c < 0) return;

	if(i == n){
		cout << "Yes" << "\n";
		rep(i, n) cout << ans[i] << "\n";
		exit(0);
	}

	if(v[i] == "AB"){
		ans[i] = "A";
		dfs(i+1, a+1, b-1, c);
		ans[i] = "B";
		dfs(i+1, a-1, b+1, c);
	}
	
	if(v[i] == "BC"){
		ans[i] = "B";
		dfs(i+1, a, b+1, c-1);
		ans[i] = "C";
		dfs(i+1, a, b-1, c+1);
	}

	if(v[i] == "AC"){
		ans[i] = "C";
		dfs(i+1, a-1, b, c+1);
		ans[i] = "A";
		dfs(i+1, a+1, b, c-1);
	}
}

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

	cin >> n;

	int a, b, c;
	cin >> a >> b >> c;

	v.resize(n);
	rep(i, n) cin >> v[i];

	dfs(0, a, b, c);
	cout << "No" << "\n";
}


Measured memory_bytes: 17460
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b[10000],c=0;
  cin>>a;
  for(int i=0;i<a;i++) cin>>b[i];
  sort(b,b+a,greater<int>());
  for(int i=0;i<a;i++){
    if(i%2==0) c=c+b[i];
    else c=c-b[i];
  }
  cout<<c<<"\n";
}


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

using namespace std;

typedef long long ll;
const int INF = 1001001001;

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    ll A_sum = 0, B_sum = 0;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        A_sum += A[i];
    }
    bool flag = true;
    for(int i = 0; i < N; ++i){
        cin >> B[i];
        B_sum += B[i];
        if(A[i] < B[i])     flag = false;
    }
    if(flag){
        cout << 0 << endl;
        return 0;
    }
    if(A_sum < B_sum){
        cout << -1 << endl;
        return 0;
    }
    
    int res = 0;
    ll negative_sum = 0;
    priority_queue<int> que;
    for(int i = 0; i < N; ++i){
        int temp = A[i] - B[i];
        if(temp < 0){
            negative_sum += temp;
            res++;
        }
        else if(temp > 0){
            que.push(temp);
        }
    }
    
    while(negative_sum < 0 && !que.empty()){
        int temp = que.top();
        que.pop();
        negative_sum += temp;
        res++;
    }
    
    cout << res << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int A, B, K;
  cin >> A >> B >> K;
  if (B - A + 1 <= 2 * K)
  {
    for (int i = A; i <= B; i++)
      cout << i << endl;
  }
  else
  {
    for (int i = A; i < A + K; i++)
      cout << i << endl;
    for (int i = B - K + 1; i <= B; i++)
      cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

int main() {
	int N, A;

	cin >> N >> A;

	if (N % 500 <= A)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	int l = 0;
	int r = 100005;
	for (int n = 0; n < M; ++n) {
		int L, R;
		cin >> L >> R;
		l = max(l, L);
		r = min(r, R);
	}
	if (l>r) {
		cout << 0 <<  endl;
	}
	else {
		cout << (1 + r - l) << endl;
	}
}


Measured memory_bytes: 3632
#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>;

map<ll,ll> factor(ll x) {
    map<ll,ll> cand;
    ll p = 2;
    if (x == 1) {
        return cand;
    }
    while (p * p <= x) {
        if (x % p == 0) {
            cand[p]++;
            x /= p;
        } else {
            p++;
        }
    }
    if (x != 1) {
        cand[x]++;
    }

    return cand;
}

void solve() {
    ll a, b;
    cin >> a >> b;

    map<ll, ll> fac_a = factor(a);
    map<ll, ll> fac_b = factor(b);

    ll ans = 0;
    for (auto it = fac_a.begin(); it != fac_a.end(); it++) {
        // cout << it->first << " " << it->second << endl;
        if (fac_b[it->first] != 0) {
            ans++;
        }
    }

    // cout << endl;
    // for (auto it = fac_b.begin(); it != fac_b.end(); it++) {
    //     cout << it->first << " " << it->second << endl;
    // }
    cout << ans + 1 << endl;
}

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


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int res = 0,sum = 0;
    int n; cin>>n;
    while(n--)
    {
        int x;
        cin >> x;
        res = (res + (1LL * x * sum) % 1000000007) % 1000000007;
        sum = (sum + x) % 1000000007;
    }
    cout << res;
    return 0;
}

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

#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 fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int X, Y, A, B, C, tmp;
	cin >> X >> Y >> A >> B >> C;
	uint64_t res = 0;
	multiset<int> P, Q, R;
	forn(i, A)
	{
		cin >> tmp;
		P.insert(-tmp);
	}
	forn(i, B)
	{
		cin >> tmp;
		Q.insert(-tmp);
	}
	forn(i, C)
	{
		cin >> tmp;
		R.insert(-tmp);
	}

	int su = 0, rctr = 0, gctr = 0;
	while (su < X + Y)
	{
		int rb = 0, gb = 0, cb = 0;
		if (rctr < X && P.size() > 0)
			rb = -(*P.begin());
		if (gctr < Y && Q.size() > 0)
			gb = -(*Q.begin());
		if (R.size() > 0)
			cb = -(*R.begin());
		if (rb >= gb && rb >= cb)
		{
			rctr++;
			res += rb;
			P.erase(P.begin());
		}
		else if (gb > cb)
		{
			gctr++;
			res += gb;
			Q.erase(Q.begin());
		}
		else 
		{
			res += cb;
			R.erase(R.begin());
		}
		++su;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 14336
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100


int M,N;
int X1[NUM],Y1[NUM];
int X2[NUM],Z2[NUM];

double width(int* X,int* Y,int N, double x){
	double lb = DBL_MAX,ub = -DBL_MAX;
	for(int i = 0; i < N; i++){
		double x1 = X[i],y1 = Y[i],x2 = X[(i+1)%N], y2 = Y[(i+1)%N];
		if((x1-x)*(x2-x) <= 0 && x1 != x2){
			double y = y1 + (y2-y1)*(x-x1)/(x2-x1);
			lb = min(lb,y);
			ub = max(ub,y);
		}
	}
	return max(0.0,ub-lb);
}

void solve(){
	int min1 = *min_element(X1,X1+M),max1 = *max_element(X1,X1+M);
	int min2 = *min_element(X2,X2+N),max2 = *max_element(X2,X2+N);
	vector<int> xs;
	for(int i = 0; i < M; i++)xs.push_back(X1[i]);
	for(int i = 0; i < N; i++)xs.push_back(X2[i]);
	sort(xs.begin(),xs.end());

	double res = 0;
	for(int i = 0; i+1 < xs.size(); i++){
		double a = xs[i],b = xs[i+1], c = (a+b)/2;
		if(min1 <= c && c < max1 && min2 <= c && c <= max2){
			
			double fa = width(X1,Y1,M,a)*width(X2,Z2,N,a);
			double fb = width(X1,Y1,M,b)*width(X2,Z2,N,b);
			double fc = width(X1,Y1,M,c)*width(X2,Z2,N,c);
			res += (b-a)/6*(fa+4*fc+fb);
		}
	}
	printf("%.10lf\n",res);
}

void func(){

	for(int i = 0; i < M; i++){
		scanf("%d %d",&X1[i],&Y1[i]);
	}

	for(int i = 0; i < N; i++){
		scanf("%d %d",&X2[i],&Z2[i]);
	}

	solve();

}


int main(){

	while(true){
		scanf("%d %d",&M,&N);
		if(M == 0 && N == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
//main
signed main(){
  int N,M;cin>>N>>M;
  std::vector<int> eki(M),sta(M),c(M);
  typedef pair<int,int> P;
  map<P,int> m;
  std::vector<P> v(2*M+N);
  for(int i=0;i<M;i++){
    cin>>eki[i]>>sta[i]>>c[i];eki[i]--;sta[i]--;
    m[P(eki[i],c[i])]=m[P(sta[i],c[i])]=0;
  }
  for(int i=0;i<N;i++)m[P(i,-1)]=0;
  int cnt=0;
  for(auto &p:m){
    v[cnt]=p.first;
    p.second=cnt++;
  }
  std::vector<P> edge[cnt];
  for(int i=0;i<M;i++){
    edge[m[P(eki[i],c[i])]].push_back(P(m[P(sta[i],c[i])],0));
    edge[m[P(sta[i],c[i])]].push_back(P(m[P(eki[i],c[i])],0));
  }
  std::vector<set<int>> s(N);
  for(auto p:m)if(~p.first.second)s[p.first.first].insert(p.first.second);
  for(int i=0;i<N;i++){
    for(int p:s[i]){
      P q=P(i,p);
      edge[m[q]].push_back(P(m[P(i,-1)],0));
      edge[m[P(i,-1)]].push_back(P(m[q],1));
    }
  }
  priority_queue<P,vector<P>,greater<P>> que;
  que.push(P(0,m[P(0,-1)]));
  std::vector<int> d(cnt,INF);d[m[P(0,-1)]]=0;
  while(que.size()){
    P p=que.top();que.pop();
    int k=p.first,n=p.second;
    if(d[n]<k)continue;
    for(auto q:edge[n]){
      if(d[n]+q.second<d[q.first]){
        d[q.first]=d[n]+q.second;
        que.push(P(d[q.first],q.first));
      }
    }
  }
  if(d[m[P(N-1,-1)]]==INF)fin(-1);
  else fin(d[m[P(N-1,-1)]]);
}


Measured memory_bytes: 117236
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    vector<int64_t> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }

    const int64_t MOD = 1e9 + 7;
    int64_t result = 0;
    rep(i, 60)
    {
        int cnt = 0;
        int64_t d = 0;
        rep(j, n)
        {
            int f = (a[j] >> i) & 1;
            if (f != 0)
            {
                d += j - cnt;
                cnt++;
            }
            else
            {
                d += cnt;
            }
        }
        result += (d % MOD) * ((1L << i) % MOD) % MOD;
        result %= MOD;
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

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

int main() {
  int N;
  std::cin >> N;

  std::vector<int> A(N);

  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }

  int min_gcd = A[0], min_gcd_index = 0;

  for (int i = 0; i < N; i++) {
    int current_gcd = gcd(A[i], min_gcd);

    if (min_gcd > current_gcd) {
      min_gcd_index = i;
      min_gcd = current_gcd;
    }
  }

  int worst_gcd = A[min_gcd_index], worst_index = min_gcd_index;

  for (int i = 0; i < N; i++) {
    if (i == min_gcd_index) {
      continue;
    }

    int current_gcd = gcd(A[i], A[min_gcd_index]);

    if (worst_gcd > current_gcd) {
      worst_index = i;
      worst_gcd = current_gcd;
    }
  }

  // min_gcd_index と worst_index のどちらかを除く
  int answer_1 = A[min_gcd_index], answer_2 = A[worst_index];

  for (int i = 0; i < N; i++) {
    if (i != worst_index) {
      answer_1 = gcd(answer_1, A[i]);
    }
  }

 for (int i = 0; i < N; i++) {
    if (i != min_gcd_index) {
      answer_2 = gcd(answer_2, A[i]);
    }
  }

  std::cout << std::max(answer_1, answer_2) << std::endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
  long long n;
  cin >> n;
  vector<pair<long long, long long> > pairs(n);
  for(long long i=0; i<n; i++){
    long long x, l;
    cin >> x >> l;
    pairs[i] = make_pair(x+l, x-l);
  }
  sort(pairs.begin(), pairs.end());
  long long now = 0;
  long long min = pairs[0].first;
  long long count = 1;
  while(true){
    bool finish = true;
   	for(long long i=now+1; i<n; i++){
      if(pairs[i].second >= min){
        now = i;
        min = pairs[i].first;
        count++;
        finish = false;
      }
    }
    if(finish) break;
  }
  cout << count << endl;
  return 0;
}
  

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int h,w,a,b;
int main() {
	scanf("%d%d%d%d",&h,&w,&a,&b);
	swap(a,b);
	rep(i,0,h) {
		rep(j,0,w) if ((i<a)==(j<b)) putchar('1'); else putchar('0');
		puts("");
	}
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#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 forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(arr,n)       for(int i=0;i<n;i++)cin>>arr[i]
#define output(arr,n)      for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define for_each(arr)      for(auto& it:arr)cout<<it<<" "
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x) 
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(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; }*/
/*int fx1[]={+1,-1,+0,+0};
int fy1[]={+0,+0,+1,-1};
int fx2={+0,+0,+1,-1,-1,+1,-1,+1};
int fy2={-1,+1,+0,+0,+1,+1,-1,-1};
*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
   // #ifndef ONLINE_JUDGE
  //  freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
  //  #endif
    cin>>n>>s;
    for(int i=0;i<s.size();i++){
    	s[i]=(s[i]-'A'+n)%26+'A';
    }
    cout<<s<<endl;
    

    
   	
    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}
 


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

long long dp[110][100010];

int main()
{
	int N,W;
	int v[110] ,w[110];
	cin>>N>>W;
	for(int i=1;i<=N;i++)
	{
		cin>>w[i]>>v[i];
	}
	for(int i=1;i<=N;i++)
	{
		for(int j=1;j<=W;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(j-w[i]>=0)
			{
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
			}
		}
	}
	cout<<dp[N][W];
	
}



Measured memory_bytes: 81744
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
typedef long long int ll;

ll go(ll *h,ll n,ll index,ll *dp){
  if(dp[index]!=0){

    return dp[index];
  }
  if(n<0){
    return 0;
  }
  if(n==0){
    return 0;
  }
  if(n==1){
    return 0;
  }
  if(n==2){
    return abs(h[1]-h[0]);
  }
  ll ans1=go(h+1,n-1,index+1,dp)+abs(h[1]-h[0]);
  ll ans2=go(h+2,n-2,index+2,dp)+abs(h[2]-h[0]);
  return dp[index]=min(ans1,ans2);
}

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

    ll n;
    cin>>n;
    ll *h=new ll[n];
    ll *dp=new ll[n];
    REP(i,n){
       cin>>h[i];
      dp[i]=0;
    }
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
      dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
    }

    cout<<dp[n-1]<<endl;
    return 0;
  }




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007

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




int main()
{
  int n ;
  cin >> n ;
  vector<int> hei(n) ;
  int count = 0 ;
  
  REP(i,n){
    cin >> hei.at(i) ;
  }
  
  int ma = 0 ;
  
  REP(i,n){
    ma = max(ma,hei.at(i)) ;
   // cout << ma <<endl ;
    if(ma==hei.at(i)){
      count++ ;
    }
  }
  cout << count <<endl ;
    
    

  return 0 ;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

vector<int> tonari[200010];

int main() {
    ll a,b;
    cin>>a>>b;
    if(a==1||b==1){
        cout<<1<<endl;
        return 0;
    }
    if(a%2==0||b%2==0) {
        cout << a * b / 2ll << endl;
    }else{
        cout<<a*b/2ll+1<<endl;
    }
    return 0;
}


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

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
}

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> arr;
  for (int i = 0; i < 2 * a - 1; ++i) {
    arr.push_back(b - a + 1 + i);
  }
  print(arr);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int calc(int n, int currentValue, int k){
    if(n == 0)
        return currentValue;

    int result1, result2;
    result1 = currentValue * 2;
    result2 = currentValue + k;

    return calc(n-1, min(result1, result2), k);
}

int main(void){
    int n,k;
    cin >> n >> k;
    cout << calc(n, 1, k) << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import permutations

N, M = map(int, input().split())

edges =[set() for _ in range(N)]
for _ in range(M):
    fr, to = map(int, input().split())
    fr -= 1
    to -= 1
    edges[fr].add(to)
    edges[to].add(fr)

ans = 0
for perm in permutations(range(1, N), r=N-1):
    for prev, now in zip((0,) + perm, perm):
        if not now in edges[prev]:
            break
    else:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include<iostream>
    using namespace std;
    int main(){
    	int n;
    	cin>>n;
    	long long int sum=0;
    	int a[200000];
    	for(int i=0;i<n;i++){
    		cin>>a[i];
    		sum+=a[i];
    	}
    	sum-=a[n-1];
    	long long int k=a[n-1];
    	long long int min=abs(sum-k);
    	for(int i=n-2;i>0;i--){
    		sum-=a[i];
    		k+=a[i];
    		if(abs(sum-k)<min){
    			min=abs(sum-k);
    		}
    		
    	}
    	cout<<min;
    
    }

Measured memory_bytes: 1024
import java.util.*;

class Main{            
     
   public static void main(String[] args){
       Scanner sc = new Scanner(System.in);  
       
       int N = sc.nextInt();
       
       int max =  Integer.MIN_VALUE;
               
       for(int i = 1 ;i*i <=N;i++){
           max = Math.max(i*i,max);
       }

       System.out.println(max);
      
       
       
       
   }
}
        

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

int  main()
{
	string s;
	cin >> s;
	if (s.back() == 's')
		s += "es";
	else
		s += "s";
	cout << s << endl;
	return (0);
}


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

int main(){
    int n;
    vector<int> A;
    A.resize(5);
    cin>>n;
    int64_t ans=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a>n-1){
            ans+=a-(n-1);
            A[i]=n-1;
        }else{
            A[i]=a;
        }
    }
    sort(A.begin(),A.end(),greater<int>());
    if(n==1){
        ans+=0;
    }else if(n==2){
        ans+=1;
    }else if(n==3){
        ans+=3;
    }else if(n==4){
        if(A[2]==3){
            ans+=6;
        }else if(A[1]==3){
            ans+=5;
        }else{
            ans+=4;
        }
    }else{
        if(A[0]==4){
            if(A[3]==4){
                ans+=10;
            }else if(A[1]==4){
                ans+=A[2]+5;
            }else{
                if(A[4]==3){
                    ans+=8;
                }else{
                    ans+=A[1]+A[2]+1;
                }
            }
        }else{
            if(A[3]==3){
                ans+=A[3]+A[4]+1;
            }else if(A[1]==3){
                ans+=A[1]+A[2];
            }else{
                ans+=A[0]+A[1];
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3160
n,x = map(int,input().split())
a = sorted([int(x) for x in input().split()])

ans = 0
for i in range(n):
    if x >= a[i] and i != n-1:
        x -= a[i]
        ans += 1
    elif i == n-1:
        if x == a[i]:
            ans += 1

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#define llint long long
using namespace std;

llint N, A, B;
vector<int> ans;

int main(void)
{
	cin >> N >> A >> B;
	
	if(N < A+B-1 || N > A*B){
		cout << -1 << endl;
		return 0;
	}
	
	llint rem = N - (A+B-1);
	for(int i = B; i >= 1; i--) ans.push_back(i);
	
	llint prev = B, next;
	for(int i = 2; i <= A; i++){
		next = prev + min(rem, B-1)+1;
		rem -= min(rem, B-1);
		for(int j = next; j > prev; j--) ans.push_back(j);
		prev = next;
	}
	
	for(int i = 0; i < ans.size(); i++){
		cout << ans[i] << " ";
	}
	cout << endl;
}

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

const int MAXN = 200005;

struct LIS {
  const int INF = 2e9;

  vector<pair<int, int>> history;
  int ans[MAXN];

  LIS() {
    for (int i = 0; i < MAXN; i++) {
      ans[i] = INF;
    }
    ans[0] = -INF;
    history.clear();
  }

  void Insert(int x) {
    int lb = lower_bound(ans, ans + MAXN, x) - ans;
    history.emplace_back(lb, ans[lb]);
    ans[lb] = x; 
  }

  void Rollback() {
    ans[history.back().first] = history.back().second;
    history.pop_back();
  }

  int Query() {
    return lower_bound(ans, ans + MAXN, INF) - ans - 1;
  }
};

LIS Solver;

int N;
int A[MAXN];
int Answer[MAXN];
vector<int> adj[MAXN];

vector<int> Query[2 * MAXN + 5];

void AddQuery(int n, int tl, int tr, int l, int r, int x) {
  if (tr < l || r < tl || tl > tr || l > r) return;
  if (l <= tl && tr <= r) {
    Query[n].emplace_back(x);
    return;
  }
  int mid = (tl + tr) / 2;
  int lc = n + 1;
  int rc = n + 2 * (mid - tl + 1);
  AddQuery(lc, tl, mid, l, r, x);
  AddQuery(rc, mid + 1, tr, l, r, x);
}

void Solve(int n, int tl, int tr) {
  for (auto Q : Query[n]) {
    if (Q > 0) {
      Solver.Insert(Q);
    } else {
      Answer[-Q] = Solver.Query();
    }
  }

  if (tl != tr) {
    int mid = (tl + tr) / 2;
    int lc = n + 1;
    int rc = n + 2 * (mid - tl + 1);
    Solve(lc, tl, mid);
    Solve(rc, mid + 1, tr);
  }

  for (auto Q : Query[n]) {
    if (Q > 0) { // remove from LIS
      Solver.Rollback();
    }
  }
}

pair<int, int> tour[MAXN];

void dfs(int n, int p, bool add) {
  static int tin = 0;
  if (!add) tour[n].first = tin++;
  if (add) AddQuery(1, 0, MAXN, tour[n].first, tour[n].second, A[n]);
  for (auto i : adj[n]) if (i != p) dfs(i, n, add);
  if (!add) tour[n].second = tin - 1;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 1; i < N; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
  }

  dfs(0, -1, 0);
  dfs(0, -1, 1);

  for (int i = 0; i < N; i++) {
    AddQuery(1, 0, MAXN, tour[i].first, tour[i].first, -i);
  }

  Solve(1, 0, MAXN);
  for (int i = 0; i < N; i++) {
    cout << Answer[i] << "\n";
  }
  return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

#define	MOD 1000000007

int	main() {
	int A, B, C;
	cin >>A >>B >>C;
	for (int i=1; i<=B; i++) 
		if (C==(A*i)%B) {
			cout <<"YES" <<endl;
			return 0;
		}
	cout <<"NO" <<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,c1,c2,c3,c4;
string a[100005];


int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  for(int i=0;i<n;i++){
    if(a[i]=="AC")c1++;
    else if(a[i]=="WA")c2++;
    else if(a[i]=="TLE")c3++;
    else if(a[i]=="RE")c4++;
  }
  cout<<"AC"<<" "<<'x'<<" "<<c1<<endl;
  cout<<"WA"<<" "<<'x'<<" "<<c2<<endl;
  cout<<"TLE"<<" "<<'x'<<" "<<c3<<endl;
  cout<<"RE"<<" "<<'x'<<" "<<c4<<endl;

        return 0;
}


Measured memory_bytes: 6712
#include <iostream>
#include <cctype>
#include <string>
using namespace std;
int main(void){
    
    string s,a,b;
    cin>>s>>a>>b;
   
    
    
    cout<<(char)toupper(s[0])<<(char)toupper(a[0])<<(char)toupper(b[0])<<endl;
    
}
   


Measured memory_bytes: 256
def is_prime(i):
  if i < 2:
    return False
  for j in range(2, i):
    if i % j == 0:
      return False
  return True
primes = [i for i in range(100) if is_prime(i)]

n = int(input())
dic = {}
for i in primes:
  dic[i] = 0

def soinsuubunnkai(x, dic):
  while True:
    for i in primes:
      if x % i == 0:
        dic[i] += 1
        x //= i
        break
    else:
      break

for i in range(1, n + 1):
  soinsuubunnkai(i, dic)

s75 = len([i for i in list(dic.values()) if i >= 74])
s25 = len([i for i in list(dic.values()) if i >= 24])
s15 = len([i for i in list(dic.values()) if i >= 14])
s5 = len([i for i in list(dic.values()) if i >= 4])
s3 = len([i for i in list(dic.values()) if i >= 2])
ans = 0
ans += s75
ans += s25 * (s3 - 1)
ans += s15 * (s5 - 1)
ans += (s5 * (s5 - 1)) // 2 * (s3 - 2)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const int MOD = 1000000007;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
const char q = '?';
int dp[51][2];//?????????n - i - 1????????§????????¨????????´????????°(j == 0 ? ??°??????????????????: ??°????????????)
int main(){
    ios::sync_with_stdio(false);
    string a, b, c;
    while(cin >> a && a != "0"){
        cin >> b >> c;
        int n = a.size();
        memset(dp, 0, sizeof(dp));
        dp[n][0] = 1;
        for(int keta = n - 1; keta >= 0; --keta){
            rep(k, 10){
                int kk = k;
                if(a[keta] != q){
                    kk = a[keta] - '0';
                    k = 9;
                }
                if(!keta && !kk) continue;
                rep(i, 10){
                    int ii = i;
                    if(b[keta] != q){
                        ii = b[keta] - '0';
                        i = 9;
                    }
                    if(!keta && !ii) continue;
                    rep(j, 10){
                        int jj = j;
                        if(c[keta] != q){
                            jj = c[keta] - '0';
                            j = 9;
                        }
                        if(!keta && !jj) continue;
                        int temp = dp[keta][0];
                        if(kk + ii == jj) dp[keta][0] += dp[keta + 1][0];
                        if(kk + ii + 1 == jj) dp[keta][0] += dp[keta + 1][1];
                        if(kk + ii - 10 == jj) dp[keta][1] += dp[keta + 1][0];
                        if(kk + ii - 9 == jj) dp[keta][1] += dp[keta + 1][1];
                        dp[keta][0] %= MOD;
                        dp[keta][1] %= MOD;
                        //if(temp < dp[keta][0]) cout << kk << ' ' << ii << ' ' << jj << endl;
                    }
                }
            }
        }
        //rep(i, n) rep(j, 2) cout << dp[i][j] << endl;
        cout << dp[0][0] << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    s = input()
    l = len(s)
    flag = True

    for i in range(l):
        if (i + 1) % 2 == 1:
            if s[i] == 'L':
                flag = False
        else:
            if s[i] == 'R':
                flag = False

    if flag:
       print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }

int main() {
  ull a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;

  ull result = 0;
  if (max(a, b) - min(a, b) > k) {
    cout << ":(" << endl;
  } else if (max(a, c) - min(a, c) > k) {
    cout << ":(" << endl;
  } else if (max(a, d) - min(a, d) > k) {
    cout << ":(" << endl;
  } else if (max(a, d) - min(a, d) > k) {
    cout << ":(" << endl;
  } else if (max(a, e) - min(a, e) > k) {
    cout << ":(" << endl;
  } else if (max(b, c) - min(b, c) > k) {
    cout << ":(" << endl;
  } else if (max(b, d) - min(b, d) > k) {
    cout << ":(" << endl;
  } else if (max(b, e) - min(b, e) > k) {
    cout << ":(" << endl;
  } else if (max(c, d) - min(c, d) > k) {
    cout << ":(" << endl;
  } else if (max(c, e) - min(c, e) > k) {
    cout << ":(" << endl;
  } else if (max(d, e) - min(d, e) > k) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    ll dist=abs(a-b);
    if(dist==0) cout << "YES" << endl;
    else{
        if(v<w) cout << "NO" << endl;
        else{
            if(t*(v-w)>=dist) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
    }
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A, B, C, D;
  string s;
  cin >> A >> B >> C >> D;
  
  while(true){
    C -= B;
    if(C<=0){
      s = "Yes";
      break;
    }
    A -= D;
    if(A<=0){
      s = "No";
      break;
    }
    else continue;
  }
  cout << s << endl;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
main()
{
	int a[510],sum=0,n;
	scanf("%d",&n);
	for (int i=1;i<=2*n;i++) scanf("%d",&a[i]);
	sort(a+1,a+2*n+1);
	for (int i=0;i<n;i++) sum+=a[2*i+1];
	printf("%d\n",sum);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair < int,int > PII;
typedef pair < ll,ll > PLL;
#define pb push_back
//#all(x) (x).begin(),(x).end()

//int const N = 1;
int const MOD = 1e9 + 7;

ll bigmod(ll a, ll b)
{
    if(b==0)
        return 1 % MOD;
    ll x = bigmod(a,b/2);
    x = (x * x) % MOD;
    if(b%2)
        x = (x * a) % MOD;
    return x;
}

int const N = 3e3 + 10;
int dp[N][N];
string s,t;

int lcs(int i,int j)
{
    if(i >= s.size() or j >= t.size())
        return 0;
    int &r = dp[i][j];
    if(r != -1)
        return r;

    if(s[i] == t[j])
        r = 1 + lcs(i+1,j+1);
    else {
        r = max(lcs(i+1,j), lcs(i,j+1));
    }
    return r;
}

void print(int i,int j)
{
    if(i >= s.size() or j >= t.size())
        return;
    if(s[i] == t[j])
    {
        cout << s[i];
        print(i+1,j+1);
    }
    else if(lcs(i+1,j) > lcs(i,j+1))
    {
        print(i+1,j);
    }
    else
        print(i,j+1);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    memset(dp,-1,sizeof dp);

    cin >> s >> t;
    //cout << lcs(0,0);
    print(0,0);
    return 0;
}




Measured memory_bytes: 35968
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n,m;
	cin>>n;
	cin>>m;
	int a[n];
	int sum=0;
	for(int i=0;i<n;++i){
		cin>>a[i];
		sum+=a[i];
	}
	sort(a, a+n);
	bool flg=true;
	for(int i=0;i<m;++i){
		if(a[n-i-1]*4*m<sum){
			flg=false;
			break;
		}
	}
	cout<<((flg)?"Yes":"No")<<endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[int(input()) for i in range(n)]
memo=[0]*n

for i in range(n):
  if i == 0:
    k=0
    memo[0]=1
    ans=0
  else:
    k=a[k]-1
    if memo[k]==0:
      memo[k]=1
    else:
      print(-1)
      exit()
    ans += 1
  if k==1:
    print(ans)
    exit()

Measured memory_bytes: 7852
#include <iostream>
#include <map>

int n;
std::string s;
std::map<std::string, int> m;

int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> s;
        m[s]++;
    }
    std::cout << "AC x " << m["AC"] << std::endl;
    std::cout << "WA x " << m["WA"] << std::endl;
    std::cout << "TLE x " << m["TLE"] << std::endl;
    std::cout << "RE x " << m["RE"] << std::endl;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define GYOU_MAX 256

int main(void) {
	
	long long int A, B, K;
	scanf("%lld%lld%lld", &A, &B, &K);
	long long int a = A;

	if (A > K) {
		printf("%lld %lld", A - K, B);
		return 0;
	}
	else {
		A = 0;
	}

	if (B>K - a ) {
		printf("%lld %lld", A, B - K + a);
	}
	else {
		printf("%lld %lld", 0, 0);
	}



	return 0;
}

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

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

    int nr=0;
    for(int i = 0; i < n; i++) {
        if(s[i]=='R'){
            nr++;
        }
    }
    int q=0;
    for(int i = 0; i < nr; i++) {
        if(s[i]=='R'){
            q++;
        }
    }
    cout << nr-q << endl;
    

    return 0;
}

Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <string>
using namespace std;

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

    string ans = "Yes";
    for(int i = 1; i < n; i++){
        for(int j = 0; j < i; j++){
            if(w[j] == w[i]) ans = "No";
        }
        if(*(w[i-1].end()-1) != *(w[i].begin())) ans = "No";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
namespace my_std {
using namespace std;
#define reg register
#define Rint register int
#define FOR(i, a, b) for (register int i = (a), ed_##i = (b); i <= ed_##i; ++i)
#define ROF(i, a, b) for (register int i = (a), ed_##i = (b); i >= ed_##i; --i)
#define GO(x, p, e, i, v) for (register int i = p[x].head, v; i; i = e[i].link)
typedef long long i64;
#define Templ(T) template <typename T>
inline int read() {
    reg int ans = 0, f = 1;
    reg char c = getchar();
    while (!isdigit(c)) f ^= (c == '-'), c = getchar();
    for (; isdigit(c); c = getchar()) ans = (ans << 1) + (ans << 3) + (c ^ 48);
    return f ? ans : -ans;
}
Templ(_Tp) inline int chkmin(_Tp &x, _Tp y) { return x > y ? x = y, 1 : 0; }
Templ(_Tp) inline int chkmax(_Tp &x, _Tp y) { return x < y ? x = y, 1 : 0; }
} // namespace my_std
using namespace my_std;

#define N 500010
int n, m;
int f[3];
int comp;
struct Edge{
    int link, to;
}e[N << 1];
struct Vertice{
    int head, col;
}p[N];
int ecnt(0);
#define col(x) p[x].col
#define head(x) p[x].head
inline void A_E(int u, int v){
    e[++ecnt] = (Edge){head(u), v};
    head(u) = ecnt;
}
inline int qm3(reg const int &x){
    return x > 2 ? x - 3 : x;
}
inline i64 sqr(reg const int &x){
    return (i64)x * x;
}

inline void dfs(int u){
    Rint t;
    ++f[col(u)];
    GO(u, p, e, i, v){
        v = e[i].to;
        if(i & 1) ++ecnt;
        t = qm3(col(u) + 1 + (!(i & 1)));
        if(col(v) == -1){
            col(v) = t, dfs(v);
        }
        else{
            if(col(v) != t) comp = 1;
        }
    }
}

int main() {
    n = read(), m = read();
    Rint u, v;
    FOR(i, 1, m){
        u = read(), v = read();
        A_E(u, v), A_E(v, u);
    }
    FOR(i, 1, n) col(i) = -1;
    reg i64 ans(0);
    FOR(i, 1, n) if(col(i) == -1){
        col(i) = 0, f[0] = f[1] = f[2] = 0;
        ecnt = 0, comp = 0;
        dfs(i);
        if(comp){
            ans += sqr(f[0] + f[1] + f[2]);
            continue;
        }
        if(!f[0] || !f[1] || !f[2]){
            ans += ecnt;
            continue;
        }
        ans += (i64)f[0] * f[1] + (i64)f[1] * f[2] + (i64)f[2] * f[0];
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 10764
#include<bits/stdc++.h>
using namespace std;
int n,b[133],a[133];
string s;
int main(){
cin>>n;
memset(b,127,sizeof(b));
for(int i=1;i<=n;i++){
cin>>s;
memset(a,0,sizeof(a));
for(int j=0;j<s.size();j++)
a[s[j]]++;
for(int j=97;j<=122;j++)
b[j]=min(a[j],b[j]);}
for(int i=97;i<=122;i++)
for(int j=1;j<=b[i];j++)
cout<<char(i);}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#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;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

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

#define P pair<int,int>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
#define MAXE(a,b) a=max(a,b)
#define MINE(a,b) a=min(a,b)

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    string str;
    cin >> str;
    LL ans = 0;
    LL s = 0;
    for(int a = 0;a < str.size();a++){
        if(str.at(a) == 'W'){
            ans += a-s;
            s++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

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

  ll n, a, b;
  cin >> n >> a >> b;
  cout << max(0LL, (a + b * (n-1)) - (b + a * (n-1)) + 1) << endl;

  return 0;
}

Measured memory_bytes: 256
use std::io::{stdin, stdout, BufReader, BufRead, StdinLock, Write, BufWriter};

fn main() {
    let (std_in, std_out) = (stdin(), stdout());
    let mut br = BufReader::new(std_in.lock());
    let mut bw = BufWriter::new(std_out.lock());
    
    let __ = rvn::<usize>(&mut br);
    let (a, b) = (__[0], __[1]);
    if ((a + b) % 2 == 1) {
        writeln!(&mut bw, "IMPOSSIBLE");
    } else {
        writeln!(&mut bw, "{}", (a + b) / 2);
    }
}


//////////////////////////////////////////////////////////////////////////////////
#[allow(dead_code)]
fn rs(br: &mut BufReader<StdinLock>) -> Vec<char> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().chars().collect()
}

#[allow(dead_code)]
fn rn<T: std::str::FromStr>(br: &mut BufReader<StdinLock>) -> T {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn rvs(br: &mut BufReader<StdinLock>) -> Vec<Vec<char>> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.chars().collect()).collect()
}

#[allow(dead_code)]
fn rvn<T: std::str::FromStr>(br: &mut BufReader<StdinLock>) -> Vec<T> {
    let mut buf = String::new();
    br.read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;

int tr(int n)
{
	if (n > 0) return 1;
	else return -1;
}

vector<pair<int, int> > ans;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int k, x, y; cin >> k >> x >> y;
	if (k % 2 == 0 && (abs(x) + abs(y)) % 2 == 1) {
		cout << -1 << '\n';
		return 0;
	}
	if (abs(x) + abs(y) == k) {
		cout << 1 << '\n';
		cout << x << " " << y << '\n';
		return 0;
	}
	ans.push_back(make_pair(x, y));
	while (abs(x) + abs(y) > 2 * k || (k % 2 == 1 && (abs(x) + abs(y)) % 2 == 1)) {
		if (abs(x) >= k) x -= k * tr(x);
		else {
			int t = k - abs(x);
			x = 0;
			y -= t * tr(y);
		}
		ans.push_back(make_pair(x, y));
	}
	int b = x + y, c = k;
	if (b > 0) b -= k;
	else b += k;
	if (x > y) c = -k;
	y = (b + c) / 2; x = y - c;
	ans.push_back(make_pair(x, y));
	cout << ans.size() << '\n';
	for (int i = (int)ans.size() - 1; i >= 0; i--)
		cout << ans[i].first << " " << ans[i].second << '\n';
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    if(s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3)) cout << "Bad" << endl;
    else cout << "Good" << endl;
}

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

int main()
{
    int N, L;
    std::vector<std::string> book;
    std::string tmp;
    std::cin >> N >> L;
    for (int i = 0; i < N; i++)
    {
        std::cin >> tmp;
        book.push_back(tmp);
    }

    std::sort(book.begin(), book.end());
    for (std::string str : book) { std::cout << str; }
    std::cout << std::endl;

    return 0;
}

Measured memory_bytes: 256
#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> ;
#define PI 3.14159265358979323846264338327950
int main () {
    string s,t,u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if (s == u) {
         a -= 1;
    }
    if(t == u){
        b -= 1;
    }
    cout << a << " " << b << endl;

}



Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
using namespace std;
long long cat;
int l,a[1000000];
int n;
vector<int>M;
void insertionsort(int a[],int n,int g){
    for(int i=g;i<n;i++){
        int v=a[i];
        int j=i-g;
        while(j>=0&&a[j]>v){
            a[j+g]=a[j];
            j-=g;
            cat++;
        }
    a[j+g]=v;
    }
}
void xier(int a[],int n){
    for(int h=1; ;){
        if(h>n)break;
        M.push_back(h);
        h=3*h+1;
    }
    for(int i=M.size()-1;i>=0;i--){
        insertionsort(a,n,M[i]);
    }
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    cat=0;
    xier(a,n);
    printf("%d\n",M.size());
    for(int i=M.size()-1;i>=0;i--){
        printf("%d",M[i]);
        if(i)printf(" ");
    }printf("\n");
    printf("%d\n",cat);
    for(int i=0;i<n;i++){
        printf("%d\n",a[i]);
    }

return 0;
}

Measured memory_bytes: 6604
import java.util.*

fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val nodes = Array(n) { mutableListOf<Pair<Int, Int>>() }

    repeat(n-1) {
        val (a, b, c) = readLine()!!.split(" ").map { it.toInt() }
        nodes[a-1].add(Pair(b-1, c))
        nodes[b-1].add(Pair(a-1, c))
    }

    val (q, k) = readLine()!!.split(" ").map { it.toInt() }
    val stack = Stack<Int>()
    val seen = BooleanArray(n)
    val distance = LongArray(n) { 0L }

    stack.push(k-1)

    while (stack.isNotEmpty()) {
        val idx = stack.pop()
        seen[idx] = true

        nodes[idx].forEach {
            if (seen[it.first]) return@forEach
            distance[it.first] = distance[idx] + it.second
            stack.push(it.first)
        }
    }

    repeat(q) {
        val (x, y) = readLine()!!.split(" ").map { it.toInt() }
        println(distance[x-1] + distance[y-1])
    }
}

Measured memory_bytes: 125156