akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    int p = 0;
    for(int i=0; i<n; i++){
        if(x[i] == '1') p += 1;
    }

    if(p == 0){
        cout << 1 << endl;
        return 0;
    }

    vector<int> pow2a(n), pow2b(n);// pow2[i] = 2^i
    pow2a[0] = 1;
    pow2b[0] = 1;
    for(int i=0; i+1<n; i++){
        if(p != 1){
            pow2a[i+1] = pow2a[i] * 2;
            pow2a[i+1] %= (p-1);
        }
        pow2b[i+1] = pow2b[i] * 2;
        pow2b[i+1] %= (p+1);
    }

    int na = 0, nb = 0;
    for(int i=0; i<n; i++){
        if(x[i] == '1'){
            if(p != 1){
                na += pow2a[n-1-i];
                na %= (p-1);
            }
            nb += pow2b[n-1-i];
            nb %= (p+1);
        }
    }

    vector<int> ans(3*1e5);
    ans[0] = 0;
    for(int i=1; i<3*1e5; i++){
        ans[i] = ans[i % __builtin_popcount(i)] + 1;
    }

    for(int i=0;i<n; i++){
        int flipped, mod;
        if(p == 1 && x[i] == '1'){
            cout << 0 << endl;
            continue;
        }
        else if(x[i] == '1'){
            flipped = na - pow2a[n-1-i];
            mod = p-1;
        }
        else if(x[i] == '0'){
            flipped = nb + pow2b[n-1-i];
            mod = p+1;
        }
        flipped = (flipped % mod + mod) % mod;
        //cout << flipped << " " << mod << " : ";
        cout << ans[flipped] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 6296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N, vector<int>());
    vector<vector<int>> par(N, vector<int>());
    vector<int> out(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].pb(b);
        out[a]++;
        par[b].pb(a);
    }
    vector<bool> close(N, 1);
    queue<int> que;
    rep(i, N) if(out[i] == 0) que.push(i);
    while(!que.empty()) {
        auto v = que.front();
        que.pop();
        close[v] = false;
        for(auto p : par[v]) {
            out[p]--;
            if(out[p] == 0)
                que.push(p);
        }
    }
    int from = -1, end = -1;
    rep(i, N) if(close[i]) { from = i; }
    if(from == -1) {
        cout << -1 << endl;
        return 0;
    }
    end = from;
    vector<int> used(N);
    queue<int> que2;
    vector<int> cycle;
    while(1) {
        if(used[end]) {
            while(que2.front() != end)
                que2.pop();
            break;
        }
        que2.push(end);
        used[end] = 1;
        for(auto nv : G[end]) {
            if(!close[nv])
                continue;
            end = nv;
            break;
        }
    }
    while(!que2.empty()) {
        cycle.pb(que2.front());
        que2.pop();
    }
    while(1) {
        vector<int> ord(N, -1);
        vector<int> cycle2;

        for(int i = 0; i < cycle.size(); i++)
            ord[cycle[i]] = i;
        bool find = 0;
        for(int i = 0; i < cycle.size(); i++) {
            for(auto nv : G[cycle[i]]) {
                if(nv != cycle[(i + 1) % cycle.size()] && ord[nv] != -1) {
                    cycle2.pb(cycle[i]);
                    cycle2.pb(nv);
                    find = 1;
                    break;
                }
            }
            if(find)
                break;
        }
        if(!find)
            break;
        int v = cycle2[1];
        while(1) {
            v = cycle[(ord[v] + 1) % cycle.size()];
            if(v == cycle2[0])
                break;
            else
                cycle2.pb(v);
        }
        cycle = cycle2;
    }
    cout << cycle.size() << endl;
    for(auto v : cycle)
        cout << v + 1 << endl;
}

Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate など
#include <stdexcept>
#include <cassert> // assert
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

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

// constexpr inline ll MOD = 1'000'000'007;

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s,t;
    cin >> s>>t;
    bool ok = true;
    REP(i, s.size()){
        ok &= (s[i] == t[i]);
    }
    cout <<(ok?"Yes":"No")<<endl;

    return 0;
}


Measured memory_bytes: 3644
a, b, k = map(int, input().split())


def calc(n):
    if n % 2 == 1:
        return n - 1
    else:
        return n


if __name__ == '__main__':
    for i in range(k):
        if i % 2 == 0:
            a = calc(a)
            b += a//2
            a //= 2
        else:
            b = calc(b)
            a += b//2
            b //= 2
print(a, b)


Measured memory_bytes: 3060
#n = int(input())
#a, b = map(int, input().split())
#al = list(map(int, input().split()))
#al=[list(input()) for i in range(n)]

a, b = map(str, input().split())

a = int(a)
b = int(b[0]+b[2:])
print(a*b//100)


Measured memory_bytes: 9028
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;

  cin >> n;
  for ( int i =0; i < n; i++ ) cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for ( int i = 1; i < n; i++ ) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;
  
  return 0;
}



Measured memory_bytes: 3884
N, Q = map(int, input().split())
S = input()

fromtos = []
for i in range(Q):
  fromtos.append(list(map(int, input().split())))

