akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL N = 300005;

LL ec = 0,hed[N] = {0},nxt[N << 1],to[N << 1];
void add_edge(LL f,LL t){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
}

LL fa[N],dis[N] = {0},deg[N],vis[N] = {0};
LL a[N],ac = 0,b[N],n;

void dfs(LL u,LL f){
	fa[u] = f; dis[u] = dis[f] + 1;
	deg[u] = 0;
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		deg[u] ++;
		dfs(v,u);
	}
}

LL solve(){
	LL id = 0,ed = 0;
	dfs(1,0); for(LL i = 1;i <= n;i ++) if(dis[i] > dis[id]) id = i;
	dfs(id,0); for(LL i = 1;i <= n;i ++) if(dis[i] > dis[ed]) ed = i;
	deg[ed] = 1;
	while(ed){
		a[++ ac] = ed;
		vis[ed] = 1; ed = fa[ed];
	}
	for(LL i = 1;i <= ac;i ++) b[i] = a[ac + 1 - i];
	for(LL i = 1;i <= n;i ++) if(!vis[i] && deg[i]) return 1;
	for(LL i = 1;i <= ac;i ++) a[i] = deg[a[i]],b[i] = deg[b[i]];
	return 0;
}

LL comp(){
	for(LL i = 1;i <= n;i ++){
		if(a[i] > b[i]) return 1;
		if(a[i] < b[i]) return -1;
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(false);
	LL u,v;
	cin >> n;
	for(LL i = 1;i < n;i ++){
		cin >> u >> v;
		add_edge(u,v);
		add_edge(v,u);
	}
	if(solve()){ cout << -1 << '\n'; return 0; }
	if(comp() == 1) swap(a,b);
    LL now = 1;
	for(LL i = 1;i <= ac;i ++){
		for(LL j = 1;j < a[i];j ++) cout << now + j << ' ';
		cout << now << ' '; now += a[i];
	} cout << '\n';
	return 0;
}

Measured memory_bytes: 23168
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
ll fact[200001], mod = 998244353;
ll power(ll x, ll y) {
	ll ans = 1;
	while(y) {
		if(y & 1) {
			ans = (ans * x) % mod;
		}
		y /= 2;
		x = (x * x) % mod;
	}
	return ans;
}
ll modinverse(ll x) {
	return power(x, mod - 2);
}

ll comb(ll n, ll r) {
	return ((fact[n] * modinverse(fact[r]))%mod * modinverse(fact[n-r]))%mod;
}
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m, k, i, ans = 0;
    cin>>n>>m>>k;
    fact[0] = fact[1] = 1;
    for(i = 2; i < 200001; i++) {
    	fact[i] = (fact[i-1] * i) % mod;
    }
    for(i = n - 1 - k; i < n; i++) {
    	ans = (ans + (((comb(n-1, i) * m) % mod) * power(m-1, i))%mod)%mod; 
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 5212
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;
const int MOD = 1000000007;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)


//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    int N, T; cin >> N >> T;
    vector<int> D(N);
    for(int i=0; i<N; i++)
        cin >> D[i];
    sort(D.begin(), D.end());
    
    ll ans = 1;
    for(int i=0; i<N; i++)
        ans = ans * (D.begin()+i+1-lower_bound(D.begin(), D.begin()+i, D[i]-T)) % MOD;
   
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1524
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s1,s2;
    cin >> s1 >> s2;
    reverse(s1.begin(), s1.end());
    if(s1 == s2){
        print("YES");
    }else{
        print("NO");
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007LL
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    rep(i, sz(v)) cout << v[i] << ",";
    cout << "]";
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N, K;
int H[100000];
int dp[100000];
int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N >> K;
    rep(i, N) cin >> H[i];

    dp[0] = 0;
    repp(i, 1, N) {
        dp[i] = INF;
        repp(j, max(0, i-K), i) {
            get_min(dp[i], dp[j]+abs(H[i]-H[j]));
        }
    }
    cout << dp[N-1] << endl;
}

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

int main() {
  int A, B, C, X, Y;
  long long Min=1000000000;
  cin >> A >> B >> C >> X >> Y;
  rep(i, 2*max(X,Y)) if(Min>=C*2*i+A*max(0,X-i)+B*max(0,Y-i)) Min=C*2*i+A*max(0,X-i)+B*max(0,Y-i);
  cout << Min << endl;
}

Measured memory_bytes: 256
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

def resolve():
    N,K,Q=pin()
    ar=[0]*N
    for i in range(Q):
        t,=pin()
        ar[t-1]+=1
    #print(ar)
    for a in ar:
        if a>Q-K:
            print("Yes")
        else:print("No")
            
        
#%%submit!    
resolve()

Measured memory_bytes: 47324
/**
*    created: 26.06.2020 17:15:30
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcount(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

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

    int n;
    cin >> n;
    int ans = 0;
    rep2(i,1,n+1) {
        int cnt = 0;
        for (int j = 1; j * j <= i; j++) {
            if (i % j == 0) cnt += 2;
            if (j * j == i) cnt--;
        }
        if (i % 2 == 1 && cnt == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll dp[3007][3007];

int main(){
  string S,T;
  cin >> S >> T;
  Rep(i,1,S.size()+1){
    Rep(j,1,T.size()+1){
      if(S[i-1]==T[j-1]){
        dp[i][j]=dp[i-1][j-1]+1;
      }
      else{
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      }
    }
  }
  string K;
  ll i=S.size(),j=T.size();
  while(i!=0 && j!=0){
    if(dp[i][j]==dp[i-1][j]+1 && dp[i][j]==dp[i][j-1]+1){
      K.pb(S[i-1]);
      i--;
      j--;
    }
    else if(dp[i][j]==dp[i-1][j]+1 && dp[i][j]!=dp[i][j-1]+1){
      j--;
    }
    else{
      i--;
    }
  }
  reverse(ALL(K));
  cout << K << endl;
}

Measured memory_bytes: 70784
#include <stdio.h>
int main(void) {
	while(1){
		long long int n;
		scanf("%lld",&n);
		if(n==0) break;
		long long int j,id[n],m1[n],s1[n],m2[n],s2[n],m3[n],s3[n],m4[n],s4[n];
		for(j=0;j<n;j++){
			scanf("%lld %lld %lld %lld %lld %lld %lld %lld %lld",&id[j],&m1[j],&s1[j],&m2[j],&s2[j],&m3[j],&s3[j],&m4[j],&s4[j]);
		}
		long long int ss1[n],ss2[n],ss3[n],ss4[n],s5[n];
		for(j=0;j<n;j++){
			ss1[j]=(m1[j]*60)+s1[j];
			ss2[j]=(m2[j]*60)+s2[j];
			ss3[j]=(m3[j]*60)+s3[j];
			ss4[j]=(m4[j]*60)+s4[j];
			s5[j]=ss1[j]+ss2[j]+ss3[j]+ss4[j];
		}
		long long int k,tmp,tmp1;
		for(k=n-1;k>0;k--){
			for(j=0;j<k;j++){
				if(s5[j]>s5[j+1]){
					tmp=s5[j];
					tmp1=id[j];
					s5[j]=s5[j+1];
					id[j]=id[j+1];
					s5[j+1]=tmp;
					id[j+1]=tmp1;
				}
			}
		}
		printf("%lld\n",id[0]);
		printf("%lld\n",id[1]);
		printf("%lld\n",id[n-2]);
	}
	return 0;
}


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

typedef long long ll;

int main()
{
    ll M,N;
    cin>>M>>N;
    if(M==1 && N==1){
        cout<<1<<endl;
    }
    else if(M==1 || N==1){
        cout<< max(M,N)-2<<endl;
    }
    else{
        cout<<(M-2)*(N-2)<<endl;
    }
    return 0;
}


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

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<i64> ans(N + 1);
  for (i64 x = 1; x * x <= N; ++x) {
    for (i64 y = 1; x * x + y * y + x * y <= N; ++y) {
      for (i64 z = 1;; ++z) {
        i64 s = x * x + y * y + z * z + x * y + y * z + z * x;
        if (s > N) break;
        ans[s]++;
      }
    }
  }
  for (int i = 1; i <= N; ++i) {
    cout << ans[i] << '\n';
  }
}

Measured memory_bytes: 3636
# import sys
# input = sys.stdin.readline
# n = int(input())
# a = [int(input()) for _ in range(n)]
#
# max_i = 0
# max_num = 0
# for i in range(n):
#     if a[i] > max_num:
#         max_num = a[i]
#         max_i = i
#
# a.sort(reverse=True)
#
# for i in range(n):
#     if i != max_i:
#         print(max_num)
#     else:
#         print(a[1])

n,*a=map(int,open(0).read().split())
ma=max(a)
# 最大値のインデックスを取得
ma_index=a.index(ma)
for i in range(n):
    if i==ma_index:
        # 最大値を除いた配列の最大値を出力
        print(max(a[:i]+a[i+1:]))
    else:
        print(ma)

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

int main() {
    int n;
    int t;
    int s1 = 0;
    int s2 = 0;
    int sprev = 0;
    int ans;

    cin >> n;

    int w[n];

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

    for(int i = 0; i < n; i++) {
        s2 += w[i];
    }

    for(int i = 0; i < n; i++) {
          s2 -= w[i];
          s1 += w[i];
        if (s2 <= s1 &&  abs(s2 - s1) < sprev) {
          ans = abs(s2 - s1);
          break;
        }
        if (s2 <= s1 &&  abs(s2 - s1) > sprev) {
          ans = sprev;
          break;
        }
        sprev = abs(s2- s1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void){
	int R[200000];
	int n, i, j;
	int max = -999999999;
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &R[i]);
	}
	int min = R[0];
	for(j=1;j<n;j++){
		if(R[j]-min>max)
			max = R[j]-min;
		if(min > R[j])
			min = R[j];
	}
	printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
//#include <cstdio>
//#include <algorithm>
//#include <cmath>
//#include <cstring>
//#include <iostream>
using namespace std;
typedef long long ll;
const int maxx=2e5+100;
const int INF=1e9;
const int MOD=1e9+7;
char s[maxx];
 
int main()
{
    cin>>s;
    for(int i=0; i<strlen(s); i++){
        if(i%2==0)
            cout<<s[i];
    }
    cout<<endl;
    return 0;
}
 

Measured memory_bytes: 384
n = gets.to_i
flower = gets.split().map(&:to_i)
flower.push(0)
n = n * 1
ans = 0
max = 0
min = 0
flower.each do |f|
  if f > max
    max = f
  elsif f < max
    ans += max - min
    min = f
    max = f
  end
end
puts ans

Measured memory_bytes: 1788
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
int cmp3(T lhs, T rhs) { return (lhs == rhs) ? 0 : (lhs > rhs) ? 1 : -1; }

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

void solve(int n, int k, vector<lli> const &hs) {
  vector<lli> dp(n+100, infty<lli>);
  dp[n-1] = 0;
  RREP(i, n-1) FOR(j, 1, k) {
    if (i + j >= n) { continue; }
    chmin(dp[i], abs(hs[i+j]-hs[i]) + dp[i+j]);
  }
  cout << dp[0] << endl;
}

int main() {
  int N, K; cin >> N >> K;
  vector<lli> hs;
  REP(i, N) {
    lli H;
    cin >> H;
    hs.push_back(H);
  }
  solve(N, K, hs);
  return 0;
}


Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll, ll> pii;
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 1e18;
const ll mod = 1000000007;
int n, k;
int a[maxn];
int ans;
int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int tmp = 0;
	for (int i = 1; i <= k; i++)tmp += a[i];
	ans = tmp;
	for (int i = k + 1; i <= n; i++) {
		tmp = tmp - a[i - k] + a[i];
		ans = max(ans, tmp);
	}
	printf("%.12f\n", 0.5*(ans + k));
	return 0;
};

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

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

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

  CIN(A, B, C, X);
  int ans = 0;
  REP(ai, A + 1) {
    if (ai * 500 > X) continue;
    REP(bi, B + 1) {
      int tmp = X - ai * 500 - bi * 100;
      if (tmp >= 0 && tmp % 50 == 0 && tmp / 50 <= C) {
	ans++;
	continue;
      }
    }
  }

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



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

struct pos{
  int x;
  int y;
};

int main(){
  int n, n1, d1;
  int left, right, up, down;
  pos setpos;
  vector<pos> position;
  vector<pos>::iterator posit;

  while(1){
    cin >> n;
    if(n == 0) break;
    
    //初期化
    left = 0;
    right = 0;
    up = 0;
    down = 0;
    setpos.x = 0;
    setpos.y = 0;
    position.clear();
    position.push_back(setpos);

    //入力
    for(int i = 1; i < n; i++){
      cin >> n1 >> d1;
      posit = position.begin() + n1;
      if(d1 == 0){
	setpos.x = (*posit).x -1;
	setpos.y = (*posit).y;
	if(setpos.x < left) left = setpos.x;
	position.push_back(setpos);
      }else if(d1 == 1){
	setpos.x = (*posit).x;
	setpos.y = (*posit).y -1;
	if(setpos.y < down) down = setpos.y;
	position.push_back(setpos);
      }else if(d1 == 2){
	setpos.x = (*posit).x +1;
	setpos.y = (*posit).y;
	if(right < setpos.x) right = setpos.x;
	position.push_back(setpos);
      }else{
	setpos.x = (*posit).x;
	setpos.y = (*posit).y +1;
	if(up < setpos.y) up = setpos.y;
	position.push_back(setpos);
      }
    }

    //表示
    int maxwidth, maxheight;
    left *= -1;
    down *= -1;
    maxwidth = left + right + 1;
    maxheight = up + down + 1;
    cout << maxwidth << " " <<  maxheight << endl;

  }

  return 0;
}

Measured memory_bytes: 1220
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int calc(int X, int Cx, int Y, int Cy) {
    return abs(X - Cx) + abs(Y - Cy);
}
 
int x[1010], y[1010], h[1010];
signed main() {
    int N; cin >> N;
    for(int i=0; i<N; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }

    for(int Cx=0; Cx<=100; Cx++) {
        for(int Cy=0; Cy<=100; Cy++) {
            int ub = INF;
            set<int> S;
            for(int i=0; i<N; i++) {
                int cand = calc(x[i], Cx, y[i], Cy);
                // if(Cx == 2 and Cy == 2) fprintf(stderr, "cand = %lld\n", cand);
                if(h[i] == 0) {
                    chmin(ub, cand);
                }
                else {
                    S.insert(h[i] + cand);
                }
            }

            bool ok = true;
            for(auto cand : S) {
                ok &= (ub >= cand);
            }
            ok &= (S.size() < 2);

            if(ok) {
                int height = ub;
                if(S.size()) chmin(height, *(S.begin()));
                cout << Cx << " " << Cy << " " << height << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
program main
  implicit none
  integer :: n, i
  integer, allocatable :: a(:)
  real(8), allocatable :: ar(:)
  read (*, *) n
  allocate (a(n), ar(n))
  read (*, *) a(:)
  ar(:) = 1.0 / dble(a(:))
  write (*, *) 1.0 / sum(ar)
end program main



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin>>s;
    if(s=="ABC") cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
	#define dbg(x) cout << #x << " : " << x << endl;
#else 
	#define dbg(x)
#endif

#define int long long
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


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

 	int n, m, k;

int x[MX];
int used[MX];
vpii g[MX];
int w = -1;

vi comp;
void no() {
	cout << "No\n";
 	exit(0);
}

void yes() {
	cout << "Yes\n";
	exit(0);
}

void dfs(int v, int s = 0) {
	comp.pb(v);
	used[v] = 1;
	x[v] = s;
	fx(kek, g[v]) {
		int to = kek.first;
		int c = kek.second;
		if (used[to]) {
			int val2 = -s + c;
			if (x[to] != val2)
				no();
		} else {
			dfs(to, -s + c);
		}
	}
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   	
 	cin >> n >> m >> k;
 	rep(it, 0, k) {
 		int i, j, c;
 		cin >> i >> j >> c;
 		--i;
 		--j;
 		
		j += n;
		g[i].pb({j, c});
		g[j].pb({i, c});
 	}
 	fi(0, n + m) {
 		if (!used[i]) {
 			comp.clear();
 			dfs(i);
 			int l = -BIG;
 			int r = BIG;
 			fx(v, comp) {
 				if (v < n) {
 					maxe(l, -x[v]);
 				}  else {
 					mine(r, x[v]);
 				}
 			}
 			if (r < l) {
 				no();
 			}
 		}
 	}
 	yes();
} 

Measured memory_bytes: 23600
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int h, w, dx[] = {0, 0, -1, 1}, dy[] = {1, -1, 0, 0};
long long a, b, ans;
char s[405][405], t;

void dfs(int x, int y) {
    char t = s[x][y];
    if (t == '#') {
        a++;
    } else {
        b++;
    }
    // 同じマスを重複してカウントしないようにする
    s[x][y] = 0;
    for (int i = 0; i < 4; i++) {
        char u = s[x + dx[i]][y + dy[i]];
        // まだ通っていないマス＆次マスの色が異なる
        if (u > 0 && t != u) {
            dfs(x + dx[i], y + dy[i]);
        }
    }
}

int main() {
    cin >> h >> w;
    for (int i = 1; i <= h; i++) {
        cin >> s[i] + 1;
        s[i][w + 1] = 0;
    }
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (s[i][j]) {
                a = b = 0;
                dfs(i, j);
                ans += a * b;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  ll W, H, x, y;
  cin >> W >> H >> x >> y;

  bool f = 2 * x == W && 2 * y == H;
  cout << setprecision(20) << (double)W * (double)H / 2.0 << " " << (int)f
       << endl;

  return 0;
}


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

using namespace std;

int main(){
  int n,m,k,h,i,c=0,j,b[40]={};
  cin>>n>>m;
  for(i=0;i<n;i++){
    cin>>k;
    for(j=0;j<k;j++){
      cin>>h;
      b[h]++;
    }
  }
  for(i=1;i<=m;i++){
    if(b[i]==n) c++;
  }
  cout<<c<<endl;
  return 0;
}


Measured memory_bytes: 256
class union_find:
  par = []
  def __init__(self,n):
    self.par = [-1]*n

  def root(self,k):
    if self.par[k] < 0:
      return k
    self.par[k] = self.root(self.par[k])
    return self.par[k]

  def size(self,k):
    k = self.root(k)
    return -self.par[k]

  def unite(self,u,v):
    u = self.root(u)
    v = self.root(v)
    if u==v:
      return
    if self.size(u)<self.size(v):
      u,v = v,u
    self.par[u] += self.par[v]
    self.par[v] = u

def main():
  n,m = map(int,input().split())
  uni = union_find(n+1)
  for _ in range(m):
    ai,bi = map(int,input().split())
    uni.unite(ai,bi)
  ans = max(uni.size(v)for v in range(1,n+1))
  print(ans)

main()

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

// return gcd(a,b)
long long gcd(long long a, long long b) {
    // O(log min(a,b))
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

// return the answer of "ax + by = gcd(a,b)"
long long extend_gcd(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    } else {
        long long d = extend_gcd(b, a % b, y, x);
        y -= a / b * x;
        return d;
    }
}

int main() {
    long long x, y;
    cin >> x >> y;
    long long ans = x * y / gcd(x, y);
    cout << ans << endl;
    return 0;
}


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

int main()
{
int i;
int X;
int Y;
int Z;
int iSum;
int iMin;

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

	iSum = 0;
	iMin = 0;
	for( i = 0; i < 5; i++ )
	{
		cin >> X;

		Y = X % 10;
		Z = X / 10;
		if( Y > 0 ) Z++;
		if( iMin == 0 || ( Y > 0 && iMin > Y ) ) iMin = Y;

		iSum += Z;
	}

	if( iMin == 0 )
		cout << iSum * 10 << endl;
	else
	{
		iSum--;
		cout << iSum * 10 + iMin << endl;
	}

	return 0;
}


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

int main() {
	int c[3][3];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>c[i][j];
		}
	}
	int flag=0;
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			for(int k=0;k<=100;k++){
				int flag2=1;
				for(int n=0;n<3;n++){
					if(((c[0][n]-i)==(c[1][n]-j))*((c[1][n]-j)==(c[2][n]-k))){
					}else{
						flag2=0;
					}
				}
				if(flag2){
					flag=1;
				}

			}
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

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

a = [0]
b = [0]
for i in range(N):
    a.append(a[i] + A[i])

for i in range(M):
    b.append(b[i] + B[i])


count = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    count = max(count, i+j)

print(count)





Measured memory_bytes: 47476
#include <cstdio>
#include <utility>
#include <tuple>
#include <vector>
#include <algorithm>
#include <iostream>
using ll = long long int;
using namespace std;
int main() {
    ll N, L; scanf("%lld%lld", &N, &L);

    vector< pair<int, int> > rooks;
    for(int i=0; i<N; i++) {
        int p, d; scanf("%d%d", &p, &d);
        rooks.emplace_back(p, d);
    }
    sort(rooks.begin(), rooks.end());

    vector<ll> S1(N+2), S2(N+2);
    for(int i=0; i<N; i++) {
        ll d = rooks[i].first - (i + 1);
        ll r = rooks[i].second;
        if(d > 0) {
            if(r == 0) S1[i+1] = S1[i] + d;
            if(r == 1) S1[i+1] = S1[i] - d;
        }
        else {
            d = -d;
            if(r == 0) S1[i+1] = S1[i] - d;
            if(r == 1) S1[i+1] = S1[i] + d;
        }
    }
    for(int i=N-1; i>=0; i--) {
        ll d = rooks[i].first - (L - (N - 1 - i));
        // fprintf(stderr, "i = %d, d = %lld\n", i, d);
        ll r = rooks[i].second;
        if(d > 0) {
            if(r == 0) S2[i+1] = S2[i+2] + d;
            if(r == 1) S2[i+1] = S2[i+2] - d;
        }
        else {
            d = -d;
            if(r == 0) S2[i+1] = S2[i+2] - d;
            if(r == 1) S2[i+1] = S2[i+2] + d;
        }
    }

    ll ans = 0;
    for(int i=0; i<=N; i++) {
        // fprintf(stderr, "S1[%d] = %lld, S2[%d] = %lld\n", i, S1[i], i+1, S2[i+1]);
        ans = max(ans, S1[i] + S2[i+1]);
    }
    printf("%lld\n", ans);
    
    /*
    rooks.emplace_back(0, 0);
    rooks.emplace_back(L+1, 1);
    sort(rooks.begin(), rooks.end());

    vector< pair< int, vector<int> > > rle;
    for(size_t i=0; i<rooks.size(); i++) {
        int p, d; tie(p, d) = rooks[i];
        if(rle.empty() or rle.back().first != d) {
            rle.emplace_back(d, vector<int>(1, p));
        }
        else rle.back().second.emplace_back(p);
    }

    for(auto e : rle) {
        auto v = e.second;
        for(auto x : v) cerr << x << " ";
        cerr << endl;
    }
    
    ll ans = 0;
    for(size_t i=0; i<rle.size(); i++) {
        int d = rle[i].first;
        if(d == 0) {
            int p = rle[i].second.front();
            for(size_t j=0; j<rle[i].second.size(); j++) {
                int t = p + j;
                ans += rle[i].second[j] - t;
            }
        }
        if(d == 1) {
            int p = rle[i].second.back();
            int M = rle[i].second.size();
            for(size_t j=0; j<rle[i].second.size(); j++) {
                int t = p - j;
                ans += t - rle[i].second[M-1-j];
            }
        }
    }
    
    // RL RL ...
    for(size_t i=1; i+1<rle.size(); i+=2) {
        ll r = rle[i].second.back();
        ll l = rle[i+1].second.front();
        ans += (l - r - 1) * max(rle[i].second.size(),
                                 rle[i+1].second.size());
    }

    printf("%lld\n", ans);
    */
    return 0;
}



