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

int main(){
  int n;
  cin >> n;
  vector<double> x(n), y(n);
  rep(i,n) cin >> x[i] >> y[i];
  vi v(n);
  rep(i,n) v[i] = i;
  double sum = 0;
  do{
    double len = 0;
    rep(i,n-1){
      double dist = pow(x[v[i]]-x[v[i+1]], 2) + pow(y[v[i]]-y[v[i+1]], 2);
      dist = pow(dist, 0.5);
      len += dist;
    }
    sum += len;
  }while(next_permutation(v.begin(),v.end()));
  int kai = 1;
  rep(i,n) kai *= i+1;
  sum /= kai;
  printf("%.7f", sum);
}


Measured memory_bytes: 4148
#include<iostream>
using namespace std;
typedef long long ll;

const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;

ll A[MAX_N], prob[MAX_N];

ll calc_pow(ll x, ll y) {
    ll z = 1;
    while (y > 0) {
        if (y & 1) {
            z = (z * x) % MOD;
        }
        x = (x * x) % MOD;
        y /= 2;
    }
    return z;
}

int main() {
    ll N;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];
    ll factorial = 1;
    // N!を計算
    for (ll i = 1; i <= N; i++) {
        factorial = (factorial * i) % MOD;
    }
    // 確率の累積和を計算
    for (ll i = 1; i <= N; i++) {
        prob[i] = (calc_pow(i, MOD - 2) + prob[i - 1]) % MOD;
    }
    ll ans = 0;
    for (ll j = 0; j < N; j++) {
        ll sum_prob = 0;
        sum_prob = (sum_prob + prob[j + 1]) % MOD;
        sum_prob = (sum_prob + prob[N - j]) % MOD;
        sum_prob = (sum_prob - prob[1] + MOD) % MOD;  // 余計に足してる分を引く
        ans = (ans + (sum_prob * A[j]) % MOD) % MOD;
    }
    ans = (ans * factorial) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,n) for(ll i=a;i<n;i++)
#define all(x) x.begin(),x.end()
#define bs binary_search
#define gcd(a,b) __gcd(a,b)
#define PI acos(-1)
#define lp lower_bound
#define up upper_bound
#define minimum(a)	*min_element(a.begin(), a.end())
#define maximum(a)	*max_element(a.begin(), a.end())
#define UNIQUE(x) (x).resize(unique(all(x))-(x).begin())
#define bp(x)  __bulitin_popcount(x)
using namespace std;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
 
const int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
int main()
{
boost
string s;
cin>>s;
bool ok=true;
for(ll i=0;i<s.length()-1;i+=2){
    if(s[i]=='h'&&i+1<s.length()&&s[i+1]=='i') continue;
    else {ok=false;break;}
}
if(ok&&s.length()%2==0)cout<<"Yes";
else cout<<"No";
return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

#define INF 2e9
int n, m;

vector<vector<int> > cost; // 隣接行列
vector<int> d; // 仮のコストの最小値、最終結果
deque<bool> used;
vector<set<pii> > route;

void dijkstra(int s) {
  d.assign(n, INF);
  used.assign(n, false);
  d[s] = 0;

  while (true) {
    int v = -1;
    rep (u, n) {
      if (!used[u] && (v == -1 || d[u] < d[v])) {
        v = u;
      }
    }
    if (v == -1) {
      break;
    }
    used[v] = true;
    rep (u, n) {
      if (d[u] > d[v] + cost[v][u]) {
        route[u] = route[v];
        route[u].insert({min(v, u), max(v, u)});
        d[u] = d[v] + cost[v][u];
      } else if (d[u] == d[v] + cost[v][u]) {
        route[u].insert({min(v, u), max(v, u)});
      }
    }
  }
}

int main() {
  scanf("%d %d", &n, &m);
  cost.assign(n, vi(n, INF));
  rep (i, n) {
    cost[i][i] = 0;
  }
  set<pii> all_edge;
  rep (i, m) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a -= 1; b -= 1;
    cost[a][b] = cost[b][a] = c;
    all_edge.insert(make_pair(min(a, b), max(a, b)));
  }
  route.resize(n);
  rep (i, n) {
    rep (j, n) {
      route[j].clear();
    }
    dijkstra(i);
    rep (j, n) {
      for (pii p : route[j]) {
        all_edge.erase(p);
      }
    }
  }
  printf("%d\n", (int)all_edge.size());

  return 0;
}


Measured memory_bytes: 768
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

ll MAX=100007;
vector<ll> F(MAX,1);
 
void fact(){
    for(ll i=1;i<MAX;i++){
    F[i]=F[i-1]*i%MOD;
    }
return;
}


// mod. m での a の逆元 a^{-1} を計算する
//ただしmとaが互いにその時のみ
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long comb(long long a, long long b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return (((F[a]*modinv(F[b],MOD))%MOD)*modinv(F[a-b],MOD))%MOD;
}

//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓



