akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<map>
#include<set>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)
#define f first
#define s second

#ifdef __BORLANDC__
	typedef __int64 ll;
#else
	typedef long long ll;
#endif

typedef pair<ll,ll> pii;

const int N = 7;
const int M = 7;
const int W = 11111;
const int T = 11111;
const ll INF = 1e16;

int n,m,w,t;

pii item[M];
int shop[N][M];
pii pos[N];

map<string,int> dict;


bool Contain(int state, int i){
	return (state&(1<<i))>0;
}


ll memo[(1<<N)][N];

void InitMemo(){
	rep(i,(1<<N))rep(j,N)memo[i][j]=-1;
}


ll GetRoot(int state, int num){
	if(state==0)return 0;
	if(state==(1<<num))return abs(pos[num].f) + abs(pos[num].s);
	if(memo[state][num]!=-1)return memo[state][num];
	
	ll ret = INF;
	
	state -= (1<<num);
	
	rep(i,n){
		if(Contain(state,i)){
			int dist = abs(pos[num].f - pos[i].f) + abs(pos[num].s - pos[i].s);
			ret = min(ret, GetRoot(state, i) + dist);
		}
	}
	
	
	return memo[state][num] = ret;
}

ll GetTime(int state){
	
	if(state==0)return false;
	
	ll ans = INF;
	
	rep(i,n){
		if(Contain(state,i)){
			ans = min(ans, GetRoot(state,i) + abs(pos[i].f)+abs(pos[i].s));
		}
	}
	
	return ans;
}


ll GetValue(int state){
	
	int has[M] = {0};
	
	rep(i,n){
		if(!Contain(state,i))continue;
		rep(j,m){
			has[j] = max(has[j], shop[i][j]);
		}
	}
	
	
	ll dp[W]={0};
	ll ans = 0;
	
	rep(i,w+1){
		rep(j,m){
			if(i+item[j].f > w)continue;
			dp[(int)(i+item[j].f)] = max(dp[(int)(i+item[j].f)], dp[i]+has[j]);
			
		}
		ans = max(ans, dp[i]);
	}
	
	return ans;
}


vector<pii> GetCand(){
	
	vector<pii> ret;
	
	rep(i,(1<<n)){
		ll a = GetTime(i);
		ll b = GetValue(i);
		
		if(a>=INF)continue;
		ret.push_back(pii(a,b));
	}
	
	return ret;
}

ll solve(){
	vector<pii> cand = GetCand();
	
	/*
	rep(i,cand.size()){
		cout<<"***"<<cand[i].f<<" "<<cand[i].s<<endl;
	}
	*/
	
	
	ll dp[T] = {0};
	ll ans = 0;
	rep(i,t+1){
		rep(j,cand.size()){
			int a = cand[j].f;
			int b  =cand[j].s;
			if(i+a>t)continue;
			dp[i+a] = max(dp[i+a], dp[i]+b);
			
		}
		ans = max(ans,dp[i]);
	}
	
	return ans;
}


bool input(){
	cin>>n>>m>>w>>t;
	
	rep(i,m){
		string s;
		cin>>s>>item[i].f>>item[i].s;
		
		dict[s] = i;
	}
	
	rep(i,n){
		int a;
		cin>>a;
		cin>>pos[i].f>>pos[i].s;
		rep(j,m)shop[i][j]=0;
		rep(j,a){
			string s;
			int p;
			cin>>s>>p;
			int num = dict[s];
			shop[i][num] = item[num].s-p;
		}
	}
	
	
	return true;
}


int main(){
	
	InitMemo();
	
	
	input();
	
	
	cout<<solve()<<endl;
}

Measured memory_bytes: 1420
import bisect

N = int(input())
L = [int(a) for a in input().split()]

L.sort()

num_triangles = 0
for i in range(0, N - 2): # 0, 1, ..., N - 3
    for j in range(i + 1, N - 1): # i+1, i+2, ..., N-2
        num_triangles += bisect.bisect_left(L[j + 1:N], L[i] + L[j])

print(num_triangles)

Measured memory_bytes: 50780
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

const int INF=1<<29;

const int V_MAX=300;
const int E_MAX=V_MAX-1;
const int T_MAX=10000;

struct edge{ int v,cost,capa,val; };

int n;
vector<edge> G[V_MAX]; // tree

vector< pair<edge,int> > order; // <<to,cost,capa,val>,forward or backward>

void dfs(int u,int pre){
	int cost_parent=0,capa_parent=0,val_parent=0;

	rep(i,G[u].size()){
		int v=G[u][i].v,cost=G[u][i].cost,capa=G[u][i].capa,val=G[u][i].val;
		if(v!=pre){
			order.push_back(make_pair((edge){u,cost,capa,val},0)); // forward
			dfs(v,u);
		}
		else{
			cost_parent=cost;
			capa_parent=capa;
			val_parent=val;
		}
	}

	order.push_back(make_pair((edge){u,cost_parent,capa_parent,val_parent},1)); // backward
}