counts = [0] * N
for i in range(N-1):
  if S[i:i+2] == 'AC':
    counts[i+1] = counts[i] + 1
  else:
    counts[i+1] = counts[i]

for fromto in fromtos:
  print(counts[fromto[1]-1] - counts[fromto[0]-1])

Measured memory_bytes: 30640
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e16
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010

int main(){
	IOS;
	// ll mx=-1,sum=0,n;cin>>n;
	// ll a[n],b[n],c[n];
	// rep(i,0,n){cin>>a[i];sum+=a[i];}
	// rep(i,0,n){cin>>b[i];sum+=b[i];}
	// rep(i,0,n){cin>>c[i];mx=max(mx,c[i]);}
	// i
	ll n;cin>>n;n--;
	ll a[n];rep(i,0,n)cin>>a[i];
	ll ans=a[0];
	rep(i,0,n-1){
		ans+=min(a[i],a[i+1]);
	}
	ans+=a[n-1];
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int MOD = 1000000007;

struct Pony
{
    long a, b;
 
    Pony(long a_, long b_)
    {
        a = a_;
        b = b_;
    }
 
    bool operator<(const Pony &another) const
    {
        return b < another.b;
    };
};

int fac(int k){
    int sum = 0;
    for (int i = 1; i <= k; ++i)
    {
        sum += i;
    }
    return sum;
}

vector<int> alpha[26];

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

  string s, t;

  cin >> s >> t;

  rep(i, s.size()) {
    alpha[s[i] - 'a'].push_back(i);
  }

  long res = 0;
  int idx = -1;

  rep(i, t.size()) {
    int next = ubv(alpha[t[i] - 'a'], idx);
    if (next == alpha[t[i] - 'a'].size()) {
      res += s.size();
      idx = -1;
      next = ubv(alpha[t[i] - 'a'], idx);
      if (next == alpha[t[i] - 'a'].size()) {
        res = -1;
        break;
      }
    }
    idx = alpha[t[i] - 'a'][next];
  }
  cout << (res == -1 ? -1 : res+idx+1) << endl;
}


Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7, N = 30;

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

int dist[N][N];
char loc[N][N];
bool vis[N][N];
int ans = 0;