int main(){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    fact();
    ll N;
    cin >> N;
    vector<ll> a(N+1,0);
    for(ll i=0;i<N+1;i++)cin>>a[i];
    ll A=INF,B=INF;
    Map M;
    for(ll i=0;i<N+1;i++)M[a[i]]++;
    ll mark;
    for(auto p: M)if(p.second==2){mark=p.first;}
    for(ll i=0;i<N+1;i++){
        if(a[i]==mark&&A==INF)A=i;
        else if(a[i]==mark)B=i;
    }
    print(N)
    for(ll i=2;i<=N+1;i++){
        ll ans=0;
        ans+=comb(N-1,i);
        ans+=comb(N-1,i-2);
        ans-=comb(N+A-B,i-1);
        ans+=comb(N-1,i-1)*2;
        print((ans+MOD)%MOD)
    }

    return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
#define int long long int
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
vector<string> f(char a, int N)
{
  string s = "";
  if (N == 0)
    return vector<string>(1, s);
  vector<string> ans;
  for (int i = N - 1; i >= 0; i--)
  {
    s += a;
    auto t = f(a + 1, i);
    for (auto ss : t)
    {
      ans.push_back(s + ss);
    }
  }
  return ans;
}
void solve(long long N)
{
  string s = "";
  rep(i, N) s += 'a' + i;
  vector<string> cur;
  cur.push_back("");
  rep(i, N)
  {
    vector<string> nxt;
    for (auto s : cur)
    {
      rep(j, i + 1)
      {
        char c = ('a' + j);
        if (j == 0 || (j && s.find(c - 1) != string::npos))
          nxt.push_back(s + c);
      }
    }
    cur = move(nxt);
  }

  for (auto s : cur)
  {
    cout << s << endl;
  }
}

signed main()
{
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


Measured memory_bytes: 9164
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

const int maxn=5e2+10;
int n,m;
char p[maxn][maxn],r[maxn][maxn],b[maxn][maxn];

int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=0;i<n;++i)
		cin>>p[i];
	memset(r,'.',sizeof(r));
	memset(b,'.',sizeof(b));
	r[0][m]=b[0][m]=r[n-1][m]=b[n-1][m]=0;
	for(int i=1;i<n-1;++i){
		r[i][0]='#';
		for(int j=1;j<m-1;++j)
			if(i&1)
				r[i][j]='#';
			else
				b[i][j]='#';
		b[i][m-1]='#';
		r[i][m]=b[i][m]=0;
	}
	for(int i=0;i<n;++i)
		for(int j=0;j<m;++j)
			if(p[i][j]=='#')
				r[i][j]=b[i][j]='#';
	for(int i=0;i<n;++i)
		cout<<r[i]<<endl;
	cout<<endl;
	for(int i=0;i<n;++i)
		cout<<b[i]<<endl;
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn=1e5;
bool a[maxn];
int n,x;
int main(){
	cin>>x>>n;
	for (int i=1;i<=n;i++){
		int tp;
		scanf("%d",&tp);
		a[tp]=1;
	}
	for (int i=0;i<=1e9;i++){
		if (x-i>=0){
			if (a[x-i]==0){
				cout<<x-i<<endl;
				return 0;
			}
		}
		if (a[x+i]==0){
			cout<<x+i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> ant(5);
  int k;
  for(int i=0;i<5;i++){
   cin>>ant.at(i); 
  }
  cin>>k;
  if(ant.at(4)-ant.at(0)<=k){
   cout<<"Yay!"<<endl;
    return 0;
  }
  cout<<":("<<endl;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(10)]
a=[list(map(int,input().split())) for _ in range(h)]

dist=[]
dist.extend(c)
for i in range(10):
  for j in range(10):
    for k in range(10):
      if dist[j][k]>dist[j][i]+dist[i][k]:
        dist[j][k]=dist[j][i]+dist[i][k]
print(sum(dist[a[i][j]][1] for i in range(h) for j in range(w) if a[i][j]>-1))

Measured memory_bytes: 9448
package main

import (
	"fmt"
	"io"
	"os"
)

var (
	reader io.Reader = os.Stdin
	writer io.Writer = os.Stdout
)

func main() {
	run()
}

func run() {
	var a, b, c, x int
	fmt.Fscan(reader, &a)
	fmt.Fscan(reader, &b)
	fmt.Fscan(reader, &c)
	fmt.Fscan(reader, &x)
	x /= 50
	var count int

	for i := 0; i <= a; i++ {
		sum1 := 10 * i

		switch {
		case sum1 == x:
			count++
			fmt.Fprintln(writer, count)
			return
		case sum1 > x:
			fmt.Fprintln(writer, count)
			return
		}

	LOOP_J:
		for j := 0; j <= b; j++ {
			sum2 := sum1 + 2*j

			switch {
			case sum2 == x:
				count++
				break LOOP_J
			case sum2 > x:
				break LOOP_J
			}

		LOOP_K:
			for k := 0; k <= c; k++ {
				sum3 := sum2 + k

				switch {
				case sum3 == x:
					count++
					break LOOP_K
				case sum3 > x:
					break LOOP_K
				}
			}
		}
	}

	fmt.Fprintln(writer, count)
}


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

using namespace std;

const int MaxN = 2005;
const int oo = 1e9;

int n,x,y;
vector<int> Adj[MaxN];
int Ans[MaxN], Depth[MaxN];
queue<int> q;

void BFS(int t)
{
    for (int i = 1; i <= n; i++)
    {
        Depth[i] = oo;
    }
    q.push(t);
    Depth[t] = 0;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        if (u > t)
        {
            Ans[Depth[u]]++;
        }
        for (auto v : Adj[u])
        {
            if (Depth[v] == oo)
            {
                Depth[v] = Depth[u] + 1;
                q.push(v);
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> x >> y;
    for (int i = 1; i < n; i++)
    {
        Adj[i].push_back(i + 1);
        Adj[i + 1].push_back(i);
    }
    Adj[x].push_back(y);
    Adj[y].push_back(x);
    for (int i = 1; i < n; i++)
    {
        BFS(i);
    }
    for (int i = 1; i < n; i++)
    {
        cout << Ans[i] << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
int main()
{
  int n,m;
  cin>>n>>m;
  vector<int> adj[n];
  for(int i=0;i<m;i++)
  {
    int a,b;
    cin>>a>>b;
    adj[a-1].push_back(b-1);
    adj[b-1].push_back(a-1);
  }
  int ans[n];
  memset(ans,-1,sizeof(ans));
  queue<int> q;
  q.push(0);
  while(!(q.empty()))
  {
    int v=q.front();
    q.pop();
    for(int u:adj[v])
    {
      if(ans[u]<0)
      {
        ans[u]=v;
        q.push(u);
      }
    }
  }
  int flag=0;
  for(int i=1;i<n;i++)
  {
    if(ans[i]<0)
    {
      flag=1;
      break;
    }
  }
  if(flag)
  {
    cout<<"No"<<endl;
  }
  else
  {
    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++)
    {
      cout<<ans[i]+1<<endl;
    }
  }
}

Measured memory_bytes: 10512
#include<iostream>
#include <string>
#include<vector>
typedef long long ll;

using namespace std;
int main()
{
	int n;
	cin >> n;
	int a, b;
	if (n == 2) {
		cin >> a >> b;
		cout << a + b;
	}
	else {
		cout << "Hello World";
	}
	return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>
#include <functional>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* ---------- Functions */
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string S, T;
    cin >> S >> T;

    if (S.size() + 1 != T.size()) {
        cout << "No" << endl;
        return 0;
    }

    for (int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
const constexpr ll INF = 1LL<<55;
ll a[int(2e5) + 10];
void solve() {
	var(int, n);
	int t;
	unordered_map<ll, ll> m;
	m[0] = 1;
	rep(i, 1, n + 1) {
		cin >> t;
		a[i] = a[i - 1] + t;
		++m[a[i]];
	}
	ll ans = 0;
	each(b, m) {
		ans += b.se * (b.se - 1) / 2;
	}
	print(ans);
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 10056
#include<bits/stdc++.h>
#define ll          long long int
#define ios        	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{	ios
  ll n ;
  cin>> n ;
  vector <ll> v(n,0) ;
  for(ll i=0;i<n;i++)
  {
    cin>> v[i] ;
  }
  vector <ll> a(n,0) ;
  a[0]=0 ;
  a[1]= abs(v[1]-v[0]) ;
  for(ll i=2;i<n;i++)
  {
   a[i]= min(a[i-1]+abs(v[i]-v[i-1]),a[i-2]+abs(v[i]-v[i-2])) ; 
  }
  cout<< a[n-1] ;
	return 0 ;
}


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

int main()
{
string s;
cin>>s;
if(s.compare("Sunny")==0)cout<<"Cloudy"<<endl;
if(s.compare("Cloudy")==0)cout<<"Rainy"<<endl;
if(s.compare("Rainy")==0)cout<<"Sunny"<<endl;
return 0;
}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 12 01:45:52 2020

@author: Kanaru Sato
"""

n = int(input())
flag = 0

for i in range(1,10):
    if n%i == 0 and n//i <= 9:
        flag = 1
      
if flag == 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 2940
//
//  main.cpp
//  ProgrammingContestChallengeBook2
//
//  Created by Hisaki Kobayashi on 2020/04/04.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
#include <stdlib.h>
//#include "mylibrary.hpp"

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

using namespace std;
int main(){

    long N,R_num=0,G_num=0,B_num=0;
    cin >> N;
    vector<char> S(N);
    for(long i=0;i<N;i++){
        cin >> S[i];
        if(S[i]=='R') R_num++;
        if(S[i]=='G') G_num++;
        if(S[i]=='B') B_num++;
    }
    
    long sub_num=0;
    for(long i=0;i<N;i++){
        for(long j=i+1;j<N;j++){
            if(2*j-i >=N) continue;
            if(S[i]!=S[j] && S[i]!=S[2*j-i] && S[j]!=S[2*j-i])
                sub_num++;
        }
    }
    
    cout << R_num * G_num* B_num - sub_num << endl;
    
    return 0;
 
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int A, B;
  cin >> A >> B;

  if (A == B) {
    cout << A + B << endl;
  } else if (A < B) {
    cout << B + B - 1 << endl;
  } else {
    cout << A + A - 1 << endl;
  }

}

Measured memory_bytes: 256
class RollingHash:
    def __init__(self, s):
        b1, b2 = 1007, 2009
        self.mod1, self.mod2 = 10**9+7, 10**9+9
        self.size = len(s)
        self.string = s

        self.hash1 = self.make_hashtable(b1, self.mod1)
        self.hash2 = self.make_hashtable(b2, self.mod2)
        self.pow1 = self.make_powtable(b1, self.mod1)
        self.pow2 = self.make_powtable(b2, self.mod2)

    def make_hashtable(self, B, MOD):
        hashtable = [0] * (self.size+1)
        for i in range(1, self.size+1):
            hashtable[i] = (hashtable[i-1] * B + ord(self.string[i-1]))%MOD
        return hashtable
    
    def make_powtable(self, B, MOD):
        power = [0] * (self.size+1)
        power[0] = 1
        for i in range(1, self.size+1):
            power[i] = (B * power[i-1])%MOD
        return power

    def get_hash(self, l, length):
        r = length+l-1
        l -= 1
        h1 = (self.hash1[r]-self.hash1[l]*self.pow1[r-l])%self.mod1
        h2 = (self.hash2[r]-self.hash2[l]*self.pow2[r-l])%self.mod2
        return (h1, h2)

from collections import defaultdict

def solve1():
    N = int(input())
    S = input()
    size = len(S)
    hash_table = RollingHash(S)

    ans = 0
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if S[i-1]!=S[j-1]:continue

            left = 1
            right = min(j-i, size-j+1)+1

            while right-left>1:
                m = (left+right)//2
                if hash_table.get_hash(i, m)==hash_table.get_hash(j, m):
                    left = m
                else:
                    right = m
            ans = max(ans, left)

    print(ans)


def solve2():
    N = int(input())
    S = input()
    size = len(S)
    hash_table = RollingHash(S)

    def check(m):
        d = defaultdict(lambda :10**20)
        for i in range(1, size-m+2):
            h = hash_table.get_hash(i, m)
            d[h] = min(d[h], i)
            if (i-d[h])>=m:
                return True
        return False

    left, right = 0, size//2 + 1
    while right-left>1:
        m = (right+left)//2
        if check(m):
            left = m
        else:
            right = m

    print(left)

if __name__ == "__main__":
    # solve1()
    solve2()



Measured memory_bytes: 74780
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		int value = 0;
		for (char c : arr) {
		    if (c == 'S') {
		        value++;
		    } else {
		        value = Math.max(0, value - 1);
		    }
		}
		System.out.println(value * 2);
	}

}


Measured memory_bytes: 26680
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

signed main() {
  ll A;
  cin >> A;

  ll N = 100004;
  vector<ll> sosu(N);
  sosu[0] = -1;
  sosu[1] = -1;

  rep(i, N) {
    if (sosu[i] == -1) {
      continue;
    }
    if (i >= A) {
      COUT(i);
      return 0;
    }
    rep2(j, i + 1, N) {
      if (sosu[j] == -1) {
        continue;
      }
      if (j % i == 0) {
        sosu[j] = -1;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 1024
let rec f ()=
	let (x,y) = Scanf.sscanf(read_line()) "%d %d" (fun x y -> if x < y then (x,y) else (y,x)) 
	in
	if x <> 0 || y <> 0 then (Printf.printf "%d %d\n" x y;f()) else ();;

f ();;



Measured memory_bytes: 4508
import numpy as np

if __name__ == "__main__":
  _n, _k = map(int, input().split())
  h_list = np.array([int(i) for i in input().split()])
  if _n <= _k:
    print("0")
    exit(0)

  h_list = np.sort(h_list)[::-1]
  h_list = h_list[_k:]
  sum = np.sum(h_list)
  print(sum)


Measured memory_bytes: 43256
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 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 (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(long long N, long long X, long long Y) {
  --X;
  --Y;
  vector<ll> a(N);
  rep(sv, N) {
    vector<int> dist(N, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != INF)
        return;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      int d = dist[v];
      if (v - 1 >= 0)
        push(v - 1, d + 1);
      if (v + 1 < N)
        push(v + 1, d + 1);
      if (v == X)
        push(Y, d + 1);
      if (v == Y)
        push(X, d + 1);
    }
    rep(i, N) a[dist[i]]++;
  }
  rep(i, N) a[i] /= 2;
  for (int i = 1; i < N; ++i) {
    ANS(a[i]);
  }
}

// clang-format off
int main() {
  long long N;
  scanf("%lld",&N);
  long long X;
  scanf("%lld",&X);
  long long Y;
  scanf("%lld",&Y);
  solve(N, X, Y);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        scanner.close();

        int result = 0;
        for (int i = 1; i <= N; i++) {
            result += i;
        }

        System.out.println(result);
    }
}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int h, w, a, b; cin >> h >> w >> a >> b;
    rep(i, h) {
        rep(j, w) {
           if((i < b)^(j < a)) cout << '1';
            else cout << '0';
        }
        cout << '\n';
    }
    return 0;
}

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

void maxheap(int* A, int n, int i){
    int l, r, largest;
    l = 2*i;
    r = 2*i + 1;
 
    if( l <= n && A[l] > A[i] ){
        largest = l;
    }else{
        largest = i;
    }
    if( r <= n && A[r] > A[largest] ){
        largest = r;
    }
 
    if( largest != i ){
        swap(A[i], A[largest]);
        maxheap(A, n, largest);
    }
}

int heapExtractMax(int *A, int *nsize){
    int max;
    max=A[1];
    A[1]=A[*nsize];
    *nsize= *nsize-1;
    maxheap(A, *nsize, 1);
    //cout << "nsize " << *nsize << endl;
    return max;
}


int main(){
    int N, K;
    cin >> N >> K;
    int l[N+1];
    int HeapSize=N;
    int tmp,ans;
    ans=0;

    for(int i=1; i<=N; i++){
        cin >> l[i];
    }

    for(int j=N/2; j>=1; j--){
        maxheap(l,N,j);
    }

    for(int i=1; i<=K; i++){
        tmp = heapExtractMax(l,&HeapSize);
        //cout << "i tmp " << i << " " << tmp << endl;
        ans +=tmp;
    }

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

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

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 3e5 + 123;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 9;
const double eps = 1e-9;

inline void boost () {
	ios_base::sync_with_stdio (0);
	cin.tie (0), cout.tie (0);
}
ll n, a[N], sum;

int main () {
	boost ();
	cin >> n;
	n *= 3;
	for (int i = 1;i <= n;i ++) cin >> a[i];
	sort (a + 1, a + n + 1);
	reverse (a + 1, a + n + 1);
	n/=3;
	for (int i = 2;i <= 2 * n;i += 2) sum += a[i];
	cout << sum; 

	return 0;
}

                

Measured memory_bytes: 2560
import itertools
from bisect import bisect_left
A,B,Q=map(int,input().split())
s=[int(input()) for i in range(A)]
t=[int(input()) for i in range(B)]
x=[int(input()) for i in range(Q)]

for i in range(Q):
    bs=bisect_left(s,x[i])
    bt=bisect_left(t,x[i])
    sli=[];bli=[]
    if(bs!=A):
        sli.append(s[bs])
    if(bs!=0):
        sli.append(s[bs-1])
    if(bt!=B):
        bli.append(t[bt])
    if(bt!=0):
        bli.append(t[bt-1])

    res=10**30
    for p in itertools.product(sli,bli):
        if(p[0]<=x[i] and p[1]<=x[i]):
            res=min(res,x[i]-min(p))
        elif(p[0]>=x[i] and p[1]>=x[i]):
            res=min(res,max(p)-x[i])
        else:
            res=min([res,abs(p[1]-x[i])*2+abs(p[0]-x[i]),abs(p[1]-x[i])+abs(p[0]-x[i])*2])
    print(res)

Measured memory_bytes: 88408
import sys
def 解():
    iN,iK = [int(_) for _ in input().split()]
    #aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

    d = {}
    for a,b in [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]:
        if a in d:
            d[a] += b
        else:
            d[a] = b
    iC = 0
    for a in sorted(d.keys()):
        iC += d[a]
        if iK <= iC :
            print(a)
            exit()
解()


Measured memory_bytes: 28204
#include <bits/stdc++.h>
     
    using namespace std;
     
    #define MOD 1000000007
    #define PI 3.1415926535897932384626433832795
    #define INF (int)1e9
    typedef long long int int64;
     
    void print() {
        cout << endl;
    }
     
    void print(string s, bool endline = true) {
        cout << s;
        if (endline) print();
    }
     
    void print(int64 s, bool endline = true) {
        cout << s;
        if (endline) print();
    }
     
    template <typename T, typename T2>
    void print(pair<T, T2>& p, bool endline = true) {
        print("(", false);
        print(p.first, false);
        print(", ", false);
        print(p.second, false);
        print(")", false);
     
        if (endline) print();
    }
     
    template <typename T, typename T2>
    void print(map<T, T2>& m, bool endline = true) {
        print("{");
        for (auto& p : m) {
            print("  ", false);
            print(p);
        }
        print("}");
     
        if (endline) {}
    }
     
    template<typename T>
    void print(vector<T>& v, bool endline = true) {
        print("[", false);
        for (size_t i = 0; i < v.size(); ++i) {
            print(v[i], false);
            if(i != v.size() - 1) print(",", false);
        }
        print("]", false);
     
        if(endline) print();
    }
     
    template <typename T>
    vector<T> operator+(const vector<T> &a, const vector<T> &b)
    {
        vector<T> ret;
        ret.reserve( a.size() + b.size() );                // preallocate memory
        ret.insert( ret.end(), a.begin(), a.end() );        // add A;
        ret.insert( ret.end(), b.begin(), b.end() );        // add B;
     
        return ret;
    }
     
    template <typename T>
    vector<T> &operator+=(vector<T> &a, const vector<T> &b)
    {
        a.reserve( a.size() + b.size() );                // preallocate memory without erase original data
        a.insert( a.end(), b.begin(), b.end() );         // add B;
        return a;
    }

    int main() {
        // g++ -Wall -Wextra -O2 -std=c++17 helloworld.cpp
        int64 n, k;

        cin >> n >> k;

        vector<int64> v(n);
        vector<int64> running_sum(n, 0);

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

        running_sum[0] = v[0];

        for(int i = 1; i < n; ++i) {
            running_sum[i] = running_sum[i-1] + v[i];
        }

        int64 count = 0;
        unordered_map<int64, int64> m;
        m[1] = 1;

        for(int i = 0; i < n; ++i) {
            int64 target = (running_sum[i] - i) % k;
            
            int64 leftmost = i - k;

            if(leftmost >= -1) {
                if (leftmost == -1) {
                    m[1]--;
                } else {
                    int64 remove = (running_sum[leftmost] - leftmost) % k;
                    m[remove]--;
                }
            }

            count += m[target];
            m[target]++;
        }

        print(count);
        return 0;
    }

Measured memory_bytes: 11592
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

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

    int H[N];
    REP(0, i, N) {
        cin >> H[i];
    }

    int cnt = 1;
    int height = H[0];
    REP(1, i, N) {
        if (H[i] >= height) {
            cnt++;
            height = H[i];
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N, Q, year;
    string s = "kogakubu10gokan", tmp;

    cin >> N >> Q;

    for (int i = 0; i < N; ++i) {
        cin >> year >> tmp;

        if (year <= Q)
            s = tmp;
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 1208
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        StringBuilder str = new StringBuilder();
        while (scanner.hasNext()) {
            String s = scanner.nextLine();
            str.append(s.toUpperCase());
        }
        System.out.println(str);
    }
}

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

typedef long long ll;
const int N = 20;

int n, ans, a[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 1; i < n - 1; i++)
		ans += ((a[i] > a[i - 1] && a[i] < a[i + 1]) || (a[i] < a[i - 1] && a[i] > a[i + 1]));
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
s = input()

x, y = 0, 0
for i, p in enumerate(s):
    if p=="a":
        if x < A+B:
            print("Yes")
            x+=1
        else:
            print("No")
    elif p=="b":
        if x < A+B and y < B:
            print("Yes")
            x+=1
            y+=1
        else:
            print("No")
    else:
        print("No")

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



double dp[301][301][301];

double compute(int one, int two, int three,int n )
{
    if(one<0 || two<0 || three<0)
        return 0;
    if((one==0) && (two==0) && (three==0))
        return 0;
    if(dp[one][two][three]>0)
        return dp[one][two][three];

    int re=one+two+three;
    double ans= (n+one*compute(one-1,two,three,n)+two*compute(one+1,two-1,three,n)+three*compute(one,two+1,three-1,n))/re;
    dp[one][two][three]=ans;
    return ans;
}
int main()
{
    int n;
    cin>>n;
    int arr[n];
    int one=0;
    int two=0;
    int three=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i]==1)
            one++;
        else if(arr[i]==2)
            two++;
        else if(arr[i]==3)
            three++;
    }
    memset(dp,-1, sizeof dp);
    cout<<fixed<<setprecision(9)<<compute(one,two,three,n)<<endl;
    return 0;
}


Measured memory_bytes: 216892
#include<stdio.h>

int main(){
    int n, num[100], i = 0, j;
    double w, h, bmi;

    for(j = 0; j < 100; j++) num[j] = 0;

    while(scanf("%d,%lf,%lf", &n, &w, &h) != EOF){
        bmi = h * h;
        bmi = w / bmi;
        if(bmi >= 25){
            num[i] = n;
            i++;
        }
    }
    for(j = 0; j < i; j++) printf("%d\n", num[j]);
    return 0;
}

Measured memory_bytes: 628
#include <stdio.h>
int main (void){
    int x,y;
    scanf("%d %d",&x,&y);
    if(x>y){
        printf("a > b\n");
    }
    else if(x<y){
        printf("a < b\n");
    }
    else if(x==y){
        printf("a == b\n");
    }    
    return 0;
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define rpd(i,a,b) for(register int i=a;i>=b;--i)
#define rep1(i,x) for(register int i=head[x];i;i=nxt[i])
typedef long long ll;
const int N=2000+5;
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,Q;int a[N][N],b[N][N],c[N][N];char ch;
int work(int a[N][N],int i1,int j1,int i2,int j2){
	return a[i2][j2]-a[i1-1][j2]-a[i2][j1-1]+a[i1-1][j1-1];
}
int main(){
	n=read();m=read();Q=read();
	rep(i,1,n)rep(j,1,m){
		cin>>ch;a[i][j]=(ch=='1');
	}
	rep(i,1,n)rep(j,1,m)b[i][j]=a[i][j]&a[i-1][j];
	rep(i,1,n)rep(j,1,m)c[i][j]=a[i][j]&a[i][j-1];
	rep(i,1,n)rep(j,1,m){
		a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
		b[i][j]+=b[i-1][j]+b[i][j-1]-b[i-1][j-1];
		c[i][j]+=c[i-1][j]+c[i][j-1]-c[i-1][j-1];
	}
	while(Q--){
		int i1=read(),j1=read(),i2=read(),j2=read();
		printf("%d\n",work(a,i1,j1,i2,j2)-work(b,i1+1,j1,i2,j2)-work(c,i1,j1+1,i2,j2));
	}
	return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b>> c;
  int d=c-(a-b);
  if(d<=0){
    cout << 0 << endl;
  }else{
    cout << c-(a-b) << endl;
  }
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

constexpr static int MOD = 1000000000 + 7;
constexpr static int inf = INT_MAX / 2;
constexpr static llong INF = 1LL << 31;
constexpr static int dx[] = {1, 0, -1, 0};
constexpr static int dy[] = {0, 1, 0, -1};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}

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

    int n;
    cin >> n;
    cout << 180 * (n - 2) << endl; 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
using namespace std;

int main()
{
   double x1,x2,x3,y1,y2,y3,xp,yp;
    double gaiseki1,gaiseki2,gaiseki3;
 
    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF){
        gaiseki1 = (x2-x1)*(yp-y1)-(y2-y1)*(xp-x1);//全部右or全部左ならok
        gaiseki2 = (x3-x2)*(yp-y2)-(y3-y2)*(xp-x2);
        gaiseki3 = (x1-x3)*(yp-y3)-(y1-y3)*(xp-x3);
 
        if((gaiseki1>0&&gaiseki2>0&&gaiseki3>0) || (gaiseki1<0&&gaiseki2<0&&gaiseki3<0)){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, k ,q;
    scanf("%d %d %d",&n,&k,&q);
    
    int a[q], san[n], aa;
    for(int i=0;i<n;i++) san[i] = 0;
    for(int i=0;i<q;i++){
      scanf("%d",&aa);  
      san[aa-1]++;
    }
    int e, temp;
    for(int i=0;i<n;i++){
        e = k-q;
      
        if(e+san[i] > 0) printf("Yes\n");
        else  printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 1152
from fractions import gcd

n, start  = map(int, (input().split()))
x = list(map(int, (input().split())))
x.append(start)
sorted_x = sorted(x)

ans = sorted_x[1] - sorted_x[0]
for i in range(1, n):
    ans = gcd(ans, sorted_x[i + 1] - sorted_x[i])

print(ans)

Measured memory_bytes: 16244
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;

long long n,q;
long long v,u;
long long del;
int main()
{
	cin>>n>>q;
	del=n-2;
	rep(i,q)
	{
		cin>>v>>u;
if(n==1)
{
if(v>u)cout<<u<<endl;
else cout<<v<<endl;
continue;
}
		v+=del;
		u+=del;
		while(1)
		{
			if(u==v)
			{
				cout<<u-del<<endl;
				break;
			}
			if(u>v)
			{
				u/=n;u+=del;
			}
			else
			{
				v/=n;
				v+=del;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1280
use std::cmp;
use std::collections::*;

pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

mod input{
    use std::io::*;
    static mut BUFFER: String = String::new();

    pub struct Scanner {
        it: std::str::SplitWhitespace<'static>,
    }

    #[allow(dead_code)]
    impl Scanner {
        pub fn new() -> Scanner {
            unsafe {
                stdin().read_to_string(&mut BUFFER).unwrap();
                return Scanner{
                    it: BUFFER.trim().split_whitespace(),
                };
            }
        }
        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            return self.it.next().unwrap().parse::<T>().ok().unwrap();
        }
        pub fn next_string(&mut self) -> Vec<char> {
            let s: String = self.next();
            return s.chars().collect::<Vec<char>>();
        }
        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
            let mut v: Vec<T> = Vec::with_capacity(n);
            for _i in 0..n {
                v.push(self.next());
            }
            v
        }
    }
}

fn lower_bound<T: std::cmp::Ord>(v: &Vec<T>, val: &T) -> usize {
    let mut lb: isize = -1;
    let mut ub: isize = v.len() as isize;
    while ub - lb > 1 {
        let mid = (lb + ub) / 2;
        if *val <= v[mid as usize] {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    return ub as usize;
}

fn dfs(
    u: usize,
    p: usize,
    dp: &mut Vec<i32>,
    ans: &mut Vec<usize>,
    a: &Vec<i32>,
    edge: &Vec<Vec<usize>>,
) {
    let idx = lower_bound(dp, &a[u]);
    let prev = dp[idx];
    dp[idx] = a[u];
    ans[u] = lower_bound(dp, &i32::max_value());

    for v in &edge[u] {
        if *v == p {
            continue;
        }
        dfs(*v, u, dp, ans, a, edge);
    }
    dp[idx] = prev;
}

fn main() {
    let mut scan = input::Scanner::new();
    let n: usize = scan.next();
    let a: Vec<i32> = scan.next_vec(n);
    let mut edge: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..n - 1 {
        let u: usize = scan.next();
        let v: usize = scan.next();
        let (u, v) = (u - 1, v - 1);
        edge[u].push(v);
        edge[v].push(u);
    }
    let mut dp: Vec<i32> = vec![i32::max_value(); n];
    let mut ans: Vec<usize> = vec![0; n];
    dfs(0, 0, &mut dp, &mut ans, &a, &edge);
    for x in ans {
        println!("{}", x);
    }
}


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

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

    int n;
    cin >> n;

    unordered_map<int, int> mp;
    REP(i, n){
        int a;
        cin >> a;
        mp[a]++;
        mp[a-1]++;
        mp[a+1]++;
    }

    int maxi = -1e9;
    for(auto x : mp){
        maxi = max(maxi, x.second);
    }

    cout << maxi << endl;

    return 0;
}

Measured memory_bytes: 4260
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,m=map(int,input().split())
if (n<=1) and (m<=1):
  ans=0
else:
  if n<=1:
    ans=comb(m,2)
  elif m<=1:
    ans=comb(n,2)
  else:
    ans=comb(n,2)+comb(m,2)
  
print(ans)
  

Measured memory_bytes: 9028
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
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;}
/*
void chmin(ll a, ll b){if (a>b){a = b; return true;}return false;}
void chmax(ll a, ll b){if (a<b){a = b; return true;}return false;}
*/

const ll MOD = 1000000007;
const ll INF = 9999999999;

int main() {
  ll N, M, V, P; cin >>N >>M >>V >>P;
  vector<ll> A(N);
  for (ll i=0; i<N; i++){
    cin >>A.at(i);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  // 降順ソート

  ll ans = N;

  ll left = 0, right = N;
  ll x;
  while(right - left > 1){
    x = left + (right - left) / 2;
    if (x <= P-1){
      left = x; continue;
    }else if (A.at(x) + M < A.at(P-1)){
      right = x; continue;
    }
    
    ll sum = M;       // 問題xにM人が入れる
    sum += (P-1) * M; // 問題1,2,...P-1にM人が入れる
    sum += (N-x-1) * M; // 問題x+1,x+2....NにM人が入れる
    for (ll i=P-1; i<x; i++){
      sum += A.at(x)+M - A.at(i);
    }
    if (sum < M*V){
      right = x; continue;
    }else{
      left = x; continue;
    }
  }

  ans = left + 1;

  cout <<ans <<endl;

}

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

int main(){
  int n; cin >> n;
  vector<vector<int>> a(n, vector<int>(n - 1));
  rep(i, n){
    rep(j, n - 1){
      int input; cin >> input;
      input--;
      a[i][j] = input;
    }
    reverse(a[i].begin(), a[i].end());
  }

  vector<P> q;
  auto check = [&](int i){
    if(a[i].size() == 0) return;
    int j = a[i].back();
    if(a[j].size() == 0) return;
    if(a[j].back() == i){
      P p(i, j);
      if(p.second < p.first) swap(p.first, p.second);
      q.push_back(p);
    }
  };

  rep(i, n){
    check(i);
  }

  int day = 0;
  while(q.size() > 0){
    day++;
    sort(q.begin(), q.end());
    q.erase(unique(q.begin(), q.end()), q.end());
    vector<P> prevQ;
    swap(prevQ, q);
    for(P p : prevQ){
      int i = p.first, j = p.second;
      a[i].pop_back();
      a[j].pop_back();
    }
    for(P p : prevQ){
      int i = p.first, j = p.second;
      check(i);
      check(j);
    }
  }

  rep(i, n){
    if(a[i].size() != 0){
      puts("-1");
      return 0;
    }
  }
  cout << day << endl;


  return 0;
}


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

int main(void) {
  int N;    // N問の問題 1<=N<=1000000
  int M;    // 提出した回数 0<=M<=100000

  cin >> N >> M;

  int correctNum = 0;   // ACを一回以上出した問題の数
  int penaltyNum = 0;   // ACする前にWAした数

  // 一つの問題につきACは一度だけ、バケット
  // ACしていなければ、ペアルティを数える
  // 提出回数のループでいけるか
  vector<bool>  v(N + 1, false);  // 1~Nを使う。ACすればtrue
  vector<int> vp(N + 1, false);   // 1~Nを使う。ペナルティのカウント

  int q;
  string result;
  rep(i, M) {
    cin >> q >> result;
    if (!v.at(q)) {
      // まだ、ACしていない問題ならば正解数にカウント
      if (result[0] == 'A') {
        // はじめて正解したならば
        // 正解数カウントと、ペナルティカウント
        // 正解しないとペナルティにならない
        correctNum++;
        penaltyNum += vp.at(q);
        v.at(q) = true;
      } else {
        // 不正解ならば
        vp.at(q)++;
      }
    }
  }

  printf("%d %d\n", correctNum, penaltyNum);

  return 0;
}

Measured memory_bytes: 640