int main(){
	int T; scanf("%d%d",&n,&T);
	rep(u,n) G[u].clear();
	rep(i,n-1){
		int u,v,cost,capa,val;
		scanf("%d%d%d%d%d",&u,&v,&cost,&capa,&val); u--; v--;
		G[u].push_back((edge){v,cost,capa,val});
		G[v].push_back((edge){u,cost,capa,val});
	}

	order.clear();
	dfs(0,-1);

	int m=order.size();
	static int pre[V_MAX+E_MAX];
	rep(i,m){
		pre[i]=-1;
		int u=order[i].first.v;
		rep(j,i){
			int v=order[j].first.v;
			if(u==v) pre[i]=j;
		}
	}

	static int dp[V_MAX+E_MAX][T_MAX+1];
	rep(i,m) rep(j,T+1) dp[i][j]=-INF;
	dp[0][0]=0;
	for(int i=1;i<m;i++){
		int cost=order[i-1].first.cost;
		int capa=order[i-1].first.capa;
		int val=order[i-1].first.val;
		int dir=order[i-1].second;

		rep(j,T+1) if(pre[i]!=-1) dp[i][j]=max(dp[i][j],dp[pre[i]][j]);

		if(dir==0){ // forward
			if(capa%2==1){
				for(int j=(capa+1)*cost;j<=T;j++){
					dp[i][j]=max(dp[i][j],dp[i-1][j-(capa+1)*cost]+capa*val);
				}
				capa--;
			}

			if(capa==0){
				for(int j=2*cost;j<=T;j++) dp[i][j]=max(dp[i][j],dp[i-1][j-2*cost]);
			}
			else{ // capa>=2
				capa-=2;
				for(int c=2;capa>0;c*=2){ // O(log capa) 個の商品に分割
					c=min(c,capa);
					for(int j=T;j>=c*cost;j--){
						dp[i-1][j]=max(dp[i-1][j],dp[i-1][j-c*cost]+c*val);
					}
					capa-=c;
				}

				for(int j=2*cost;j<=T;j++) dp[i][j]=max(dp[i][j],dp[i-1][j-2*cost]+2*val);
			}
		}
		else{ // backward
			rep(j,T+1) dp[i][j]=max(dp[i][j],dp[i-1][j]);
		}
	}

	printf("%d\n",*max_element(dp[m-1],dp[m-1]+T+1));

	return 0;
}

Measured memory_bytes: 24544
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
//const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=405,mod=10007;
ll n,C[M][M],dp[101][M][8][4];

int main(){
	cin>>n;
	C[0][0]++;
	for(int i=0;i<M-1;i++) for(int j=0;j<=i;j++){
		(C[i+1][j]+=C[i][j])%=mod;
		(C[i+1][j+1]+=C[i][j])%=mod;
	}
	dp[0][0][0][0]++;
	int S=0,N,N_=0;
	for(int i=0;i<n;i++){
		cin>>N;
		ll t=1;
		for(int j=1;j<=N;j++) (t*=j)%=mod;
		for(int j=0;j<=S+1;j++) for(int k=0;k<8;k++) for(int l=0;l<4;l++) for(int x=1;x<=min(S+1,N);x++) if(dp[i][j][k][l]){
			int q=2*(N_-l)-k;
			for(int J=0;J<=min(x,j);J++) for(int K=0;K<=min(x-J,k);K++) for(int L=0;L<=min(x-J-K,l);L++) for(int Q=0;Q<=min(x-J-K-L,q);Q++){
				(dp[i+1][j+k+l-J-K-L][K+2*L+Q][N-x]+=t*C[N-1][x-1]*C[j][J]*C[k][K]*C[l][L]*C[q][Q]*C[S-j-k-l-q+1][x-J-K-L-Q]*dp[i][j][k][l])%=mod;
			}
		}
		S+=N;N_=N;
	}
	cout<<dp[n][0][0][0]<<endl;
}



Measured memory_bytes: 9720
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <cstdio>