Measured memory_bytes: 5096
N = int(input())
*A, = map(int, input().split())

for i in range(N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)


Measured memory_bytes: 5980
a, b, c, x, y = map(int, input().split())

ans = x * a + y * b
if a + b > 2 * c:
    if x < y:
        ans = min(ans, 2 * c * x + b * (y - x))
    else:
        ans = min(ans, 2 * c * y + a * (x - y))
    ans = min(ans, 2 * c * max(x, y))
    
print(ans)

Measured memory_bytes: 3064
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int N; std::cin >> N;
    long long pmx(-LINF), pmn(LINF), mmx(-LINF), mmn(LINF);
    {
        int x, y;
        for(int i(0); i < N; ++i){
            std::cin >> x >> y;
            chmax(pmx, x + y);
            chmax(mmx, x - y);
            chmin(pmn, x + y);
            chmin(mmn, x - y);
        }
    }
    std::cout << std::max(pmx - pmn, mmx - mmn) << std::endl;
    return 0;
}


Measured memory_bytes: 3600
def comb1(n, r):
    if n == 0 or r == 0: return 1
    return comb1(n, r-1) * (n-r+1) / r 
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
# N, M = 10, 400000000
# A = [int(i) for i in '1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000'.split()]
surplus = {0:0}
res = 0
tmp = 0
B = []
for i in range(0, N):
    tmp += A[i]
    tmp %= M
    B.append(tmp)
    surplus[tmp] = 0