void bfs(int i, int j) {
  memset(vis, 0, sizeof vis);
  memset(dist, -1, sizeof dist);
  queue<pair<int, int>> q;
  vis[i][j] = 1;
  q.push({i, j});
  dist[i][j] = 0;
  while(!q.empty()) {
    i = q.front().first;
    j = q.front().second;
    q.pop();
    for (int d = 0; d < 4; d++) {
      int x = i + dx[d];
      int y = j + dy[d];
      if (vis[x][y] || loc[x][y] != '.') continue;
      dist[x][y] = dist[i][j] + 1;
      vis[x][y] = 1;
      q.push({x, y});
      ans = max(ans, dist[x][y]);
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> loc[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (loc[i][j] == '#') continue;
      bfs(i, j);
    }
  }
  cout << ans << "\n";
  return 0;
}

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

int main()
{
  int x, y, z, temp;
  cin >> x >> y >> z;

  temp = x;
  x = y;
  y = temp;
  temp = x;
  x = z;
  z = temp;

  cout << x << "	" << y << "	" << z << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
	//ABC168 A
	int n;
	// N

	cin >> n;

	switch (n % 10) {
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		cout << "hon";
		break;
	case 0:
	case 1:
	case 6:
	case 8:
		cout << "pon";
		break;
	case 3:
		cout << "bon";
		break;
	}

	return 0;
}


Measured memory_bytes: 3592
# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-
from sys import stdin


############################################
#from sys import stdin
import numpy as np

# read data for n sequences.
d = stdin.readline().split()
N = int(d[0])
Q = int(d[1])
data = str(stdin.readline().split()[0])

q = []
for _ in range(Q):
    q.append(stdin.readline().split())

count=0

def leftsearch(N, q, data):
    x = 0 
    for spell in q:
        now = data[N]
        if now==spell[0]:
            if spell[1]=='R':
                N+=1
            else:
                N-=1
            if N < 0:
                x = 1
                break
            elif N==len(data):
                break
    return(x)
def rightsearch(N, q, data):
    x = 0    
    for spell in q:
        now = data[N]
        if now==spell[0]:
            if spell[1]=='R':
                N+=1
            else:
                N-=1
            if N >= len(data):
                x = 1
                break
            elif N == 0:
                break
    return(x)

# binary search
left = 0
right = len(data)-1
while(right >= left):
    mid = left + int((right - left)/2)
    if 1 == leftsearch(mid, q, data):
        left = mid + 1
    else:
        right = mid -1
#print("left:",mid)
if mid == 0: 
    if 0 == leftsearch(mid, q, data):
        leftamount = 0
    else:
        leftamount = 1
else:
    if 1 == leftsearch(mid, q, data):
        leftamount = mid+1
    else:
        leftamount = mid

# right binary
left = 0
right = len(data)-1
while(right >= left):
    mid = left + int((right - left)/2)
#    print(mid)
    if 1 == rightsearch(mid, q, data):
        right = mid -1
    else:
        left = mid + 1
#print("right:",mid)

#if mid == len(data)-1:
if 0 == rightsearch(mid, q, data):
    rightamount = 0
else:
    rightamount = 1

rightamount += len(data)-1 - mid

print(len(data) - (leftamount + rightamount))


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

int main()
{
  int N; cin >> N;
  int A[N]; rep(i,N) cin >> A[i];
  
  sort(A, A+N, greater<int>());
  
  int ans = A[0] - A[N-1];
  
  cout << ans << endl;
}

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

int n,m,step;

void move(int* tray,int i,int u,int d)
{
  if(i>n) return;

  if(tray[i]==u){
    move(tray,i+1,u,d);
    tray[i]=1;
    step++;
    if(step>m) return;
    //    cout <<"step "<< step <<" | "<< i <<":"<< u << " to " << 1 << endl;
  }

  if(tray[i]==1){
    move(tray,i+1,d,u);
    tray[i]=d;
    step++;
    if(step>m) return;
    //    cout <<"step "<< step <<" | "<< i <<":"<< 1 << " to " << d << endl;
  }

  move(tray,i+1,u,d);
  return;
}

int main()
{

  while(1){
    cin >> n >> m;
    if(n==0 && m==0) break;
    int tray1[16],tray2[16];
    for(int i=0;i<3;i++){
      int nt;
      cin >> nt;
      for(int j=0;j<nt;j++){
	int cup;
	cin >> cup;
	tray1[cup]=tray2[cup]=i;
      }
    }

    step=0;
    move(tray1,1,0,2);
    //  cout << step << endl;
    int ans=step;
    step=0;
    move(tray2,1,2,0);
    //  cout << step << endl;
    if(step<ans) ans=step;
    if(ans>m) ans=-1;

    cout << ans << endl;
  }
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define INF 2e+9
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> PP;

int siz,segMax[300000],segAdd[300000],bit[300010];

void b_add(int i,int x){
	while(i <= siz){
		bit[i] += x;
		i += i & -i;
	}
}

int sum(int i){
	int s = 0;
	while(i){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(int a,int b,int x,int k = 0,int l = 0,int r = siz){
	if(b <= l || r <= a) return;
	if(a <= l && r <= b){
		segAdd[k] += x;
		return;
	}
	add(a,b,x,k * 2 + 1,l,(l + r) / 2);
	add(a,b,x,k * 2 + 2,(l + r) / 2,r);
	segMax[k] = max(segMax[k * 2 + 1] + segAdd[k * 2 + 1],segMax[k * 2 + 2] + segAdd[k * 2 + 2]);
}

int get(int a,int b,int k = 0,int l = 0,int r = siz){
	if(b <= l || r <= a) return 0;
	if(a <= l && r <= b) return segMax[k] + segAdd[k];
	return max(get(a,b,k * 2 + 1,l,(l + r) / 2),get(a,b,k * 2 + 2,(l + r) / 2,r)) + segAdd[k];
}

signed main(){
	int n,a[100000],ma = -1,mi = INF,tent = 0,ans = 0;
	bool used[100000] = {};
	vector<int> ls,rs,la,ra,as;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		as.push_back(a[i]);
	}
	sort(as.begin(),as.end());
	as.erase(unique(as.begin(),as.end()),as.end());
	for(int i = 0;i < n;i++) a[i] = lower_bound(as.begin(),as.end(),a[i]) - as.begin();
	for(int i = 0;i < n;i++){
		if(ma < a[i]){
			ma = a[i];
			ls.push_back(i);
			la.push_back(a[i]);
			used[i] = true;
		}
	}
	for(int i = n - 1;i >= 0;i--){
		if(mi > a[i]){
			mi = a[i];
			rs.push_back(i);
			ra.push_back(a[i]);
			used[i] = true;
		}
	}
	reverse(rs.begin(),rs.end());
	reverse(ra.begin(),ra.end());
	siz = 1;
	while(siz < n) siz *= 2;
	for(int i = 0;i < n;i++){
		tent += i - sum(a[i] + 1);
		b_add(a[i] + 1,1);
	}
	vector<PP> evt1[100001],evt2[100001];
	for(int i = 0;i < n;i++){
		if(!used[i]){
			int l1 = upper_bound(la.begin(),la.end(),a[i]) - la.begin();
			int l2 = upper_bound(ls.begin(),ls.end(),i) - ls.begin() - 1;
			int r1 = upper_bound(rs.begin(),rs.end(),i) - rs.begin();
			int r2 = lower_bound(ra.begin(),ra.end(),a[i]) - ra.begin() - 1;
			if(l1 <= l2 && r1 <= r2){
				evt1[r1].push_back(mp(2,mp(l1,l2)));
				evt2[r2].push_back(mp(-2,mp(l1,l2)));
			}
			if(l1 > 0 && la[l1 - 1] == a[i]){
				evt1[r1].push_back(mp(1,mp(l1 - 1,l1 - 1)));
				evt2[r2].push_back(mp(-1,mp(l1 - 1,l1 - 1)));
			}
			if(r2 < (int)rs.size() - 1 && ra[r2 + 1] == a[i]){
				evt1[r2 + 1].push_back(mp(1,mp(l1,l2)));
				evt2[r2 + 1].push_back(mp(-1,mp(l1,l2)));
			}
		}
	}
	for(int i = 0;i < n;i++){
		for(PP p : evt1[i]) add(p.second.first,p.second.second + 1,p.first);
		ans = max(ans,get(0,siz));
		for(PP p : evt2[i]) add(p.second.first,p.second.second + 1,p.first);
	}
	if(!tent) cout << ((ls.size() == n) ? 1 : 0) << endl;
	else cout << tent - ans - 1 << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  map<ll, int> mp;
  for (int i = 0; i < n; ++i) {
    ll tmp = i - a[i];
    // if (tmp >= 0)
      mp[tmp]++;
  }

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ll tmp = i + a[i];
    ans += mp[tmp];
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 27368
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.8.2)

import math
import statistics
import numpy as np
import queue
import itertools
import functools 

n = int(input())
dice1, dice2 = [], []
for i in range(n):
	a, b = map(int, input().split())
	dice1.append(a)
	dice2.append(b)

chk = False
for i in range(2, n):
	if (dice1[i - 2] == dice2[i - 2] and dice1[i - 1] == dice2[i - 1] and dice1[i] == dice2[i]):
		chk = True
		break

print('Yes' if chk else 'No')

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

int main(){
  int64_t A,B,V,W,T;
  cin>>A>>V;
  cin>>B>>W;
  cin>>T;

  int64_t dis=(int64_t)abs(A-B);

  if(T*V>=T*W+dis) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 3636
n, a, b, c, d = gets.split.map(&:to_i)
ss = gets.split('').map{|e| e=='#' ? true : false}
overlap = c > d

f_single = false
double_stone_flag = (ss[(a-1)..([c,d].max-1)].select{|e|
  f_double = f_single && e
  f_single = e
  f_double
}).size.positive?
f_single = false
f_double = false
triple_dots_flag = (ss[(b-2)..(d)].select{|e|
  f_triple = f_double && !e
  f_double = f_single && !e
  f_single = !e
  f_triple
}).size.positive?

if c < d
  puts double_stone_flag ? 'No' : 'Yes'
else
  puts !double_stone_flag && triple_dots_flag ? 'Yes' : 'No'
end


Measured memory_bytes: 18044
#include<bits/stdc++.h>
using namespace std;
int mp[100];
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    mp[a]++;
    mp[b]++;
    mp[c]++;
    if(mp[a]==2)cout<<"Yes"<<endl;
    else if(mp[b]==2)cout<<"Yes"<<endl;
    else if(mp[c]==2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include<string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
using namespace std;
const int MAX=1e5+10;
long long a[MAX];
bool b[MAX];
int main()
{
    long long x;
    long long n,m;
    long long pre;
    long long now;
    bool st=0;
    cin>>x;
    for(int i=1;;i++)
    {
    	for(int j=i-1;;j--)
    	{
    		pre=abs(pow(i,5)-pow(j+1,5)-x);
			now=abs(pow(i,5)-pow(j,5)-x);
			if(now==0) 
			{
				n=i;
				m=j;
				st=1;
				break;
			}
			if(now>pre) break;
		}
		if(st==1) break;
		
	}
	cout<<n<<" "<<m;
}

Measured memory_bytes: 4052
lst=[int(input()) for _ in range(5)]

c=[]
for i in range(5):
    if lst[i]%10!=0:
        c.append(lst[i]%10)
        lst[i]=(lst[i]//10+1)*10

if not c:
    print(sum(lst))
else:
    print(sum(lst)+min(c)-10)

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

using namespace std;

#define REP(a, b, c) for (register int a = b, _n = c; a <= _n; ++a)
#define DREP(a, b, c) for (register int a = b, _n = c; a >= _n; --a)
#define FOR(a, b, c) for (register int a = b, _n = c; a < _n; ++a)
#define DFOR(a, b, c) for (register int a = b, _n = c; a > _n; --a)
#define EREP(a, b) for (register int a = head[b]; a; a= edge[a].nxt)

inline int rd () {
	int x = 0; char IO = getchar();
	bool f = 0;
	while ((IO < '0' || IO > '9') && IO != '-') IO = getchar();
	if (IO == '-') f = 1, IO = getchar();
	while (IO >= '0' && IO <= '9') x = (x << 3) + (x << 1) + (IO ^ 48), IO = getchar();
	return f ? -x : x;
}

const int SIZE = 200005;

char s[SIZE], t[SIZE];

int nxt[SIZE][26];

void _main () {
	scanf ("%s%s", s + 1, t + 1);
	memset(nxt, -1, sizeof nxt);

	int n = strlen(s + 1);
	REP (i, 1, n) s[i + n] = s[i];
	DREP (i, 2 * n, 1) {
		FOR (j, 0, 26)
			nxt[i][j] = nxt[i + 1][j];
		nxt[i][s[i] - 'a'] = i;
	}

	int now = 0;
	long long ans = 0;

	int m = strlen(t + 1);

	REP (i, 1, m) {
		if (nxt[1][t[i] - 'a'] == -1) {
			puts("-1");
			return;
		}
		ans += nxt[now + 1][t[i] - 'a'] - now;
		now = nxt[now + 1][t[i] - 'a'];
		if (now > n) now -= n;
	}
	printf ("%lld\n", ans);
}

int main () {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
#endif
	_main();
	return 0;
}


Measured memory_bytes: 20992
from itertools import permutations
N, M = map(int, input().split())
c = []
for i in range(N):
    c.append([int(j) for j in input().split()])

a = [1,-1]
ans = 0
for i in a:
    for j in a:
        for k in a:
            s = []
            for l,m,n in c:
                s.append(l*i + j * m + k * n)
            t = sum(sorted(s, reverse=True)[:M])
            ans = max(ans, t)
print(ans)

Measured memory_bytes: 3320
use std::io::stdin;
use std::vec::Vec;

mod utils {
    use std::io::BufRead;
    use std::str::{self, FromStr};

    pub struct StdinReader<R: BufRead> {
        reader: R,
        buf: Vec<u8>,
    }

    impl<R: BufRead> StdinReader<R> {
        pub fn new(reader: R) -> StdinReader<R> {
            StdinReader {
                reader: reader,
                buf: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        pub fn reads<T: FromStr>(&mut self) -> T {
            self.read_until(b' ')
        }

        #[allow(unused)]
        #[inline]
        pub fn readl<T: FromStr>(&mut self) -> T {
            self.read_until(b'\n')
        }

        #[allow(unused)]
        #[inline]
        pub fn read_vec<T: FromStr>(&mut self) -> Vec<T> {
            return self.read_until::<String>(b'\n').trim().split_whitespace().map(|c| c.parse().ok().unwrap()).collect();
        }

        #[inline]
        pub fn read_until<T: FromStr>(&mut self, delim: u8) -> T {
            loop {
                self.buf.clear();
                let len = self.reader
                    .read_until(delim, &mut self.buf)
                    .expect("failed reading bytes");
                match len {
                    0 => panic!("early eof"),
                    1 if self.buf[0] == delim => (),
                    _ => {
                        if self.buf[len - 1] == delim {
                            self.buf.truncate(len - 1);
                        }
                        break;
                    }
                }
            }

            let elem = unsafe { str::from_utf8_unchecked(&self.buf) };
            elem.parse().unwrap_or_else(|_| panic!(format!("failed parsing: {}", elem)))
         }
    }
}


fn main(){
    let stdin = stdin();
    let mut r = utils::StdinReader::new(stdin.lock());
    let a:i32 = r.reads();
    let b:i32 = r.readl();

    if(a * b % 2 == 1) {
        println!("Odd");
    }else{
        println!("Even");
    }

}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    int r,g,b,N; cin >> r >> g >> b >> N;

    ll ans = 0;

    for (ll i = 0;i*r <= N;i++){
        for (ll j = 0;i*r+j*g <= N;j++){
            //cout << i << " " << j << " " << N-(i*r+j*g)<< endl;
            if((N-(i*r+j*g)) % b == 0 ) ans++;
        }
    }

    cout << ans << endl;

    return 0;

}

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

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 20005;

int n, m;

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  Read(n);
  if (n == 3) {
    puts("2 5 63");
    return 0;
  }
  if (n & 1) {
    int a[8] = {6, 2, 10, 3, 9, 4, 8, 12};
    for (int i = 0; i < n; ++i) {
      printf("%d%c", a[i & 7], i == n - 1 ? '\n' : ' ');
      a[i & 7] += 12;
    }
  } else {
    int a[8] = {2, 10, 3, 9, 4, 8, 6, 12};
    for (int i = 0; i < n; ++i) {
      printf("%d%c", a[i & 7], i == n - 1 ? '\n' : ' ');
      a[i & 7] += 12;
    }
  }
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  switch (N%10) {
  case 0:
  case 1:
  case 6:
  case 8:
    cout << "pon" << endl;
    break;
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
    cout << "hon" << endl;
    break;
  case 3:
    cout << "bon" << endl;
    break;
  }
  return 0;
}


Measured memory_bytes: 3636
#include<iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    for (long long i = 0; i < (1 << n); i++) {
        cout << i << ":";
        for (long long j = 0; j < n; j++) {
            if (i & (1 << j)) { cout << " " << j;}
        }
        cout << endl;
    }
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int k, a,b; cin >> k >> a >> b;
  bool ok = a/k != b/k;
  ok |= a % k == 0;
  ok |= b % k == 0;
  puts(ok?"OK": "NG") ;
  
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

const ll mod=1e9+7;
ll mu(ll a,ll b){
  return (ll)a*b%mod;
}
ll ad(ll a,ll b){
  if((a+=b)>=mod)a%=mod;
  return a;
}
ll pw(ll a,ll b,ll c=1LL){
  for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
  return c;
}
ll dv(ll a,ll b){
  return mu(a,pw(b,mod-2));
}

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

  ll n,k;
  cin >> n >> k;
  ll ans =0;
  vector<ll> ko(k+1,0);
  for(ll i = k; i>0;i--){
    for(ll j = i+i; j<=k;j+=i) {
      ko[i] = ad(ko[i], mod-ko[j]);
    }
    ko[i] = ad(pw(k/i,n),ko[i]);
    ans = ad(ans,mu(ko[i] ,i) );
  }
  cout << ans << endl;
  return 0;
    

}


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

int main(){
    int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;

    int time = 0;
    int vals[5] = {A, B, C, D, E};

    int last_index = 0;
    int r = 0;
    for(int i=0; i<5; i++){
        int tmp_r = vals[i] % 10;
        if(tmp_r != 0){
            if(r < 10-tmp_r){
                r = 10 - tmp_r;
                last_index = i;
            }
        }
    }

    for(int i=0; i<5; i++){
        if(i!=last_index){
            time += (int)ceil(vals[i]/10.0)*10;
        } else {
            time += vals[i];
        }
    }
    cout << time << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int H,W;
    cin>>H>>W;
    vector<vc> C(H,vc(W));
    rep(i,H) {
        rep(j,W) {
            cin>>C[i][j];
        }
    }
    rep(i,H) {
        rep(j,W) {
            cout<<C[i][j];
        }
        cout<<endl;
        rep(j,W) {
            cout<<C[i][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a[200];
	int b[200];
	int i,j;
	char s[200];
	int keta,wa;
	i=0;
	while((scanf("%d %d",&a[i],&b[i]))!=EOF){
//		printf("debug %s is read -scanf = %d\n",s,j);
		i++;
		if(i==199)break;
	}
//printf("debug %d %d is read last %d\n",a[i-1],b[i-1],i-1);
	for(j=0;j<i;j++){
		keta=1;
		wa=a[j]+b[j];
		for(;wa/=10;keta++);
		printf("%d\n",keta);
	}
	return 0;
}

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

long long int calcount(long long int n,map<long long int,long long int>& m)
{
	if(n==1)
	{
		return 1;
	}
	if(m.find(n)!=m.end())
	{
		return m[n];
	}
	else
	{
		long long int interm = calcount(n/2,m);
		m[n/2]=interm;
		return 1+2*m[n/2];
	}
}
int main()
{
	long long int n;
	cin>>n;
	map<long long int,long long int> m;
	long long int ans = calcount(n,m);
	cout<<ans<<endl;
}

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

const int N=3009,mod=998244353;
int n,s,a[N],dp[N][N];

int f(int i,int k){
    if(k<0)return 0;
    if(i==0 and k==0)return 1;
    if(k and i==0)return 0;
    if(dp[i][k]!=-1)return dp[i][k];
    int res=f(i-1,k-a[i]);
    res=(res+2*f(i-1,k)%mod)%mod;
    return dp[i][k]=res;
}
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n >> s;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    memset(dp,-1,sizeof dp);
    cout << f(n,s);
}


Measured memory_bytes: 74536
#include<iostream>
using namespace std;int main(){int n;while(true){cin>>n;if(n==0)break;int w[25],f[25];for(int i=0;i<n;i++)cin>>w[i]>>f[i];for(int i=0;i<n-1;i++){for(int j=n-1;j>i;j--){if(f[j]<f[j-1]){int tmp=f[j];f[j]=f[j-1];f[j-1]=tmp;tmp=w[j];w[j]=w[j-1];w[j-1]=tmp;}}}int h=0;bool t=true;for(int i=0;i<n;i++){h+=w[i];if(h>f[i])t=false;}if(t==true)cout<<"Yes"<<endl;else cout<<"No"<<endl;}return 0;}

Measured memory_bytes: 1152
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;



public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		ArrayList<Integer> array = new ArrayList<Integer>();
		array.add(a);
		array.add(b);
		array.add(c);
		Collections.sort(array);
		System.out.println(array.get(0)+array.get(1));

	}
}

Measured memory_bytes: 21972
s = input() #sys.stdin.readlineは最後が改行
n = len(s)

INF = float('inf')

a = [-INF]*(n+1)

for i in range(n):
    if i==0 and s[i] =='<':
        a[i]=0
        continue
    if i==n-1:
        if s[i] =='>':
            a[i+1]=0
        continue

    if s[i] =='>' and s[i+1]=='<':
        a[i+1]=0


def left(i):
    while True:
        if i ==0:
            break
        if s[i-1] == '>' and a[i-1] <=a[i]:
            a[i-1]=a[i]+1
        else:
            break
        i-=1

def right(i):
    while True:
        if i==n:
            break
        if s[i] == '<' and a[i]>=a[i+1]:
            a[i+1]=a[i]+1
        else:
            break
        i+=1

for i in range(n+1):
    if a[i] == 0:
        left(i)
        right(i)

print(sum(a))


Measured memory_bytes: 23336
program sample
	implicit none
    integer ::x,y,z,e,f,i,k,l
    integer,allocatable :: a(:),b(:),c(:,:),d(:)
    
    read(*,*) x,y,z
    
    allocate(a(x))
    allocate(b(y))
    allocate(c(3,z))
    allocate(d(z+1))
    
    do i=1,size(d)+1
    	d(i)=0
    end do
    
    read(*,*) a
    read(*,*) b
    read(*,*) c
    
    e=minval(a)
    f=minval(b)
    d(1) = e+f
    
    do i=2,z+1
    	!k,lは何番目の冷蔵庫と電子レンジが割引になるか示す。
    	k=c(1,i-1)
        l=c(2,i-1)
        d(i)= a(k) +b(l)-c(3,i-1)
    end do

    write(*,*) minval(d)
    
    deallocate(a)
    deallocate(b)
    deallocate(c)
    deallocate(d)
    
    stop
end program sample


Measured memory_bytes: 3200
/* ---------- 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>

// 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>

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

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

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

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    cin >> N;

    map<string, int> m;
    for (int i = 0; i < N; i++) {
        string str;
        cin >> str;
        m[str]++;
    }

    int mx = -1;
    for (auto it = m.begin(); it != m.end(); it++) {
        mx = max(mx, it->second);
    }

    vector<string> v;
    for (auto it = m.begin(); it != m.end(); it++) {
        if (it->second == mx) {
            v.push_back(it->first);
        }
    }

    sort(v.begin(), v.end());

    for (auto& vv : v) {
        cout << vv << endl;
    }
    return 0;
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define pi 3.14159265358979323846
#define Endl endl
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int N;
ll seg[530000]; // 0-indexed!!
void init(int n_){
	N = 1;
	while(N<n_)N*=2;
	for(int i=0;i<2*N-1;i++)seg[i]=0;
}

void update(int k,int a){
	k += N-1;
	seg[k]=a;
	while(k>0){
		k = (k-1)/2;
		seg[k] = max(seg[k*2+1],seg[k*2+2]);
	}
}

ll query(int a,int b, int k, int l, int r){ 
	if(r<=a || b<=l) return 0;
	if(a<=l && r<=b) return seg[k];
	else{
		ll vl = query(a,b,k*2+1,l,(l+r)/2);
		ll vr = query(a,b,k*2+2,(l+r)/2,r);
		return max(vl,vr);
	}
}
int rig[214514];
int dp[214514];
signed main(){
	int n;
	cin>>n;
	vector< pair<int,int> > v;
	vector<int> s;
	for(int i=0;i<n;i++){
		int x,d;
		cin>>x>>d;
		v.pb( mp( x,d ) );
		s.pb( x );
	}
	sort( v.begin(), v.end() );
	sort( s.begin(), s.end() );
	init(214514);
	for(int i=n-1;i>=0;i--){
		int x = v[i].first;
		int d = v[i].second;
		auto it = upper_bound( s.begin(), s.end(), x+d-1 );
		it--;
		int nex = it - s.begin();
		if( nex == i ){
			update( i, i );
			rig[i] = i;
		}
		else{
			int q = query( i+1, nex+1 , 0, 0, N);
			update( i, q );
			rig[i] = q;
		}
	}
	dp[n] = 1;
	for(int i=n-1;i>=0;i--){
		dp[i] = dp[i+1] + dp[rig[i]+1];
		dp[i] %= 998244353;
	}
	cout<<dp[0]<<endl;
	return 0;
}

Measured memory_bytes: 15084
#include <iostream>
#include <algorithm>
#include <vector>
 
using ll = long long int;
 
int main() {
  using namespace std;
  int n, k;
  ll ans = 0;
  vector<ll> h;
  cin >> n >> k;
  h.resize(n);
  for(int i=0; i<n; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  for(int i=0; i<n-k; i++) {
    ans += h[i];
  }
  cout << ans;
}

Measured memory_bytes: 1792
defmodule Main do
  def main do
      [a, b, x] =
      IO.read(:line)
      |> String.trim
      |> String.split(" ")
    a = String.to_integer(a)
    b = String.to_integer(b)
    x = String.to_integer(x)
    if (a < x and a + b >= x) or a == x do
    	IO.puts("YES")
    else
    	IO.puts("NO")
    end
  end
end


Measured memory_bytes: 30720
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;
vector<pair<pair<double,double>,bool> > cp;
pair<double,double> relv(pair<double,double> a,pair<double,double> b)
{
  return make_pair(a.first-b.first,a.second-b.second);
}
double cross(pair<double,double> va,pair<double,double> vb)
{
  return va.first*vb.second-va.second*vb.first;
}
void crosspoint(pair<double,double> a,pair<double,double> b,pair<double,double> c,pair<double,double> d,bool e)
{
  auto ab=relv(a,b),cd=relv(c,d);
  if(!(cross(ab,relv(a,c))*cross(ab,relv(a,d)) < 0 &&
       cross(cd,relv(c,a))*cross(cd,relv(c,b)) < 0)) return;
  double midrat=cross(cd,relv(c,a))/(cross(cd,relv(c,a))+cross(cd,relv(b,d)));
  cp.push_back(make_pair(make_pair(a.first+midrat*ab.first,a.second+midrat*ab.second),e));
}

int main(void)
{
  int n;
  cin >> n;
  REP(i,n){
    int sx,sy,ex,ey;
    cin >> sx >> sy >> ex >> ey;
    pair<double,double> s,e;
    s=make_pair(sx,sy),e=make_pair(ex,ey);
    cp.clear();
    int m;
    cin >> m;
    REP(i,m){
      int x[2],y[2],p,q;
      cin >> x[0] >> y[0] >> x[1] >> y[1] >> p >> q;
      crosspoint(s,e,make_pair(x[0],y[0]),make_pair(x[1],y[1]),p==q);
    }
    SORT(cp);
    int answer=0;
    REP(i,(int)cp.size()-1) if(cp[i].second!=cp[i+1].second) ++answer;
    cout << answer << endl;
  }
}

Measured memory_bytes: 3072
import math

n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
dist = [[0 for _ in range(n-1)] for _ in range(n)]
ans = 0

for i in range(n):
    for j in range(n):
        if i == j: continue
        d = math.sqrt((p[i][0] - p[j][0])**2 + (p[i][1] - p[j][1])**2)
        dist[i].append(d)
    ans += sum(dist[i]) * math.factorial(n-1)

print(ans / math.factorial(n))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    long int a, b, temp;
    cin >> a >> b;
    if(a>b){
        temp = a;
        a    = b;
        b    = temp;
    }
    for(int i=1;i<=b;i++){
        if((a*i)%b==0){ temp = a*i; break; }
    }
    cout << temp << endl;
    return 0;
}

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

constexpr int MAX_N = 1e5;
int s[MAX_N+1];

int main() {
  // エラトステネスのふるい
  bitset<MAX_N + 1> isPrime;
  for (int i{2}; i <= MAX_N; ++i)
    isPrime.set(i);
  for (int i{2}; i <= MAX_N; ++i) {
    if (isPrime[i]) {
      for (int j{i * 2}; j <= MAX_N; j += i) {
        isPrime.reset(j);
      }
    }
  }

  // 累積和
  for (int i{1}; i < MAX_N; ++i) {
    s[i] = s[i-1] + (i % 2 == 1 && isPrime[i] && isPrime[(i+1)/2] ? 1 : 0);
  }

  int Q; cin >> Q;
  for (int i{}; i < Q; ++i) {
    int l, r; cin >> l >> r;
      cout << s[r] - s[l-1] << endl;
  }


  return 0;
}


Measured memory_bytes: 1532
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int p=0;
        while(true){
            int a=sc.nextInt(),b=sc.nextInt();
            if(a==0&&b==0)break;
            if(p>0){
                System.out.println();
            }
            boolean check=true;
            for(int i=a;i<=b;i++){
                boolean uru=false;
                if(i%4==0){
                    if(i%100==0){
                        if(i%400==0){
                            uru=true;
                        }
                    }else{
                        uru=true;
                    }
                }
                if(uru){
                    System.out.println(i);
                    check=false;
                }
            }
            if(check){
                System.out.println("NA");
            }
            p++;
        }
    }
}

Measured memory_bytes: 20676
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, m = i_map()
    a_list = i_list()
    num_list = i_row_list(m)

    a_list.sort(reverse=True)
    num_list = sorted(num_list, key=lambda x: -x[1])

    ans = 0
    a_count = 0
    num_count = 0
    for _ in range(n):
        if num_count == m or a_list[a_count] > num_list[num_count][1]:
            ans += a_list[a_count]
            a_count += 1
        else:
            ans += num_list[num_count][1]
            num_list[num_count][0] -= 1
            if num_list[num_count][0] == 0:
                num_count += 1
    print(ans)

if __name__ == '__main__':
    main()


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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	int max,res;
	if (a>max){
		max = a;
		res = max*10 + b + c;
	}
	if (b>max){
		max = b;
		res = max*10 + a + c;
	}
	if (c>max){
		max = c;
		res = max*10 + b + a;
	}
	cout << res << "\n";
}

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

using namespace std;

#define INF 2<<29
#define F first
#define S second

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

int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  printf("%d\n",max(a+b,max(a-b,a*b)));
  
  return 0;
}



Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; string S; cin >> N >> S;
    string SF = S.substr(0, N);
    string SL = S.substr(N, N);
    reverse(ALL(SL));
    
    map<string, ll> former;
    rep(st, 1ll<<N){
        string f, l;
        rep(i, N){
            if(st>>i&1) f += SF[i];
            else l += SF[i];
        }
        former[f+"-"+l]++;
    }
    
    map<string, ll> latter;
    rep(st, 1ll<<N){
        string f, l;
        rep(i, N){
            if(st>>i&1) f += SL[i];
            else l += SL[i];
        }
        latter[f+"-"+l]++;
    }
    
    ll ans = 0;
    FORMAP(it, former){
        ans += it->ss * latter[it->ff];
    }
    cout << ans << endstr;
    return 0;
}


Measured memory_bytes: 83584
N = int(input())

link = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    link[u - 1].append((v - 1, w))
    link[v - 1].append((u - 1, w))

d = [0] * N
q = [0]
while q:
    p = q.pop()
    for n, w in link[p]:
        if d[n] == 0:
            d[n] = d[p] + w
            q.append(n)

for i in d:
    print(i % 2)


Measured memory_bytes: 42772
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    int count = 1;
    while(true){
      if(count*(2*d+1) >= n){
        System.out.println(count);
        break;
      } else {
        count++;}
    }
  }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	int  n; cin >> n;
	
	if(n < 1200) cout << "ABC" << endl;
	else if(n < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
	return 0;
}


Measured memory_bytes: 256