int main(){
  int n,m,ans=0;
  
  int A[100000];
  scanf("%d",&n);
  
  for(int i=0;i<n;i++)
    scanf("%d",A+i);
  
  scanf("%d",&m);
  
  for(int i=0;i<m;i++){
    int a;
    scanf("%d",&a);

    for(int j=0;j<n;j++){
      if(A[j]==a){
        ans++;
        break;
      }
    }

  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 3064
x = int(input())
ans = (-1,-1)
gojo = [i**5 for i in range(200)]
for i in range(200):
    for j in range(200):
        if gojo[i]+gojo[j]==x:
            ans = (i,-j)
        if gojo [i]- gojo[j]==x:
            ans = (i,j)
        
print(ans[0],ans[1])

Measured memory_bytes: 9148
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


struct man{
  ll num;
  ll money;
};

int main()
{
  int n;
  while(true)
    {
      cin>>n;
      if(n==0)
	exit(0);
      vector<man> d;
      d.clear();
      for(int i=0;i<n;i++)
	{
	  ll num,a,b;
	  bool ch=false;
	  cin>>num;
	  cin>>a;
	  cin>>b;
	  for(int j=0;j<d.size();j++)
	    {
	      if(d[j].num==num)
		{
		d[j].money=d[j].money+a*b;
		ch=true;
		break;
		}
	    }
	  if(ch==false)
	    {
	      struct man x;
	      x.num=num;
	      x.money=a*b;
	      d.push_back(x);
	    }
	}
      int count=0;
      for(int j=0;j<d.size();j++)
	if(d[j].money>=1000000)
	  {
	    cout<<d[j].num <<endl;
	    //    cout<<d[j].num << "   "<< d[j].money<<endl;
	    count++;
	  }
      if(count<1)
	cout<<"NA"<<endl;

    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define MAXN 200 + 5
const long long INF = 1LL << 60;
const int inf = 1 << 30;


int main(){
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " <<  y << endl;
}
     


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
int r,g,b,a;
scanf("%d",&r);
scanf("%d",&g);
scanf("%d",&b);
a=100*r+10*g+b;
if(a%4==0){
  printf("YES\n");
}else{
  printf("NO\n");
}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

const ll mod = 1000000007;
const int N = 2e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n, q;
multiset<int> e;
void init() {
	e.clear();
}
struct Node {
	int t, pos, fg;
	bool operator < (const Node c) const {
		return t < c.t;
	}
} node[N<<1];
int main() {
	while(~scanf("%d%d", &n, &q)) {
		init();
		int len = 0;
		rep(i, 0, n) {
			int x, y, c; scanf("%d%d%d", &x, &y, &c);
			node[len].t = x - c;
			node[len].pos = c;
			node[len++].fg = 0;
			node[len].t = y - c;
			node[len].pos = c;
			node[len++].fg = 1;
		}
		sort(node, node + len);
		int j = 0;
		rep(i, 0, q) {
			int x; scanf("%d", &x);
			while(j < len) {
				if(node[j].t <= x) {
					if(!node[j].fg) e.insert(node[j].pos);
					else e.erase(e.find(node[j].pos));
				} else break;
				j++;
			}
			if(!sz(e)) printf("-1\n");
			else printf("%d\n", *e.begin());
		}
	}
    return 0;
}


Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

vvi jisyo;
void dfs(vi ans, vi res)
{
    if (res.size() == 0)
    {
        jisyo.push_back(ans);
    }
    else
    {
        REP(i, res.size())
        {
            vi ares{ans};
            vi tres{res};
            ares.push_back(tres.at(i));
            tres.erase(tres.begin() + i);
            dfs(ares, tres);
        }
    }
}

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

    vi tmp;
    REP(j, N)
    tmp.push_back(j + 1);

    dfs({}, tmp);

    vi a(N);
    vi b(N);
    REP(i, N)
    cin >> a.at(i);
    REP(i, N)
    cin >> b.at(i);

    int aa, bb;
    REP(i, jisyo.size())
    {
        if (jisyo.at(i) == a)
            aa = i;
        if (jisyo.at(i) == b)
            bb = i;
    }
    cout << abs(aa - bb) << endl;
    // system("pause");
    return 0;
}

Measured memory_bytes: 4408
#include <stdio.h>
int main()
{

  int x, y, r = 0, gcd;

  scanf("%d%d",&x,&y);
  if(x == y) gcd = x;
  if(x > y){
    while((r = x % y) != 0){
      x = y;
      y = r;
    }
    gcd = y;
  }
  if(y > x){
    while((r = y % x) != 0){
      y = x;
      x = r;
    }
    gcd = x;
  }
  printf("%d\n",gcd);
  return 0;
}

Measured memory_bytes: 592
import java.util.*;

public class Main {
  // constant
  static final int MAX_INT = 1 << 30;

  // global variables
  static int[] dists;

  // inner classes

  static class QComp implements Comparator<Integer> {
    public int compare(Integer i0, Integer i1) {
      int cmpd = dists[i0] - dists[i1];
      return  (cmpd != 0) ? cmpd : i0 - i1;
    }
  }

  // main
  public static final void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int k = sc.nextInt();

    int[][] taxis = new int[n][2];
    for (int i = 0; i < n; i++) {
      taxis[i][0] = sc.nextInt();
      taxis[i][1] = sc.nextInt();
    }

    ArrayList<ArrayList<Integer>> nbrs = new ArrayList<ArrayList<Integer>>();
    for (int i = 0; i < n; i++)
      nbrs.add(new ArrayList<Integer>());

    for (int i = 0; i < k; i++) {
      int ai = sc.nextInt() - 1;
      int bi = sc.nextInt() - 1;
      nbrs.get(ai).add(bi);
      nbrs.get(bi).add(ai);
    }

    ArrayList<ArrayList<Integer>> tnbrs = new ArrayList<ArrayList<Integer>>();
    for (int i = 0; i < n; i++)
      tnbrs.add(new ArrayList<Integer>());

    dists = new int[n];

    for (int st = 0; st < n; st++) {
      Arrays.fill(dists, MAX_INT);
      dists[st] = 0;

      ArrayList<Integer> q = new ArrayList<Integer>();
      q.add(st);

      int max_dist = taxis[st][1];
      ArrayList<Integer> tnbrst = tnbrs.get(st);

      while (! q.isEmpty()) {
        Integer ui = q.remove(0);

        int du = dists[ui];
        if (du >= max_dist) continue;

        for (Integer vi: nbrs.get(ui))
          if (dists[vi] >= MAX_INT) {
            dists[vi] = du + 1;
            q.add(vi);
            tnbrst.add(vi);
          }
      }
    }

    Arrays.fill(dists, MAX_INT);
    dists[0] = 0;

    PriorityQueue<Integer> q = new PriorityQueue<Integer>(n, new QComp());
    q.add(0);

    while (! q.isEmpty()) {
      Integer ui = q.poll();
      int u = ui.intValue();
      if (u == n - 1) break;

      int duv = dists[u] + taxis[u][0];

      for (Integer vi: tnbrs.get(u)) {
        int dv = dists[vi];
        if (dv > duv) {
          dists[vi] = duv;
          if (dv < MAX_INT) q.remove(vi);
          q.add(vi);
        }
      }
    }

    System.out.println(dists[n - 1]);
  }
}

Measured memory_bytes: 286180
// <<<<GOD>>>> lET'S gO

#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 100, MOD = 1000 * 1000 * 1000 + 7;

int sum(int a, int b) {
	a += b;
	if(a < 0)
		a += MOD;
	else if(a >= MOD)
		a -= MOD;
	return a;
}

int mul(int a, int b) {
	return 1LL * a * b % MOD;
}

int n, a, b, c, d, dp[N], to_a[N], to_b[N], to_c[N], to_d[N], from_a[N], from_b[N], from_c[N], from_d[N];
string s;

void YES() {
	cout << "Yes";
	exit(0);
}

void NO() {
	cout << "No";
	exit(0);
}

void go_to(int y) {
	memset(dp, 0, sizeof dp);
	dp[y] = 1;
	for (int i = y - 1; ~i; i--)
		if(s[i] != '#') {
			if(i + 1 < n && s[i + 1] != '#')
				dp[i] = sum(dp[i], dp[i + 1]);
			if(i + 2 < n && s[i + 2] != '#')
				dp[i] = sum(dp[i], dp[i + 2]);
		}
}

void go_from(int y) {
	memset(dp, 0, sizeof dp);
	dp[y] = 1;
	for (int i = y + 1; i < n; i++)
		if(s[i] != '#') {
			if(i - 1 >= 0 && s[i - 1] != '#')
				dp[i] = sum(dp[i], dp[i - 1]);
			if(i - 2 >= 0 && s[i - 2] != '#')
				dp[i] = sum(dp[i], dp[i - 2]);
		}
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> a >> b >> c >> d >> s;
	a--, b--, c--, d--;
	go_to(a);
	copy(dp, dp + N, to_a);
	go_from(a);
	copy(dp, dp + N, from_a);
	
	go_to(b);
	copy(dp, dp + N, to_b);
	go_from(b);
	copy(dp, dp + N, from_b);
	
	go_to(c);
	copy(dp, dp + N, to_c);
	go_from(c);
	copy(dp, dp + N, from_c);
	
	go_to(d);
	copy(dp, dp + N, to_d);
	go_from(d);
	copy(dp, dp + N, from_d);
	
	if(to_c[a] == 0 || to_d[b] == 0)
		NO();
	if(d > c)
		YES();
	set<int> st;
	for (int i = 0; i < n; i++)
		if(mul(from_a[i], to_c[i]) == from_a[c])
			st.insert(i);
	for (int i = 0; i < n; i++)
		if(from_b[i] && to_d[i] && st.find(i) == st.end())
			YES();
			
	NO();
    return 0;
}

Measured memory_bytes: 12880
N, M = map(int, input().split())

point = [[] for i in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    if b not in point[a-1]:
        point[a-1].append(b)
    if a not in point[b-1]:
        point[b-1].append(a)

ans = 0
while True:
    idx, flg = 0, 0
    for i in point:
        if len(i) == 1:
            flg = 1
            point[i[0]-1].remove(idx+1)
            point[idx] = []
            ans += 1
        idx += 1
    if flg == 0:
        break

print(ans)


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

int posv[100001];
int negv[100001];

int main(){
    int N,K;
    cin>>N>>K;
    int x[100001];
    int pos=0;
    int neg=0;
    for(int i=1;i<=N;i++){
        cin>>x[i];
        if(x[i]>=0) pos++;
    }
    neg=N-pos;

    for(int i=1;i<=pos;i++){
        posv[i]= x[i+neg];
    }
    for(int i=1;i<=neg;i++){
        negv[i]=-1*x[neg+1-i];
    }

    int MIN=1e9;
    int m=min(pos,K);
    for(int i=0;i<=m;i++){
        int num=0;
        if(K-i<=neg){
            num=((posv[i]<negv[K-i])+1)*posv[i]+((posv[i]>=negv[K-i])+1)*negv[K-i];
            MIN=min(MIN,num);
        }
    }
    cout<<MIN<<endl;

    return 0;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef string::const_iterator State;
int expression(State &begin);
int number(State&);
int factor(State&);
int term(State&);
int expression(State&);
int _or[3][3] = {{0,1,2},
                {1,1,2},
                {2,2,2}};

int _and[3][3] ={ {0,0,0},
                 {0,1,1},
                 {0,1,2}};

int _not[3] = {2,1,0};


int formula(State &begin){
  while(true){
    if(isdigit(*begin)){
      int ret = *begin - '0';
      begin++;
      return ret;
    } else if(*begin == '-'){
      begin++;
      return _not[formula(begin)];
    } else if (*begin == '(') {
      begin++;
      int ret = formula(begin);
      if(*begin == '*'){ //and
        begin++;
        ret = _and[ret][formula(begin)];
      } else if (*begin == '+') { // or
        begin++;
        ret = _or[ret][formula(begin)];
      }
      begin++;
      return ret;
    } else {
      break;
    }
  }
  return -1;
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  int n;
  while(true){
    cin >> s;
    if(s==".") break;
    n = s.size();
    VI P;
    VI Q;
    VI R;

    rep(i,n){
      if(s[i] == 'P') P.push_back(i);
      if(s[i] == 'Q') Q.push_back(i);
      if(s[i] == 'R') R.push_back(i);
    }
    int ans = 0;
    rep(p,3){
      rep(q,3){
        rep(r,3){
          rep(i,P.size()) s[P[i]] = (char)(p + '0');
          rep(i,Q.size()) s[Q[i]] = (char)(q + '0');
          rep(i,R.size()) s[R[i]] = (char)(r + '0');
          State begin = s.begin();
          int tmp = formula(begin);
          //cout << ans << endl;
          if(tmp == 2) ans++;
        }
      }
    }
    cout << ans << endl;

  }
  return 0;
}



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

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

unsigned long long str_to_int(std::string str) {
	unsigned long long ret;
	std::stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

void solve(){
	string a,b;
	cin >> a >> b;
	int num = str_to_int(a+b);
	for(int i = 1;i*i <= num;i++){
		if(num%i == 0 and i*i == num){
			P("Yes");
			return;
		}
	}
	P("No");
}

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


Measured memory_bytes: 256
#include <iostream>
int main(){
        std::string S,P="keyence";
        std::cin >> S;
        int pre=0,suf=0;
        for(int i=0; i<7; i++) {
                if(S.at(i)==P.at(i)) pre++;
                else break;
        }
        for(int i=0; i<7; i++) {
                if(S.at(S.length()-i-1)==P.at(7-i-1)) suf++;
                else break;
        }
        if(pre+suf>=7) std::cout << "YES";
        else std::cout << "NO";
        return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
def partition(A, p, r):
    x = A[r][1]
    i = p - 1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1
def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q - 1)
        quicksort(A, q + 1, r)
def isStable(A):
    for i in range(0, len(A) - 1):
        if A[i][1] == A[i + 1][1]:
            if A[i][2] > A[i + 1][2]:
                return False
    return True
n = int(input())
f = lambda a: (a[0], int(a[1]))
A = [f(readline().split()) + (i,) for i in range(n)]
quicksort(A, 0, n - 1)
print("Stable" if isStable(A) else "Not stable")
print("\n".join(f"{a} {b}" for a, b, c in A))



Measured memory_bytes: 26992
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }


        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var A = Sarray();
            var o = new Dictionary<long, long>();
            var e = new Dictionary<long, long>();
            Dictionary<long, long> t;
            o[-1] = 0;
            e[-1] = 0;
            for (var i = 0; i < A.Length; ++i)
            {
                if (i % 2 == 0)
                    t = o;
                else
                    t = e;
                if (!t.ContainsKey(A[i]))
                    t[A[i]] = 1;
                else
                    ++t[A[i]];
            }
            var oary = o.ToArray();
            Array.Sort(oary, (l, r) => (int)(r.Value - l.Value));
            long maxvo1 = oary[0].Key;
            long maxvo2 = oary[1].Key;
            var eary = e.ToArray();
            Array.Sort(eary, (l, r) => (int)(r.Value - l.Value));
            long maxve1 = eary[0].Key;
            long maxve2 = eary[1].Key;

            if (maxvo1 == maxve1)//最長が同じ文字
            {
                if (o[maxvo1] < e[maxve1])
                    N -= e[maxve1] + o[maxvo2];
                else if (e[maxve1] < o[maxvo1])
                    N -= o[maxvo1] + e[maxve2];
                else
                {
                    var max = Math.Max(o[maxvo2], e[maxve2]);
                    N -= o[maxvo1] + max;
                }
            }
            else
                N -= e[maxve1] + o[maxvo1];
            WriteLine(N);
        }
    }
}


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

bool is_rev(string s){
        string t(s.rbegin(),s.rend());
        return s == t;
}

int main(){
        string s;
        cin >> s;
        int n = s.size();

        if(is_rev(s) && is_rev(s.substr(0,(n-1)/2)) && is_rev(s.substr((n+1)/2))){
                cout << "Yes" << endl;
        }
        else{
                cout << "No" << endl;
        }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;

string to_string(int n) {
    stringstream ss;
    ss << n;
    return ss.str();
}

string conv(string s) {
    string ret = "";
    int c = 0;
    for (int i=0; i<(int)s.size(); ++i) {
        ++ c;
        if (i == (int)s.size()-1 || s[i] != s[i+1]) {
            ret += to_string(c);
            ret += s[i];
            c = 0;
        }
    }
    return ret;
}

int main() {
    int n;
    while (cin >> n, n) {
        string s;
        cin >> s;
        for (int i=0; i<n; ++i) {
            s = conv(s);
        }
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 1360
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    long long x, y;
    scanf("%lld%lld", &x, &y);
    if (x == 1 || y == 1)
        printf("1");
    else
    {
        long long ans = x * y;
        printf("%lld", (ans + 1) / 2);
    }
    return 0;
}

Measured memory_bytes: 256
program distribute_numbers
  implicit none
  integer, parameter :: k = 38, n = k*(k-1)+1, p = k-1
  integer :: i, d, s, a(k)
  write(*,'(i0,x,i0)') n, k
  do i = 0, p
    do s = 1, p
      a(s) = i*p+s
    end do
    a(k) = n
    call output()
  end do
  do d = 0, p-1
    do s = 0, p-1
      do i = 0, p-1
        a(i+1) = i*p+1+mod(d*i+s,p)
      end do
      a(k) = p**2+1+d
      call output()
    end do
  end do
contains
  subroutine output()
    integer :: i
    write(*,'(i0)',advance='no') a(1)
    do i = 2, k
      write(*,'(x,i0)',advance='no') a(i)
    end do
    write(*,*)
  end
end program distribute_numbers

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define int long long

inline int read () {
    int ret = 0, t = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') t = -1, c = getchar();
    while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
    return ret * t;
}

const int MAXN = 2020;
const int mod = 1e9 + 7;

int qpow (int x, int y) {
    int ret = 1;
    while (y) {
        if (y & 1) ret = ret * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return ret;
}
int inv (int x) { return qpow(x, mod - 2); }

int fac[MAXN * MAXN];
int binom (int x, int y) { return fac[x] * inv(fac[y]) % mod * inv(fac[x - y]) % mod; }

int n, k;
int dp[MAXN][MAXN];

signed main () {
    n = read(), k = read();
    if (k == 1) { puts("1"); return 0; }
    int i, j;
    dp[0][0] = fac[0] = 1;
    for (i = 1; i <= n * k; i++) fac[i] = fac[i - 1] * i % mod;
    for (i = 1; i <= n; i++) for (j = 0; j <= i; j++) {
        dp[i][j] = dp[i - 1][j];
        if (j) 
            dp[i][j] += dp[i][j - 1] * (n - j + 1) % mod * binom(n * k - i - 1 - (j - 1) * (k - 1), k - 2) % mod, dp[i][j] %= mod;
    }
    printf("%lld\n", dp[n][n]);
    return 0;
}

Measured memory_bytes: 63744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RAnK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int maxn = 1e5+233;
char s[maxn];
int n,last[maxn];
int main(){
	scanf("%s",s+1);
	n = strlen(s+1);
	Rep(i,1,n){
		s[i] -= '0';
	}
	last[n] = n;
	Dep(i,n-1,1){
		last[i] = last[i+1];
		if(s[i]) last[i] = i;
	}
	Rep(i,1,n-1){
		if(s[i] && !(s[n-i])){
			puts("-1");
			return 0;
		}
	}
	if(s[1] == 0){
		puts("-1");
		return 0;
	}
	if(s[n] == 1){
		puts("-1");
		return 0;
	}
	Rep(i,1,n-1){
		if(s[i]){
			printf("%d %d\n",i,last[i+1]);
		} else{
			printf("%d %d\n",i,last[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 1920
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}

//end of jonathanirvings' template v3.0.3 (BETA)

int risan;
int a,b;

void go(int a,int b,int c)
{
  if (a <= b) MIN(risan,b-a + c);
}

int main()
{
  scanf("%d %d",&a,&b);
  risan = INF * 2;
  go(a,b,0);
  go(-a,b,1);
  go(a,-b,1);
  go(-a,-b,2);
  printf("%d\n",risan);
  return 0;
}










Measured memory_bytes: 764
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

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

  int date(int y, int m, int d) {
    --y;
    --m;
    return y * (19 * 5 + 20 * 5) + (y / 3) * 5 + m * 20 - ((y+1) % 3 != 0 ? m / 2 : 0) + d;
  }

  void run() {
    int n = ni();
    for (int i = 0; i < n; ++i) {
      int ay = 1000, am = 1, ad = 1;
      int y, m, d;
      y = ni();
      m = ni();
      d = ni();
      System.out.println(date(ay, am, ad) - date(y, m, d));
    }
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 26628
#98 C - Product and GCD 
import collections
N,P = map(int,input().split())

def Prime_Factorize(n):
    primes = []
    while n%2 == 0:
        n//=2
        primes.append(2)
    f = 3
    while f*f <= n:
        if n%f == 0:
            n//=f
            primes.append(f)
        else:
            f += 2
    if n != 1:
        primes.append(n)
    return primes
Primes = Prime_Factorize(P)

cnt = collections.Counter(Primes)

ans = 1
for key, value in cnt.items():
    if value >= N:
        num = key**(value//N)
        ans *= num
if N == 1:
    print(P)
else:
    print(ans)

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

int main() {
  int c[3][3], a[3], b[3];

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c[i][j];
    }
  }

  a[0] = 0;
  for (int j = 0; j < 3; j++) b[j] = c[0][j];

  for (int i = 1; i < 3; i++) {
    if (c[i][0]-b[0] != c[i][1]-b[1] || c[i][0]-b[0] != c[i][2]-b[2]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;

}

Measured memory_bytes: 256
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, K] = string_to_int(inputs[0])
    heights = string_to_int(inputs[1])
    return len(list(filter(lambda x: x >= K, heights)))


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


Measured memory_bytes: 13012
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin);i>(end);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}

#define ll long long
#define f first
#define s second
using namespace std;

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;

int main()
{
	// 入力
	string S;
	cin>>S;

	ll ans1=0,ans2=0;
	ll s=S.size();
	REP(i,s){
		if(i%2==0){
			if(S[i]=='0') ans2++;
			if(S[i]=='1') ans1++;
		}
		if(i%2==1){
			if(S[i]=='0') ans1++;
			if(S[i]=='1') ans2++;
		}
	}

	cout<<min(ans1,ans2)<<endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define all(c) (c).begin(),(c).end()
#define N 100002

int dp[N];
int n;
vi v(N);

int rec(int i)
{

    if(i>=n)
        return inf;
    if(i == n - 1)
        return 0;
    if(dp[i] == -1)
    {
        int ans = 0;
        ans = min(abs(v[i+1]-v[i])+rec(i+1),abs(v[i+2]-v[i])+rec(i+2));
        dp[i] = ans;
        return ans;
    }
    else
        return dp[i];
}
int32_t main()
{                
    IOS;
    
   
    memset(dp,-1,sizeof(dp));
    cin>>n;
    v[n] = 1e9;
    v[n+1] = 1e9;
    for(int i = 0;i  < n;i++)
    {
        cin>>v[i];
    }
    cout<<rec(0);
    return 0;

}

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

int main(){
  int n;
  cin>>n;
  vector<int>x(n);
  vector<int>y(n);
  for(int i=0 ; i < n ;i++){
    cin>>x[i]>>y[i];
  }
  

  cout << fixed << setprecision(10); //少数以下10桁まで表示
  
  
    double sum=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      sum+= sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])) ;
      
    }
    
    
  }


  

  cout<<sum/n *2 <<endl;

  
  
}

Measured memory_bytes: 256
import bisect

n = int(input())
a = [int(input()) for i in range(n)][::-1]
LIS = [a[0]]
for i in a[1:]:
    if i >= LIS[-1]:
        LIS.append(i)
    else:
        LIS[bisect.bisect_right(LIS, i)] = i
print(len(LIS))

Measured memory_bytes: 8472
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int len;
    cin>>s;
    int cnt=0;
    len=s.size();
    for(int i=0;i<len/2;i++)
    {
        if(s[i]!=s[len-i-1]) cnt++;
    }
    cout<<cnt<<endl;













    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

signed main() {
    int N, M;
    cin >> N >> M;
    
    vector<int> divisor;
    for (int i = 1; i * i <= M; ++i) {
        int j = M / i;
        if (i * j == M) {
            if (i == j) {
                divisor.push_back(i);
            } else {
                divisor.push_back(i);
                divisor.push_back(j);
            }
        }
    }
    int ans = 1;
    for (int i : divisor) {
        if (M >= i * N) ans = max(ans, i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#今回は行列を使用します。
#行列演算に完全勝利したコード
n = int(input())
dp = [[0, 0, 0] for i in range(n)]
h = [list(map(int, input().split())) for i in range(n)]
#print(h)
#print(dp)
for j in range(3):
    dp[0][j] = h[0][j]
for i in range(1,n):
    dp[i][0] = h[i][0]+max(dp[i-1][1], dp[i-1][2])
    dp[i][1] = h[i][1]+max(dp[i-1][2], dp[i-1][0])
    dp[i][2] = h[i][2]+max(dp[i-1][0], dp[i-1][1])
print(max(dp[-1]))


Measured memory_bytes: 74016
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll x;
int main() {
    cin>>x;

    ll ans=0;
    ans+=(x/500*1000);
    x=x%500;
    ans+=(x/5*5);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr double PI = atan2(0, -1);
struct Point {
    int x, y;
    Point() {}
    Point(int x, int y) : x(x), y(y) {}
};
bool operator<(const Point &lhs, const Point &rhs) {return lhs.x < rhs.x || lhs.x == rhs.x && lhs.y < rhs.y;}
Point operator-(const Point &lhs, const Point &rhs) {return Point(lhs.x - rhs.x, lhs.y - rhs.y);}
LL cross(const Point &lhs, const Point &rhs) {return 1LL * lhs.x * rhs.y - 1LL * lhs.y * rhs.x;}
LL dot(const Point &lhs, const Point &rhs) {return 1LL * lhs.x * rhs.x + 1LL * lhs.y * rhs.y;}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<Point> p(n);
    for (int i = 0; i < n; ++i)
        cin >> p[i].x >> p[i].y;
    vector<int> q(n);
    iota(q.begin(), q.end(), 0);
    sort(q.begin(), q.end(), [&](int i, int j) {return p[i] < p[j];});
    vector<int> hull, pts;
    vector<Point> vecs;
    for (int i = 0; i < n; ++i) {
        while ((int)pts.size() >= 2 && cross(vecs.back(), p[q[i]] - p[pts.back()]) <= 0) {
            pts.pop_back();
            vecs.pop_back();
        }
        if (!pts.empty())
            vecs.push_back(p[q[i]] - p[pts.back()]);
        pts.push_back(q[i]);
    }
    hull = pts;
    pts.clear();
    vecs.clear();
    for (int i = 0; i < n; ++i) {
        while ((int)pts.size() >= 2 && cross(vecs.back(), p[q[i]] - p[pts.back()]) >= 0) {
            pts.pop_back();
            vecs.pop_back();
        }
        if (!pts.empty())
            vecs.push_back(p[q[i]] - p[pts.back()]);
        pts.push_back(q[i]);
    }
    pts.pop_back();
    reverse(pts.begin(), pts.end());
    pts.pop_back();
    hull.insert(hull.end(), pts.begin(), pts.end());
    vector<double> ans(n);
    for (int i = 0; i < (int)hull.size(); ++i) {
        auto r = p[i == (int)hull.size() - 1 ? hull[0] : hull[i + 1]] - p[hull[i]], l = p[hull[i]] - p[i == 0 ? hull.back() : hull[i - 1]];
        ans[hull[i]] = acos(1.0 * dot(l, r) / sqrt(1.0 * dot(l, l) * dot(r, r))) / (2 * PI);
    }
    cout << setprecision(10) << fixed;
    for (auto i : ans)
        cout << i << "\n";
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,sum;
    
    while(1){ cin >> a; if(a==0) break;
    cin >> b;
    sum=0;
    for(int i=0;i<b;i++){
        cin >>c>>d;
        sum+=(d-c);
    }
    if (sum>=a) cout << "OK" <<endl;
    else cout << a-sum <<endl;
    }
}



Measured memory_bytes: 3056
A,B,N = map(int,input().split())
t = N//B
if N % B == 0:
    a = max(1,N-1)
    b = N
else:
    a = max(1,t*B - 1)
    b = N

print(max(A*a//B-A*(a//B),A*b//B-A*(b//B)))

Measured memory_bytes: 61524
class UF:
    #経路圧縮＋マージテクのunion find木
    def __init__(self,n):
        self.n = n
        self.parents = [-1] * (n+1) #1-indexedにするために１個足している
        self.rnks = [0] * (n+1)

    def find(self,n):
        if self.parents[n] < 0:
            return n
        else:
            return self.find(self.parents[n])


    def union(self,a,b):
        a_par = self.find(a)
        b_par = self.find(b)

        if a_par == b_par:
            return
        ##union by rank
        #if self.rnks[a_par] < self.rnks[b_par]: #ランクの高い方の根に低い方の根をつける　逆にしないように……！
        #    a_par,b_par = b_par,a_par
        #if self.rnks[a_par] == self.rnks[b_par]:
        #    self.rnks[a_par] += 1
        if self.size(a_par) < self.size(b_par): #parentsの値が負の数のとき、それはその木のサイズを表す。
            a_par,b_par = b_par,a_par
        self.parents[a_par] += self.parents[b_par]
        self.parents[b_par] = a_par

    def size(self,n):
        par = self.find(n)
        return abs(self.parents[par])

    def is_same(self,a,b):
        return self.find(a) == self.find(b)

def main():
    n,m = map(int,input().split())
    uf = UF(n)
    for i in range(m):
        a,b = map(int,input().split())
        uf.union(a,b)
    mx = -1
    for i in range(n):
        mx = max(uf.size(i),mx)
    print(mx)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16060
from collections import deque


x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
p.sort(reverse=True)
q = list(map(int, input().split()))
q.sort(reverse=True)
r = list(map(int, input().split()))
ans = []
ans.extend(p[:x])
ans.extend(q[:y])
ans.extend(r)
ans.sort(reverse=True)
print(sum(ans[:x+y]))


Measured memory_bytes: 23616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trace(x) clog<<#x<<": "<<x<<endl
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define pb push_back
#define mod 1000000007
#define vi vector<int>
#define si set<int>
#define pi pair<int,int>
#define li list<int>
#define fi first
#define in insert
#define se second
#define mkp make_pair
#define fr(i,n) for(i = 0 ; i < n ; i++)

long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
int main()
{
    fio
    ll n,i,j,k;
    cin>>n>>k;
    int l = 0,h = 31,mid,ans;
    while(l<=h)
    {
        mid = (l+h)/2;
        ll v = binpow(k,mid);
        if(n<= (v-1))
        {
             h = mid-1;
            ans = mid;
        }
        else{
          l = mid+1;
        }

    }

    cout<<ans;

    return 0;
}



Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<long long int>v(100);
	v[0] = 2;
	v[1] = 1;
	for (int i = 2; i <= N; i++) {
		v[i] = v[i - 1] + v[i - 2];
	}
	cout << v[N] << endl;
	return 0;
}

Measured memory_bytes: 256