for i in B:
    surplus[i] += 1

for tmp_key in surplus.keys():
    res += comb1(surplus[tmp_key], 2)

corner = surplus[0]
if corner == 0:
    res -= 1
else:
    res += corner
print(int(res))

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]= {-1,0,1,-1,1,-1,0,1};
//int dy[]= {1,1,1,0,0,-1,-1,-1};




int n;
bool visited[10];
pair<double,double>a[10];
double sum,ans,cnt,dis[10][10];

double find_dis(int x,int y)
{
    return sqrt(((a[x].FI-a[y].FI)*(a[x].FI-a[y].FI)) + ((a[x].SE-a[y].SE)*(a[x].SE-a[y].SE)));
}

void find_ans(int cur)
{
    if(cur > n)
    {
        ans+=sum;
        ++cnt;
        return;
    }
    int i;
    for(i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            visited[i]=true;
            sum+=dis[cur][i];
            find_ans(cur+1);
            sum-=dis[cur][i];
            visited[i]=false;
        }
    }
}

int main()
{
    FAST();

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

    int i,j;
    cin >> n;
    for(i=1;i<=n;i++)cin >> a[i].FI >> a[i].SE;
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            dis[i][j]=dis[j][i]=find_dis(i,j);
        }
    }
    find_ans(1);
    cout << fixed << setprecision(10) << ans/(double)cnt;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    int N,K;
    GI(N);GI(K);
    vector<int> A(N);
    REP(i,N)GI(A[i]);
    int pos1;
    REP(i,N)
        if(A[i] == 1)
            pos1=i;

    int ans = IMAX;
    for(int r=max(pos1,K-1);r<min(pos1+K,N);r++){
        int res = 1;
        int l = r - K + 1;
        if(0 < l)
            res += (l+K-2)/(K-1);
        if(r<N-1)
            res += (N-r-1+K-2)/(K-1);
        ans = min(ans,res);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
const int N=1e5+5;
typedef std::pair<int,int> P;
std::vector<P> g;
P stk[N];int top,r,c,n;
int change(int x,int y) {
    if(y==0) return x;
    else if(x==r) return y+x;
    else if(y==c) return r+c+r-x;
    else return 2*(r+c)-y;
}
bool check(int x,int y) {
    return x==0||x==r||y==0||y==c;
}
int main() {
    scanf("%d%d%d",&r,&c,&n);
    int x1,y1,x2,y2,l,r;
    while(n--) {
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        if(!check(x1,y1)||!check(x2,y2)) continue;
        l=change(x1,y1),r=change(x2,y2);
        if(l>r) std::swap(l,r);
        g.push_back(P(l,r));
    }
    std::sort(g.begin(),g.end());
    top=0;bool f=true;
    for(P &v:g) {
        while(top&&v.second>stk[top-1].second) {
            if(v.first<stk[top-1].second) {
                f=false;break;
            }
            --top;
        }
        stk[top++]=v;
        if(!f) break;
    }
    printf("%s\n",f?"YES":"NO");
    return 0;
}


Measured memory_bytes: 1524
from collections import Counter
N=int(input())

alpha2num = lambda c: ord(c) - ord('a')

S_num_list=[]

for n in range(N):
    S_=input()
    S_num=[0]*26
    for s in S_:
        S_num[alpha2num(s)] += 1
    S_num_list.append(''.join(map(str,S_num)))
    
S_counter=Counter(S_num_list)

ans=0
for s in S_counter.keys():
    s_num = S_counter[s]
    s_combination_num = int((s_num*(s_num-1))/2)
    ans += s_combination_num
print(ans)

Measured memory_bytes: 25816
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rev(a) reverse(all(a))
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main() {
    int t;
    cin >> t;
    map<string,int> m;
    while(t--){
        string s;
        cin >>s ;
        m[s]++;
    }
    int mx=0;
    for(auto i : m){
        mx=max(mx,i.ss);
    }
    for(auto i : m){
        if(i.ss==mx){
            cout << i.ff << endl;
        }
    }
	return 0;
}

Measured memory_bytes: 25216
package main

import (
	"fmt"
	"math"
)

const MAX = 200 * 100 * 2 + 1

var maxv [MAX]float64

func main() {
	// input data
	n := 0
	fmt.Scan(&n)
	//
	t := make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&t[i])
	}
	//
	v := make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&v[i])
	}

	// velocity limit set to maxv
	tdx := 1
	vdx := 0
	maxv[0] = 0
	for _, tm := range t {
		if maxv[tdx-1] > v[vdx] { // overlap point
			maxv[tdx-1] = v[vdx]
		}
		for i := 0; i < int(tm); i++ {
			maxv[tdx] = v[vdx]
			maxv[tdx+1] = v[vdx]
			tdx += 2
		}
		vdx += 1
	}

	endp := tdx - 1
	maxv[endp] = 0

	// scan from start to end
	for i := 1; i <= endp; i++ {
		maxv[i] = math.Min(maxv[i], maxv[i-1]+0.5)
	}

	// scan from end to start
	for i := endp - 1; i >= 0; i-- {
		maxv[i] = math.Min(maxv[i], maxv[i+1]+0.5)
	}

	//for debug
	//fmt.Println(t, v)
	//for i:=0; i < tdx; i++ {
	//  fmt.Println(i, maxv[i])
	//}
	
	// calc area
	area := float64(0)
	for i := 0; i < endp; i++ {
		area += maxv[i] + maxv[i+1]
	}

	fmt.Printf("%f\n", 0.25*area)
}

