akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n;
	string s;
	cin >> n >> s;

	map<ll, ll> mp1,mp2,mp3;


	REP(i, n) {
		ll x = s[i] - '0';
		for (auto i : mp2) {
			mp3[i.first * 10 + x]++;
		}
		for (auto i : mp1) {
			mp2[i.first * 10 + x]++;
		}
		mp1[x]++;
	}

	cout << mp3.size() << endl;

	return 0;
}

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

int main(){
    string s;cin>>s;
    int w;cin>>w;
    string out = "";
    for (int i=0;i<s.size();i++){
        if (i % w == 0){
            out += s[i];
        }
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll K;
ll N=50;
ll A[52];
int main()
{
	scanf("%lld",&K);
	for(ll i=0;i<N;i++){
		A[(int)i]=N-1;
	}
	for(ll i=0;i<N;i++){
		A[(int)i]+=K/N;
	}
	for(ll i=0;i<(K%N);i++){
		for(ll j=0;j<N;j++){
			if(i==j){A[j]+=N;}
			else{A[j]-=1;}
		}
	}
	printf("%lld\n",N);
	for(int i=0;i<N;i++){
		printf("%lld",A[i]);
		if(i!=N-1)printf(" ");
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int main(){
  int N,A[100];
  scanf("%d",&N);
  for(int i=0;i<N;i++) scanf("%d",&A[i]);
  sort(A,A+N);
  printf("%d\n",A[N-1]-A[0]);
  return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
ans = 0

while True:
  check = 0
  for j in range(N):
    if A[j] % 2 == 0:
      check += 1
  if check == N:
    for i in range(N):
      A[i] = A[i]//2
    ans += 1
  else:
    break
print(ans)

Measured memory_bytes: 3060
a,b,c = map(int,input().split())
K = int(input())

inputL = [a,b,c]
max = a
idx = 0
if(max < b):
    max = b
    idx = 1
if(max < c):
    max = c
    idx = 2

for i in range(K):
    max *= 2

inputL[idx] = max

sum = 0
sum = inputL[0] + inputL[1] + inputL[2]
print(sum)


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

using namespace std;


int main() {

	int a = 0;
	int b = 0;
	cin >> a >> b;
	if (b % a == 0) {
		cout << b / a << endl;
	}
	else {
		cout << b / a + 1 << endl;
	}
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i] >>y[i];
typedef long long int ll;
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }

int main(){
	int a,b; cin >>a>>b;
	if(a<=5) cout << 0 << endl;
	else if(a<=12) cout << b/2 << endl;
	else cout << b << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
long long int modpow(long long int a, long long int n, long long int p)
{
	long long int res = 1;
	while (n > 0)
	{
		if (n % 2 > 0)
			res = res * a % p;
		a = a * a % p;
		n /= 2;
	}
	return res;
}
int main()
{
	long long int n;
	scanf("%lld", &n);
	long long int p = 1000000007;
	printf("%lld\n", ((modpow(10, n, p) - 2 * modpow(9, n, p) % p) % p + modpow(8, n, p) + p) % p);
	return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define ll long long int
int main()
{
    ll t,i,j,k,w,l,n,m;
    cin>>n>>w;

    vector<ll> v1(n),w1(n);
    for(i=0;i<n;i++)
    cin>>w1[i]>>v1[i];
    k=0;
    for(i=0;i<n;i++)
        k+=v1[i];
    vector<ll> dp(k+1,INF);
    dp[0]=0;
    for(i=0;i<n;i++)
    {
        for(j=k;j>=v1[i];j--)
        {
            dp[j]=min(dp[j],dp[j-v1[i]]+w1[i]);
        }
    }
    for(i=0;i<=k;i++)
    {
        //cout<<dp[i]<<" ";
        if(dp[i]<=w)
            l=i;
    }//cout<<"\n";

    cout<<l;
}


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

using namespace std;
typedef long long ll;

const int mxN = 3010, mxF = 2e5 + 5, mod = 1e9 + 7;
int H, W, N;
pair<int, int> p[mxN];
ll fac[mxF], inv[mxF], dp[mxN];

bool comp(const pair<int, int>& a, const pair<int, int>& b)
{
	return (a.first + a.second < b.first + b.second);
}

ll power(ll x, ll y)
{
	ll ret = 1;
	while (y > 0)
	{
		if (y & 1)
			ret = ret * x % mod;
		x = x * x % mod;
		y = y >> 1;
	}
	return ret;
}

ll invpow(ll x)
{
	return power(x, mod - 2);
}

ll comb(ll n, ll r)
{
	ll ret;
	if (r >= 0 && n >= 0 && n >= r)
	{
		ret = fac[n] * inv[n - r] % mod;
		ret = ret * inv[r] % mod;
	}
	else
	{
		ret = 0;
	}
	return ret;
}

ll solve(ll x, ll y)
{
	return comb(x + y, x);
}

int main()
{
	fac[0] = inv[0] = 1;
	for (int i = 1; i < mxF; i++)
	{
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = invpow(fac[i]);
	}
	scanf("%d%d%d", &H, &W, &N);
	for (int i = 0; i < N; i++)
	{
		scanf("%d%d", &p[i].first, &p[i].second);
	}
	p[N] = make_pair(H, W);
	p[N + 1] = make_pair(1, 1);
	N += 2;
	sort(p, p + N, comp);
	dp[0] = 1;
	for (int i = 1; i < N; i++)
	{
		dp[i] = solve(p[i].first - 1, p[i].second - 1);
		for (int j = 1; j < i; j++)
		{
			if (p[j].first <= p[i].first && p[j].second <= p[i].second)
			{
				dp[i] = (dp[i] - solve(p[i].first - p[j].first, p[i].second - p[j].second) * dp[j]) % mod;
			}
		}
	}
	dp[N - 1] = (dp[N - 1] + mod) % mod;
	printf("%lld", dp[N - 1]);
	return 0;
}

Measured memory_bytes: 6972
#include<iostream>
#include<string>
#include<sstream>
#include<stack>
#include<cstdlib>
using namespace std;
bool str_isdigit(std::string &str){
	int len = str.length();
	bool dot=false;
	if(len==0) return false;
	else{
		int i=0;
		if(str[0] == '-' || str[0] == '+'){
			if(1 == len) return false;////
			i++;
		}
		for(;i<len;i++){
			if(i>0 && str[i] == '.'){
				if(dot==false)
					dot=true;
				else
					return false;
			}
			if('9' < str[i] || str[i] < '0') return false;
		}
	}
	return true;
}

int gyakupo(int a, int b, char ch){
	if(ch == '+') return a+b;
	if(ch == '-') return a-b;
	if(ch == '*') return a*b;
	return a;
}

int main(){
	stack<int> stk;
	int left, right;
	char ope;
	string str;
	stringstream ss;
	getline(cin,str);
	ss<<str;
	while(ss>>str){
		if(str_isdigit(str)){
			stk.push(atoi(str.c_str()));
		}else{
			ope=str[0];
			right=stk.top();
			stk.pop();
			left=stk.top();
			stk.pop();
			stk.push(gyakupo(left, right, ope));
		}
	}
	cout<<stk.top()<<endl;
	return 0;
}

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

int main ()
{
    int a[200010];
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.size();i++)
        {a[i]=s[i]-'0';sum+=a[i];}
    sum%9?cout<<"No\n":cout<<"Yes\n";
	return 0;
}


Measured memory_bytes: 3732
// PotentializedUnionFindTree
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

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

template <class Abelian> class PotentializedUnionFind {

public:
  using value_type = Abelian;
  using size_type = size_t;
  using container_type =
      vector<tuple<size_type, value_type, size_type>>;

protected:
  container_type c;

private:
  size_type &par(const size_type i) { return get<0>(c[i]); }
  value_type &val(const size_type i) { return get<1>(c[i]); }
  size_type &siz(const size_type i) { return get<2>(c[i]); }
  value_type potential(size_type x) {
    value_type ret = {};
    while (x != par(x)) {
      val(x) = val(x) + val(par(x));
      ret = ret + val(x);
      x = par(x) = par(par(x));
    }
    return std::move(ret);
  }

public:
  PotentializedUnionFind() : c() {}
  explicit PotentializedUnionFind(const size_type size)
      : c(size, forward_as_tuple(static_cast<size_type>(0), value_type(),
                                      static_cast<size_type>(1))) {
    for (size_type i = 0; i < size; ++i)
      par(i) = i;
  }

  size_type size() const { return c.size(); }
  bool empty() const { return c.empty(); }

  size_type find(size_type x) {
    assert(x < size());
    while (x != par(x)) {
      val(x) = val(x) + val(par(x));
      x = par(x) = par(par(x));
    }
    return x;
  }
  value_type diff(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    assert(same(x, y));
    return potential(y) + (-potential(x));
  }
  bool same(const size_type x, const size_type y) {
    assert(x < size());
    assert(y < size());
    return find(x) == find(y);
  }
  size_type size(const size_type x) {
    assert(x < size());
    return siz(find(x));
  }

  bool unite(size_type x, size_type y, value_type d) {
    assert(x < size());
    assert(y < size());
    d = d + potential(x) + (-potential(y));
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (siz(x) < siz(y))
      swap(x, y), d = -d;
    siz(x) += siz(y);
    par(y) = x;
    val(y) = move(d);
    return true;
  }
};

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n,m;cin>>n>>m;
  PotentializedUnionFind<int> PUF(n);
  REP(i,m){
    int l,r,d;cin>>l>>r>>d;
    l--;r--;
    if(!PUF.unite(l,r,d)){
      if(PUF.diff(l,r) != d){
        P("No");
        return 0;
      }
    }
  }
  P("Yes");
  return 0;
}


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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
typedef long long ll;

int main(){
  while(1) {
    int a,b;
    string op;
    cin >> a >> op >> b;
    if (op == "?") break;
    int r;
    if (op == "+") {
      r = a + b;
    } else if(op == "-") {
      r = a - b;
    } else if(op == "/") {
      r = a / b;
    } else if(op == "*") {
      r = a * b;
    }
    cout << r << endl;
  }

}



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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define repN_1(i, n) for(int i = 0; i < (int)(n - 1); i++)
#define repM(i, n) for(int i = (int)(n - 1); i >= 0; i--)
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; }

int main()
{
	int n;
	int a[200005];
	int tmp;
	memset(a, 0, sizeof(a));

	cin >> n;

	rep(i, n - 1)
	{
		cin >> tmp;
		a[tmp - 1]++;
	}

	rep(i, n)
		cout << a[i] << endl;

	return 0;
}

Measured memory_bytes: 4416
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>

#define EXIT {puts("-1");return 0;}

using namespace std;

struct edge{
	int v,c;
	edge():v(0),c(0){}
	edge(int w,int d):v(w),c(d){}
};

vector<edge> vec;
vector<int> point[301];
int d[301],n,m,S,T;
char s[202][202];
queue<int> q;

inline void addedge(int x,int y,int c){point[x].push_back(vec.size()),vec.push_back(edge(y,c));point[y].push_back(vec.size()),vec.push_back(edge(x,0));}

bool bfs(){
	memset(d,0,sizeof(d));
	q.push(S);
	d[S]=1;
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i:point[u]){
			edge e=vec[i];int v=e.v,c=e.c;
			if(!d[v]&&c)d[v]=d[u]+1,q.push(v);
		}
	}
	return d[T];
}

int dfs(int u,int flow){
	if(u==T)return flow;
	for(int i:point[u]){
		edge e=vec[i];int v=e.v,c=e.c,fl;
		if(d[v]==d[u]+1&&c&&(fl=dfs(v,min(c,flow)))){vec[i].c-=fl,vec[i^1].c+=fl;return fl;}
	}
	return 0;
}

int main(){
	scanf("%d%d",&n,&m);
	T=(S=n+m+1)+1;
	for(int i=1;i<=n;++i){
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;++j){
			if(s[i][j]=='o')addedge(i+m,j,1),addedge(j,i+m,1);
			if(s[i][j]=='S')addedge(S,i+m,2147483647),addedge(S,j,2147483647);
			if(s[i][j]=='T')addedge(i+m,T,2147483647),addedge(j,T,2147483647);
		}
	}
	for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(s[i][j]=='S'){for(int k=1;k<=n;++k)if(s[k][j]=='T')EXIT;for(int k=1;k<=m;++k)if(s[i][k]=='T')EXIT;}
	int ans=0;
	while(bfs()){int flow;while(flow=dfs(S,2147483647))ans+=flow;}
	printf("%d",ans);
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
#include <stdlib.h>
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
#define erep(i,l,r) for(int (i)=(l);(i)<=(r);(i)++)
#define drep(i,l,r) for(int (i)=(l);(i)>=(r);(i)--)
#define MOD 1000000007
#define ll long long
using namespace std;
int main(){
  int n;
  cin>>n;
  ll a[n],b[n],sum=0;
  
  rep(i,0,n){
    cin>>a[i];
    sum-=a[i];
  }
  rep(i,0,n){
    cin>>b[i];
    sum+=b[i];
  }
  rep(i,0,n) if(a[i]<b[i]) sum-=(b[i]-a[i]+1)/2;

  if(sum<0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 384
N,M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

first_to = []
to_dest = []

for ab in AB:
    if ab[0] == 1:
        first_to.append(ab[1])
    elif ab[1] == N:
        to_dest.append(ab[0])
first_to = set(first_to)
to_dest = set(to_dest)

for f in first_to:
    if f in to_dest:
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 103896
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 97;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

char s[N], t[N];

int main(){
  ll a, b;
  fastScan(a);
  fastScan(b);
  printf("%lld\n", (a * b) / __gcd(a, b));
  return 0;
}


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

int main()
{
	int n,m,s=0;
	cin>>n>>m;
	int a[m+1];
	
	for(int i=1;i<=m;i++)
	{
		cin>>a[i];
		s+=a[i];
	}
	s=n-s;
	if(s<0)
		cout<<"-1";
	else
		cout<<s;
	return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
int main(void){
char a;
cin >> a;
if((a == 'a') || (a == 'i') || (a == 'u') || (a == 'e') || (a == 'o'))cout << "vowel" << endl;
else cout << "consonant" << endl;
}


Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


class UnionFind:
    def __init__(self, size=None, nodes=None):
        """
        size か nodes どっちか指定。
        nodes は set、size は list を使う。
        set の最悪計算量は O(N) なので size 指定のほうが若干速い
        :param int size:
        :param collections.Iterable nodes:
        """
        assert size is not None or nodes is not None
        if size is not None:
            self._parents = [i for i in range(size)]
            self._ranks = [0 for _ in range(size)]
            self._sizes = [1 for _ in range(size)]
        else:
            self._parents = {k: k for k in nodes}
            self._ranks = {k: 0 for k in nodes}
            self._sizes = {k: 1 for k in nodes}

    def unite(self, x, y):
        """
        x が属する木と y が属する木を併合
        :param x:
        :param y:
        :return:
        """
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return

        # rank が小さい方が下
        if self._ranks[x] > self._ranks[y]:
            # x が root
            self._parents[y] = x
            self._sizes[x] += self._sizes[y]
        else:
            # y が root
            self._parents[x] = y
            self._sizes[y] += self._sizes[x]
            if self._ranks[x] == self._ranks[y]:
                self._ranks[y] += 1

    def root(self, x):
        """
        x が属する木の root
        :param x:
        :return:
        """
        if self._parents[x] == x:
            return x
        self._parents[x] = self.root(self._parents[x])
        return self._parents[x]

    def size(self, x):
        """
        x が属する木のノード数
        :param x:
        :return:
        """
        return self._sizes[self.root(x)]


N, M = list(map(int, sys.stdin.readline().split()))
uf = UnionFind(size=N + M + 1)
for i in range(N):
    _, *L = list(map(int, sys.stdin.readline().split()))
    for lang in L:
        uf.unite(i, N + lang)

ok = True
root = uf.root(0)
for i in range(N):
    ok &= root == uf.root(i)
if ok:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 24300
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int n = scanner.nextInt();
        double tmp = 0;
        double sum = 0;
        for(int i=0;i<n;i++) {
        	tmp = scanner.nextDouble();
        	sum += (1/tmp);
        }
        System.out.println(1/sum);

    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

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

int main() {
  int N; cin >> N;
  switch (N) {
    case 3:
      cout << "2 5 63" << endl; return 0;
    case 4:
      cout << "2 5 20 63" << endl; return 0;
    case 5:
      cout << "2 5 20 30 63" << endl; return 0;
    default:
      int s = 0, m = 0, cur = 0, loop[] = {0, 2, 3, 4};
      set<int> st;
      for (int i = 0; i < N; ++i) {
        if (++cur % 4 == 0) m += 6;
        int n = m + loop[cur % 4];
        st.insert(n);
        s += n;
      }
      switch (s % 6) {
        case 2:
          st.erase(8); st.insert(m + 6); break;
        case 3:
          st.erase(9); st.insert(m + 6); break;
        case 5:
          st.erase(9); st.insert(m + loop[3]); break;
        default:
          break;
      }
      for (auto itr = begin(st); itr != end(st); ++itr) {
        cout << ( (itr == begin(st)) ? "" : " " ) << *itr;
      }
      cout << endl;
  }
  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define mod 1000000007
#define eps 0.000000001
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<" "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double PI = acos(-1.0);
void solve(int u, int n, vector<vector<int>> &adj, vector<bool> &vis, vector<int> &dist, vector<int> &ans)
{

    dist[u] = 0;
    set<pair<int, int>> q;
    q.insert(make_pair(0, u));
    while(!q.empty())
    {
        int v = q.begin()->second;
        q.erase(q.begin());
        vis[v] = true;
        for(int x : adj[v])
        {
            if(!vis[x] && dist[v] + 1 < dist[x])
            {
                ans[x] = v;
                q.erase(make_pair(dist[x], x));
                dist[x] = dist[v] + 1;
                q.insert(make_pair(dist[x], x));
            }
        }
    }

}

void cp()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj(n + 1);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    vector<int> dist(n + 1, INT_MAX), ans(n + 1, -1);
    vector<bool> vis(n + 1, false);
    solve(1, n, adj, vis, dist, ans);
    for(int i = 2; i < sz(dist); i++)
    {
        if(dist[i] == INT_MAX)
        {
            cout << "No";
            return;
        }
    }
    cout << "Yes\n";
    for(int i = 2; i <= n; i++)
        cout << ans[i] << endl;
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 14716
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
    long long int X ,Y;
    cin >> X >> Y;
    long long int sum=0;
    while(Y>=X){X*=2;sum++;}
    cout << sum<<endl;
	return 0;
}

Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int base = 0;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int h; cin >> h;
        base = min(base, h);
        // h -= base;
        // ans += h;
        ans += h - base;
        base = h;
    }
    cout << ans << '\n';
}


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

typedef long long ll;
using namespace std;
const int mod = 1000000007;

int main() {

    int N; cin >> N;
    int A; cin >> A;

    cout << (N + A - 1) / A << '\n';



}



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

ll solve(int n, string s) {
  vector<int> w(n, 0), e(n, 0);
  if(s[0] == 'W') {
    w[0] = 1;
  } else {
    e[0] = 1;
  }
  for(int i=1;i<n;i++) {
    if(s[i] == 'W') {
      w[i] = w[i-1] + 1;
      e[i] = e[i-1];
    } else {
      e[i] = e[i-1] + 1;
      w[i] = w[i-1];
    }
  }
  int res = min(numeric_limits<int>::max(), e[n-1] - e[0]);
  for(int i=1;i<n-1;i++) {
    res = min(res, w[i-1] + e[n-1] - e[i]);
  }
  res = min(res, w[n-2]);
  return res;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  cout << solve(n, s);
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	i64 n, x, d; scanf("%lld%lld%lld", &n, &x, &d);
	i64 m = std::abs(2 * d);

	if(x == 0 and d == 0) {
		printf("1\n");
		return 0;
	}
	if(d == 0) {
		printf("%lld\n", n + 1);
		return 0;
	}

	auto calc = [&](i64 l, i64 r) { return (l + r) * (r - l + 1) / 2LL; };
	auto tan = [&](i64 t) { return (t % m + m) % m; };
	
	std::map<int, std::vector<std::pair<i64, i64>>> mp;
	for(int k = 1; k < n; k++) {
		i64 X = (2 * k - n) * x;
		i64 L = X + d * (calc(0, k - 1) - calc(k, n - 1));
		i64 R = X + d * (calc(n - k, n - 1) - calc(0, n - k - 1));
		if(!(L < R)) std::swap(L, R);
		
		mp[tan(L)].push_back({L, R});
	}
	{
		i64 sum = 0;
		for(i64 i = 0; i < n; i++) sum -= x + i * d;
		mp[tan(sum)].push_back({sum, sum});

		sum *= -1;
		mp[tan(sum)].push_back({sum, sum});
	}

	i64 ans = 0;
	for(auto e: mp) {
		std::vector<std::pair<i64, i64>> vec = e.second;
		sort(begin(vec), end(vec));

		std::stack<std::pair<i64, i64>> st; st.push(vec[0]);
		for(auto p: vec) {
			auto& q = st.top();

			if(p.first <= q.second) q.second = std::max(q.second, p.second);
			else st.push(p);
		}

		while(!st.empty()) {
			auto p = st.top(); st.pop();
			
			ans += (p.second - p.first) / m + 1;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 22144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    string s;
    cin>>s;
    int n=s.size();
    rep(i,n){
        if(s[i]=='?') s[i]='D';
    }

    cout<<s<<endl;
    
}


 

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

bool judge(string s){
	string s1 = s;
	reverse(s1.begin(),s1.end());
	if(s1 == s)
		return true;
	else
		return false;
}
int main(){
	string s;
	cin >> s;
	int n = s.length();
	if(judge(s) && judge(s.substr(0,(n-1)/2)))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr int MOD_TYPE = 2;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

#pragma endregion

void solve()
{
  int n;
  string s;
  cin >> n >> s;
  ll cnt[3] = {};
  rep(i, n)
  {
    cnt[s[i] % 3]++;
  }

  ll ans = 1;
  rep(i, 3) ans *= cnt[i];
  rep(i, n) REP(j, i + 1, n)
  {
    int k = j + (j - i);
    if (k >= n)
      continue;
    if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i])
      ans--;
  }
  cout << ans << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  solve();
  return 0;
}


Measured memory_bytes: 3624
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

k = I()
s = S()
l = len(s)
n = k + l + 1
fac = [1] * (n + 1)
inv = [1] * (n + 1)
twentyFive = [1] * (n + 1)
twentySix = [1] * (n + 1)
for j in range(1, n + 1):
    fac[j] = fac[j-1] * j % mod
    twentyFive[j] = twentyFive[j - 1] * 25 % mod
    twentySix[j] = twentySix[j - 1] * 26 % mod


inv[n] = pow(fac[n], mod-2, mod)
for j in range(n-1, -1, -1):
    inv[j] = inv[j+1] * (j+1) % mod


def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod




ans = 0
for i in range(k + 1):
    ans += comb(l - 1 + i, i) * twentyFive[i] % mod * twentySix[k - i] % mod
    ans %= mod

print(ans)



Measured memory_bytes: 164128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(int i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

int main(void){
  int N;cin >> N;
  int h[N];
  REP(i,N)cin >> h[i];
  //dp[i];i+1番目にたどり着くまでに支払うコストの総和の最小値
  ll dp[N];
  dp[0] = 0;
  REP(i,N-1){
    dp[i+1] = dp[i]+abs(h[i+1]-h[i]);
    if(i==0)continue;
    dp[i+1] = min(dp[i+1],dp[i-1]+abs(h[i+1]-h[i-1]));
  }
  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1408
# from sys import stdin, stdout
n,capacity=map(int,input().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,input().split())
dp=[[0]*(capacity+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,capacity+1):
        if(weights[i-1]<=j):
            dp[i][j]=max(values[i-1]+dp[i-1][j-weights[i-1]],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][capacity])

Measured memory_bytes: 147328
from statistics import median
N=int(input())
A,B=[],[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a);B.append(b)
mA=median(A);mB=median(B)
if N%2:
    ans=int(mB-mA)+1
else:
    if mA//1==mA and mB//1==mB:
        ans=int(mB-mA)*2+1
    elif mA//1!=mA and mB//1==mB:
        ans=(mB-(mA//1))*2
    elif mA//1==mA and mB//1!=mB:
        ans=((mB//1+1)-mA)*2
    else:
        ans=int(mB-mA)*2+1
print(int(ans))

Measured memory_bytes: 28984
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)
 
 
int main(){
    int n,d;
    cin>>n>>d;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
     
    int ans = 0;
    rep(i,n){
        if(v[i]>d)ans+=v[i]-d;
    }
 
    if(ans<=0)cout<<"kusoge"<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 3092
//const int K = 18;
//ll pow10[K];
//void _(){
//    pow10[0] = 1;
//    rep(i,1,K-1)
//        pow10[i] = 10*pow10[i-1];
//    int d;
//    cin >> d;
//    ll ans = 0;
//    rep(n,2,K){
//        vl sz;
//        rep(i,0,n/2-1)
//            sz.pb(-pow10[i]+pow10[n-i-1]);
//        map<ll,ll> ways;
//        ways[d] = 1;
//        rep(i,0,sz(sz)-1){
//            map<ll,ll> nxt;
//            for(auto _ : ways){
//                ll d = _.X;
//                ll times = d/sz[i];
//                rep(t,times-1,times+1){
//                    if(abs(t) > 9 || (abs(t) == 9 && i==0)) continue;
//                    ll d = _.X-sz[i]*t;
//                    if(i == 0)
//                        nxt[d] += _.Y*(9-abs(t));
//                    else
//                        nxt[d] += _.Y*(10-abs(t));
//                }
//            }
//            ways = nxt;
//        }
//        if(n%2 == 1)
//            ways[0] *= 10;
//        ans += ways[0];
//    }
//    print(ans);
//}
//
#include <map>
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define pb push_back
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define X first
#define Y second
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
T1 void print(T x, string end = "\n"){
    cout << x << end;
}
const int K = 18;
ll pow10[K];
void _(){
    pow10[0] = 1;
    rep(i,1,K-1)
        pow10[i] = 10*pow10[i-1];
    int d;
    cin >> d;
    ll ans = 0;
    rep(n,2,K){
        vl sz;
        rep(i,0,n/2-1)
            sz.pb(-pow10[i]+pow10[n-i-1]);
        map<ll,ll> ways;
        ways[d] = 1;
        rep(i,0,sz(sz)-1){
            map<ll,ll> nxt;
            for(auto _ : ways){
                ll d = _.X;
                ll times = d/sz[i];
                rep(t,times-1,times+1){
                    if(abs(t) > 9 || (abs(t) == 9 && i==0)) continue;
                    ll d = _.X-sz[i]*t;
                    if(i == 0)
                        nxt[d] += _.Y*(9-abs(t));
                    else
                        nxt[d] += _.Y*(10-abs(t));
                }
            }
            ways = nxt;
        }
        if(n%2 == 1)
            ways[0] *= 10;
        ans += ways[0];
    }
    print(ans);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        _();
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	998244353

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

using ipair = pair<int, pair<int, int>>;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; };

int main()
{
	int n, m;
	cin >> n >> m;
	map<int, list<int>> e;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		if (e.find(a) == e.end())
			e[a] = list<int>(1, b);
		else
			e[a].push_back(b);
		if (e.find(b) == e.end())
			e[b] = list<int>(1, a);
		else
			e[b].push_back(a);
	}
	const int maxa = 100000000;
	vector<pair<int, int>> d(n, make_pair(maxa, maxa));
	d[0] = make_pair(0, 0);
	priority_queue<ipair, vector<ipair>, greater<ipair>> q; 
	for (auto p : e[0])
		q.push(make_pair(1, make_pair(0, p)));

	while (!q.empty())
	{
		pair<int, int> pos = q.top().second;
		if (d[pos.second].first <= q.top().first)
		{
			q.pop();
			continue;
		}
		d[pos.second] = make_pair(q.top().first, pos.first);
		q.pop();
		for (auto p : e[pos.second])
			if (d[p].first == maxa)
				q.push(make_pair(d[pos.second].first + 1, make_pair(pos.second, p)));
	}

	printf("Yes\n");

	for (int i = 1; i < n; i++)
		printf("%d\n", d[i].second + 1);

	return 0;
}

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

ll gcd(ll a, ll b){
  if(b==0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}

int main(){
  int x,y;
  cin>>x>>y;
  for(int i=0;i<1000;i++){
    for(int j=0;j<1000;j++){
      if(2*i+4*j==y&&i+j==x){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3632
//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \\#################\\
//   \\#################\\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) (cerr<<#x<<" = "<<(x)<<'\n')
#define all(v) begin(v),end(v)
#define siz(v) (ll(v.size()))
#define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
#define pb emplace_back
#define ff first
#define ss second
#define mid (l+(r-l>>1))
#define mem(v,x) memset(v,x,sizeof v)

using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
typedef pair<ll,ll> pll;
template <typename T> using rkt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-9;
constexpr ll N = 1000025, INF = 1e18, MOD = 998244353, K = 63;
constexpr inline ll cdiv(ll x, ll m) { return (x+m-1)/m; } // ceiling divide, x/m for flooring divide
template <typename T> void M(T &x, ll m = MOD){x%=m; if(x<0) x+=m;}

ll w[N],cnt[N],n,v;
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    w[1] = 1;
    for(int i = 2; i < N; i++) w[i] = (MOD-MOD/i)*w[MOD%i]%MOD;
    for(int i = 1; i < N; i++) for(int j = i*2; j < N; j += i) w[j] = (w[j]-w[i]+MOD)%MOD;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> v, cnt[v]++;
    for(int i = 1; i < N; i++) cnt[i] = cnt[i]*i%MOD;
    ll res = 0;
    for(int d = 1; d < N; d++) {
        ll sum = 0;
        for(int j = d; j < N; j += d) if(cnt[j]) {
            res = (res+w[d]*cnt[j]%MOD*sum%MOD)%MOD;
            res = (res+(cnt[j]*(cnt[j]-j)/2)%MOD*w[d]%MOD)%MOD;
            sum = (sum+cnt[j])%MOD;
        }
    }
    cout << res << '\n';
}


Measured memory_bytes: 15872
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    u64 N;
    cin >> N;
    u64 ans = (N & 1) ? (N - 1) / 2 : (N - 2) / 2;

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long long LL;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N, M;
	cin >> N >> M;
	if (N == M)cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

struct info{
    int n;
    int p;
    int r;
};

int main(){
    int k = 0;
    struct info inp[105];
    while(scanf("%d%*c%d",&inp[k].n, &inp[k].p), inp[k].n||inp[k].p) k++;
    rep(i,k){
        rep(j,k){
            if(inp[j].p < inp[j + 1].p){
                struct info g = inp[j]; inp[j] = inp[j + 1]; inp[j + 1] = g;
            }
        }
    }
    int rank = 1;
    rep(i,k){
        inp[i].r = rank;
        if(inp[i].p != inp[i + 1].p) rank++;
    }
    int inr;
    while(cin >> inr){
        rep(i, k){
            if(inp[i].n == inr)
                cout << inp[i].r << endl;
        }
    }
}

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

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

    int size = sz(s);

    int ans = 0;
    for(int i = 0; i < size/2; i++){
        if(s.at(i)!=s.at(size-1-i))ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
use std::io::prelude::*;

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

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

fn main() {
    let n: usize = input();
    let m: usize = input();
    let ab: Vec<(usize, usize)> = (0..m).map(|_| (input(), input())).collect();

    let mut uf = UnionFind::new(n);
    let mut ans = vec![0; m];
    ans[m - 1] = n * (n - 1) / 2;
    for i in (1..m).rev() {
        let (a, b) = ab[i];
        let (a, b) = (a - 1, b - 1);
        let na = uf.size(a);
        let nb = uf.size(b);
        if uf.union(a, b) {
            ans[i - 1] = ans[i] - na * nb;
        } else {
            ans[i - 1] = ans[i];
        }
    }

    with_stdout_lock(|mut w| {
        for a in ans {
            writeln!(w, "{}", a).unwrap();
        }
    });
}

struct UnionFind {
    parent: Vec<usize>,
    size: Vec<usize>,
}
impl UnionFind {
    fn new(n: usize) -> UnionFind {
        UnionFind {
            parent: (0..n).collect(),
            size: vec![1; n],
        }
    }
    fn find(&mut self, x: usize) -> usize {
        if self.parent[x] == x {
            x
        } else {
            let p = self.parent[x];
            self.parent[x] = self.find(p);
            self.parent[x]
        }
    }
    fn union(&mut self, x: usize, y: usize) -> bool {
        let mut x = self.find(x);
        let mut y = self.find(y);
        if x == y {
            false
        } else {
            if self.size[x] < self.size[y] {
                std::mem::swap(&mut x, &mut y);
            }
            self.parent[y] = x;
            self.size[x] += self.size[y];
            true
        }
    }
    fn size(&mut self, x: usize) -> usize {
        let p = self.find(x);
        self.size[p]
    }
}


Measured memory_bytes: 9468
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count=0;
		for (int i=1;i<=n;i+=2) {
			int uoc = 0;
			for (int j=1;j<=n;j++) {
				if (i%j==0) uoc++;
			}
			if (uoc==8) count++;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 20948
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	ar := make(ress, n)
	for i := range ar {
		var s string
		var p int
		fmt.Scan(&s, &p)
		v := res{s: s, p: p, n: i + 1}
		ar[i] = v
	}
	sort.Sort(ar)
	for _, v := range ar {
		fmt.Println(v.n)
	}
}

type res struct {
	s string
	p int
	n int
}

type ress []res

func (d ress) Len() int {
	return len(d)
}

func (d ress) Swap(i, j int) {
	d[i], d[j] = d[j], d[i]
}

func (d ress) Less(i, j int) bool {
	if d[i].s == d[j].s {
		return d[i].p > d[j].p
	}
	return d[i].s < d[j].s
}


Measured memory_bytes: 512