Measured memory_bytes: 896
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;

fn main() {
    let n: usize = read();
    let mut s: Vec<Vec<char>> = vec![vec![]; n];

    let mut map: HashMap<Vec<char>, i64> = HashMap::new();
    for i in 0..n {
        s[i] = read::<String>().chars().collect();
        s[i].sort();
        let count = map.entry(s[i].clone()).or_insert(0);
        *count += 1;
    }

    let mut ans = 0;
    for (_, i) in &map {
        ans += i * (i-1) / 2;
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

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

start = 0
ind = 0
NG = [0]*(2*N+1)

bdic = {}
for i, b in enumerate(B):
    if not b in bdic:
        bdic[b] = [i, i]
    else:
        bdic[b] = [min(bdic[b][0], i), max(bdic[b][1], i)]


for i, a in enumerate(A):
    if a in bdic:
        j1, j2 = bdic[a]
        if j1 >= i:
            NG[j1-i] += 1
            NG[j2-i+1] -= 1
        elif j2 < i:
            NG[j1-i+N] += 1
            NG[j2-i+1+N] -= 1
        else:
            NG[j1-i+N] += 1
            NG[0] += 1
            NG[j2-i+1] -= 1

start = -1
for i in range(N):
    if NG[i] == 0:
        start = i
        break
    NG[i+1] += NG[i]

if start == -1:
    print("No")
else:
    print("Yes")
    ans = []
    for i in range(N):
        ans.append(B[(i+start)%N])
    print(*ans)

Measured memory_bytes: 146540
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	vector<long long int>s;
	map<long long int, long long int>mp;
	for (int i = 0; i < n; i++) {
		long long int a;
		cin >> a;
		s.push_back(a);
		mp[a]++;
	}
	long long int ans = 0;
	for (auto iter = mp.begin(); iter != mp.end(); iter++) {
		ans = ans + (iter->second) * (iter->second - 1) / 2;
	}
	for (int i = 0; i < n; i++) {
		cout << ans - mp[s[i]] * (mp[s[i]] - 1) / 2 + (mp[s[i]] - 1) * (mp[s[i]] - 2) / 2<<endl;
	}
}

Measured memory_bytes: 11888