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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(false);
	int N;
	vector<pll> v;
	map<pll, int> mp;

	cin >> N;
	rep(i,N){
		int x, y;
		cin >> x >> y;
		v.emplace_back(x, y);
		mp[pii(x,y)] = i;
	}
	sort(all(v));

	vector<int> cv[2];
	auto check = [&](int i, int k){
		pll a = v[ cv[k][cv[k].size()-2] ];
		pll b = v[ cv[k][cv[k].size()-1] ];
		pll c = v[i];
		if(k == 0) return (b.Y-a.Y) * (c.X-a.X) < (c.Y-a.Y) * (b.X-a.X);
		if(k == 1) return (b.Y-a.Y) * (c.X-a.X) > (c.Y-a.Y) * (b.X-a.X);
	};
	rep(k,2) rep(i,N){
		while( cv[k].size() >= 2 && check(i, k) ) cv[k].pop_back();
		cv[k].push_back(i);
	}
	// {
	// 	rep(i,N){
	// 		int k = 0;
	// 		while( cv[k].size() >= 2 && check(i, k) ) cv[k].pop_back();
	// 		cv[k].push_back(i);
	// 	}
	// 	rrep(i,N-1){
	// 		int k = 0;
	// 		while( cv[k].size() >= 2 && check(i, k) ) cv[k].pop_back();
	// 		cv[k].push_back(i);
	// 	}
	// }

	vector<int> convex;
	for(auto t: cv[0]) convex.push_back(t);
	rrep(i, cv[1].size()-1) convex.push_back(cv[1][i]);
	convex.push_back( cv[0][1] );

	//for(auto i: convex) cout << v[i].X << "," << v[i].Y << endl;

	vector<double> ans(N);
	reps(i, 1, convex.size()-1){
		pll a = v[ convex[i-1] ];
		pll b = v[ convex[i] ];
		pll c = v[ convex[i+1] ];
		double vx1 = - (b.Y - a.Y);
		double vy1 = b.X - a.X;
		double vx2 = - (c.Y - b.Y);
		double vy2 = c.X - b.X;
		double cdot = (vx1*vx2 + vy1*vy2);
		double l1 = sqrt(vx1*vx1 + vy1*vy1);
		double l2 = sqrt(vx2*vx2 + vy2*vy2);
		double ang = acos( cdot / l1 / l2 );
		int n = mp[ v[convex[i]] ];
		ans[n] = ang / 2.0 / M_PI;
	}

	for(auto t: ans) printf("%.20f\n", t);

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>


using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    ll s = 0;
    int x[N];
    REP(i, N) {
        cin >> x[i];
        s += x[i];
    }

    double mm = s / double(N);

    ll m[2];
    m[0] = ll(ceil(mm));
    m[1] = ll(floor(mm));

    ll ans = INF;
    REP(i, 2) {
        ll tmp = 0;
        REP(j, N) {
            tmp += pow(x[j] - m[i], 2);
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import os
import sys

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

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

S = sys.stdin.readline().rstrip()

S = list(S)
S.sort()

if S[0] == S[1] and S[2] == S[3] and S[1] != S[2]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  map<int,int> mp;
  rep(i,N) {
    int a;
    cin >> a;
    mp[a]++;
  }
  int a=0,b=0;
  for(auto x:mp) {
    if(x.second >= 4) {
      a = max(a,x.first);
      b = max(b,x.first);
    } else if(x.second >= 2) {
      int c = x.first;
      a = max(a,min(b,c));
      b = max(b,c);
    }
  }
  cout << (ll)a * (ll)b << endl;
  return 0;
}

Measured memory_bytes: 4992
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')

N, W = MAP()
w, v = ZIP(N)
max_v = sum(v)
dp = [INF]*(max_v+1)
dp[0] = 0
for w, v in zip(w, v):
	for i in range(max_v, -1, -1):
		if i-v >= 0:
			dp[i] = min(dp[i], dp[i-v]+w)

ans = 0
for i in range(len(dp)):
	if dp[i] <= W:
		ans = i
print(ans)


Measured memory_bytes: 113488
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	var k int
	fmt.Scan(&k)

	for i := 0; i < k && i < len(s); i++ {
		if s[i] != '1' {
			fmt.Println(string(s[i]))
			return
		}
	}
	fmt.Println("1")
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;
int w,h,sx,sy,gx,gy,num;
string s[500];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
ll dg[500][500],db[500][500],inf=1e18;
void gbfs(int gx,int gy){
	rep(i,h) rep(j,w) dg[i][j]=inf;
	dg[gx][gy]=0;
	queue<PP> que;
	que.push(PP(dg[gx][gy],P(gx,gy)));
	while(!que.empty()){
		PP pp=que.front();
		que.pop();
		P p=pp.second;
		rep(i,4){
			int nx=p.fs+dx[i],ny=p.sc+dy[i];
			if(s[nx][ny]!='#'&&s[nx][ny]!='*'&&dg[nx][ny]==inf){
				dg[nx][ny]=pp.fs+1;
				que.push(PP(dg[nx][ny],P(nx,ny)));
			}
		}
	}
}
void bbfs(){
	queue<PP> que;
	rep(i,h) rep(j,w){
		if(s[i][j]!='*') db[i][j]=inf;
		else que.push(PP(0,P(i,j)));
	}
	while(!que.empty()){
		PP pp=que.front();
		que.pop();
		P p=pp.second;
		rep(i,4){
			int nx=p.fs+dx[i],ny=p.sc+dy[i];
			if(s[nx][ny]!='#'&&s[nx][ny]!='*'&&db[nx][ny]==inf){
				db[nx][ny]=pp.fs+1;
				que.push(PP(db[nx][ny],P(nx,ny)));
			}
		}
	}
}
bool check(long double x){
	long double sum=0;
	rep(i,h) rep(j,w) if(s[i][j]!='#'&&s[i][j]!='*') sum+=min(x+db[i][j],(long double)dg[i][j]);
	return sum/num<x;
}
int main(){
	cin>>w>>h;
	rep(i,h) cin>>s[i];
	rep(i,h) rep(j,w){
		if(s[i][j]=='s') sx=i,sy=j,num++;
		if(s[i][j]=='g') gx=i,gy=j;
		if(s[i][j]=='.') num++;
	}
	gbfs(gx,gy);
	bbfs();
	bool flag=false;
	rep(i,h) rep(j,w){
		if(s[i][j]!='#'&&dg[i][j]==inf&&db[i][j]==inf) flag=true;
	}
	if(flag){
		printf("%lld\n",dg[sx][sy]);
		return 0;
	}
	long double ub=500.0*500*500*500,lb=0;
	int cnt=0;
	while(cnt<100){
//		cout<<ub<<" "<<lb<<endl;
		cnt++;
		long double mid=(ub+lb)/2;
		if(check(mid)) ub=mid;
		else lb=mid;
	}
	printf("%.12f\n",(double)min(ub+db[sx][sy],(long double)dg[sx][sy]));
}

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

typedef long long ll;
ll a[200005];


int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	int k=n-2;
	ll sum=a[n];
	for(int i=n-1;i>=1;i--){
		if(k>0){
			sum+=a[i];
			k--;
		}
		else {
			break;
		}
		if(k>0){
			sum+=a[i];
			k--;
		}
		else {
			break;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 5156
#include<stdio.h>

#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs(void);
void visit(int);

int A[1000][1000],time,d[1000],f[1000],color[1000],S[1000],top=1,tail=1,n;



int main(){

  int i,j,u,k,v;

  scanf("%d",&n);

  for(i=0;i<n;i++){

    A[i][i]=0;

  }

  for(i=1;i<=n;i++){
  
    scanf("%d%d",&u,&k);

    for(j=1;j<=k;j++){

      scanf("%d",&v);
      
      A[u][v]=1;



    }
  }
  /* for(i=1;i<=n;i++){
    for(j=1;j<n;j++){
      


      
      printf("%d ",A[i][j]);
      
    }
    printf("%d",A[i][j]);
    printf("\n");
    }*/
  
  dfs();

  for(i=1;i<=n;i++){

    printf("%d %d %d\n",i,d[i],f[i]);

  }


  /*for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){

      
       printf("%d ",A[i][j]);

    }
    printf("%d",A[i][j]);
    printf("\n");
    }*/ 

  return 0;
}

void dfs(){

  int i;

  //printf("wa-i\n");
  
  for(i=1;i<=n;i++){

    color[i]=WHITE;
  }

  //printf("wa-i2\n");

  time =0;

  for(i=1;i<=n;i++){

    if(color[i]==WHITE){
      visit(i);
      // break;
    }
  } 

}

void visit(int r){

  int u,v,i,count=0;

  // printf("wa-i3\n");
  tail++; 
  S[tail-1]=r; 
  color[r] = GRAY;
  d[r]=++time;

  // printf("%d\n",r);
  // printf("%d\n",tail);
  //printf("%d\n",S[tail-1]);
  
  //printf("wa-i4\n");

  //printf("wa-i\n");

  while(top!=tail){

    //printf("wa-i100\n");
    
    u = S[tail-1];
    v=-1;

    // printf("color:%d\n",color[u]);

    

    //printf("wa-i101\n");

    count=0;
    
    for(i=1;i<=n;i++){  

      //printf("wa-i1\n");
      //if(u==0)break;
      if(A[u][i]==1&&color[i]==WHITE){
	v=i;
	count++;
      }
      
      //printf("i:%d u:%d,v:%d,color:%d\n",i,u,v,color[v]);
      //printf("A:%d\n",A[u][i]);

      
      //printf("wa-i5\n");

      if(count==1)break;
    }
    

    if(v != -1){

      // printf("wa-i2\n");
	      
      if(color[v]==WHITE){
	tail++;
	S[tail-1]=v;
	//tail++;
	color[v]=GRAY;
	d[v] = ++time;
      }
      
    }
    else{

      //printf("wa-i3\n");
      tail--;
      color[u] = BLACK;
      f[u]=++time;

    }
    // printf("tail:%d top:%d,%d u:%d %d\n ",tail,top,S[tail-1],S[top],u,v);
    
  }

  
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll C[10005];

struct RootedTree {
    RootedTree(int n, int root = 0) :
            mRoot(root) {
        mVertexTbl.resize(n);
    }

    void addEdge(int a, int b, long long int cost = 1) {
        mVertexTbl[a].child.push_back(pair<int, long long int>(b, cost));
        mVertexTbl[b].child.push_back(pair<int, long long int>(a, cost));
    }

    void build() {
        queue<tuple<int, int, long long int>> q;
        q.push(make_tuple(mRoot, -1, 0));
        while (!q.empty()) {
            auto t = q.front();
            q.pop();
            int index = get<0>(t);
            int parent = get<1>(t);
            long long int depth = get<2>(t);
            mVertexTbl[index].parent = parent;
            mVertexTbl[index].depth = depth;
            for (auto it = mVertexTbl[index].child.begin(); it != mVertexTbl[index].child.end();) {
                int nxt = (*it).first;
                if (nxt == parent) {
                    mVertexTbl[index].child.erase(it);
                    continue;
                }
                q.push(make_tuple(nxt, index, depth + (*it).second));
                ++it;
            }
        }
    }

    struct Vertex {
        vector<pair<int, long long int>> child;
        long long int depth = 0;
        int parent = -1;
    };

    int mRoot;
    vector<Vertex> mVertexTbl;
};

ll A[10005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    RootedTree tree(N);
    REP(i, N - 1) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        tree.addEdge(a, b);
    }
    tree.build();
    REP(i, N) {
        cin >> C[i];
    }
    sort(C, C + N);
    ll sum = 0;
    REP(i, N - 1) {
        sum += C[i];
    }

    queue<ll> q;
    q.push(0);
    ll index = N - 1;
    while (!q.empty()) {
        ll t = q.front();
        q.pop();
        A[t] = C[index--];
        REP(i, tree.mVertexTbl[t].child.size()) {
            ll n = tree.mVertexTbl[t].child[i].first;
            q.push(n);
        }
    }
    cout << sum << endl;
    REP(i, N) {
        cout << A[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1532
#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 tmp=998244353;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=5005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll n,C[M][M];
vl a,s;
vvi g;

void dfs(int v,int p){
	s[v]=1;
	for(auto u:g[v]) if(u!=p){
		dfs(u,v);
		s[v]+=s[u];
	}
}

int main(){
	Init();
	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;
	}
	cin>>n;
	g=vvi(n);
	s=vl(n);
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int G=-1;
	for(int i=0;i<n;i++){
		dfs(i,-1);
		bool B=1;
		for(auto u:g[i]) if(s[u]*2>n) B=0;
		if(B){
			if(G<0) G=i;
			else{
				cout<<F[n-s[G]]*F[s[G]]%mod<<endl;
				return 0;
			}
		}
	}
	dfs(G,-1);
	for(auto u:g[G]) a.push_back(s[u]);
	vl dp(n+1);
	dp[0]++;
	int t=0;
	for(auto i:a){
		vl DP(n+1);
		for(int j=0;j<=t;j++) for(int k=0;k<=min(n-j,i);k++) (DP[j+k]+=dp[j]*C[i][k]%mod*C[i][k]%mod*F[k])%=mod;
		t+=i;
		dp=DP;
	}
	ll res=0;
	for(int i=0;i<=n;i++) (res+=dp[i]*F[n-i]%mod*(i%2==0?1:mod-1))%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 194816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
 
int main(){
  int a,b;
  cin >> a >> b;
  int cnt=0;
  int c=1;
  while(c<b){
    cnt++; c+=a-1;
  }
  cout << cnt << endl;
}

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n,k; cin >> n >> k;
    int r,s,p; cin >> r >> s >> p;
    map<char,int> point;
    point['s']=r;
    point['p']=s;
    point['r']=p;
    string t; cin >> t;
    int ans=0;
    for(int i=0;i<t.size();i++){
        if(i>=k){
            if(t[i]==t[i-k]){
                t[i]='X';
                continue;
            }
            ans+=point[t[i]];
           
        }else{
            ans+=point[t[i]];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string s;
    cin >> s;
    
    ll res = 0;
    ll cnt = 0;
    for(ll i = 0; i < s.size(); i++) {
        if (s[i] == 'B') {
            cnt++;
        } else {
            res += cnt;
        }
    }

    cout << res << endl;

    return 0;
}

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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cerr << #variable":\t" << (variable) << "\n"
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cerr << (i) << ":\t" << (container)[(i)] << "\n"
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template<typename T = int>
T in() {T a; cin >> a; return a;}
/***** MAIN *****/
int lowerbound(vector<int> &v, int num) {
  int left = 0, right = v.size()-1;
  while(right-left > 0) {
    int mid = (left + right) / 2;
    if(v[mid] >= num) right = mid;
    else left = mid + 1;
  }
  if(v[left] >= num) return left;
  else return v.size();
}

int upperbound(vector<int> &v, int num) {
  int left = 0, right = v.size()-1;
  while(right-left > 0) {
    int mid = (left + right) / 2;
    if(v[mid] > num) right = mid;
    else left = mid + 1;
  }
  if(v[left] > num) return left;
  else return v.size();
}
signed main() {
  int n; cin >> n;
  vector<int> a(n), b(n), c(n);
  REP(i,n) cin >> a[i];
  REP(i,n) cin >> b[i];
  REP(i,n) cin >> c[i];
  SORT(a); SORT(b); SORT(c);
  int ans = 0;
  REP(i,n) {
    int upper_count = lowerbound(a, b[i]);
    int lower_count = n - upperbound(c, b[i]);
    ans += upper_count * lower_count;
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/

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

int main(){
  long W, H, x, y;
  cin >> W >> H >> x >> y;
  long double Area = W * H / 2.0;
  cout << fixed;
  cout << std::setprecision(20) << Area << " ";
  vector<double> center(2);
  center.at(0) = W / 2.0;
  center.at(1) = H / 2.0;
  if(x == center.at(0) && y == center.at(1)) cout << 1 << endl;
  else cout << 0 << endl;
}

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

const int oo = 1e6;
int l[100007], r[100007], sum[100007];
int main() {
	string s; cin >> s;
	int len = s.length();
	int zero = 0, one = 0;
	rep(i, len) {
		if (s[i] == '0')
			zero++;
		if (s[i] == '1')
			one++;
	}

	cout << 2 * min(one, zero) << endl;
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
unsigned char dp[65536][16];
struct st{
	unsigned short haichi;
	unsigned char pos;
};
queue<st> P;
int main() {
	int n;
	while (cin >> n,n){
		string s, ans_s;
		cin >> s;
		cin >> ans_s;
		unsigned short sh=0;
		unsigned short ans_sh=0;
		REP(i, n){
			sh <<= 1;
			ans_sh <<= 1;
			if (s[i] == 'W')
				sh |= 1;
			if (ans_s[i] == 'W')
				ans_sh |= 1;
		}
		REP(i, 65536 * 16)
			dp[i / 16][i % 16] = 255;
		
		REP(i, n){
			P.push({ sh, (unsigned char)i });
			dp[sh][i] = 0;
		}
	
		while (!P.empty()){
			st p = P.front(); P.pop();
			unsigned short diff=p.haichi^ans_sh;
			vector<unsigned char> db;
			vector<unsigned char> dw;
			REP (i,n){
				if ((diff >> i) & 1)
					if (!((p.haichi >> i) & 1))
						db.push_back(i);
					else
						dw.push_back(i);
			}
			REP(i, db.size()){
				REP(j,dw.size()){
					unsigned short change = (1 << db[i]) + (1 << dw[j]);
					change ^= p.haichi;
					if (dp[change][db[i]]>dp[p.haichi][p.pos]+abs(p.pos - dw[j]) + abs(db[i] - dw[j])){
						dp[change][db[i]] = dp[p.haichi][p.pos] + abs(p.pos - dw[j]) + abs(db[i] - dw[j]);
						P.push({ change, db[i] });
					}
					if (dp[change][dw[j]]>dp[p.haichi][p.pos] + abs(p.pos - db[i]) + abs(db[i] - dw[j])){
						dp[change][dw[j]] = dp[p.haichi][p.pos] + abs(p.pos - db[i]) + abs(db[i] - dw[j]);
						P.push({ change, dw[j] });
					}
				}
			}
		}
		int min_ans=255;
		REP(i,n){
			min_ans = min((int)dp[ans_sh][i],min_ans);
		}
		cout << min_ans << endl;
	}
}

Measured memory_bytes: 2556
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    ll n;
    cin>>n;
    ll q=sqrt(n);
    cout<<q*q<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool have_9(int a)
{
    while(a!=0)
    {
        if(a%10==9)
            return true;
        a/=10;
    }
    return false;
}
int main()
{
    int a;
    cin>>a;
    if(have_9(a))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ll a, v, b, w, t;   cin >> a >> v >> b >> w >> t;
    ll dist = abs(a-b);
    string ans = "NO";
    if(0<v-w){
        ll res = dist/(v-w)+min(dist%(v-w), 1LL);
        if(res<=t) ans = "YES";
    }
    cout << ans << endl;

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define For(i, a, b) for (int i = int(a); i < int(b); i++)
#define Dor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define Foz(i, a) For(i, 0, a)
#define Doz(i, a) Dor(i, 0, a)
#define Trav(e, v) for (auto& e : v)
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	int n;
	cin >> n;
	vi a(n + 1), b(n);
	Foz(i, n + 1) cin >> a[i];
	Foz(i, n) cin >> b[i];

	ll ans = 0;
	Foz(i, n) {
		int k = min(b[i], a[i]);
		ans += k;
		b[i] -= k;

		k = min(b[i], a[i + 1]);
		ans += k;
		a[i + 1] -= k;
	}
	
	cout << ans << '\n';
}



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

int main(){
    int n;
    cin >> n;
    vector<int> height(n);
    for(int i = 0; i < n; ++i){
        cin >> height[i];
    }
    if(n < 3){
      cout << abs(height[1] - height[0]);
      return 0;
    }
    int min_cost = 0, prev2 = 0, prev1 = abs(height[1] - height[0]);
    //vector<int> path, par(n);
    for(int i = 2; i < n; ++i){
        //min_cost = min(prev2 + abs(height[i] - height[i - 1]), prev1 + abs(height[i] - height[i - 2]) );
        //cout << "curr: " << min_cost << endl;
        int cost1 = prev1 + abs(height[i] - height[i - 1]), cost2 = prev2 + abs(height[i] - height[i - 2]);
        if(cost1 < cost2){
            min_cost = cost1;
            //par[i] = i-1;
        }else{
            min_cost = cost2;
            //par[i] = i-2;
        }
        //cout << "c1: " << cost1 << " c2: " << cost2 << " min: " << min_cost << endl;
        prev2 = prev1;
        prev1 = min_cost;
    }
    cout << min_cost << endl;
    /*int elem = par[n-1];
    path.push_back(n);
    while(elem){
        path.push_back(elem + 1);
        elem = par[elem];
    }
    path.push_back(1);
    int size = path.size();
    for(int i = size - 1; i >= 0; --i){
        cout << path[i] << "-->";
    }
    cout << endl;*/
    return 0;
}

Measured memory_bytes: 640
n,k=map(int,input().split())
MOD=10**9+7
ans=0

baig=[0]*(10**5+1)
exg=[0]*(10**5+1)

for i in range(1,k+1):
    baig[i]=pow(k//i,n,MOD)

for j in range(k,0,-1):
    exg[j]=baig[j]
    for jj in range(2*j,k+1,j):
        exg[j]-=exg[jj]
    exg[j]%=MOD
    ans+=exg[j]*j
    ans%=MOD

print(int(ans))



Measured memory_bytes: 13480
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
     int i,j,k,n,m;
     scanf("%d%d",&n,&m);
     printf("%d\n",n*n-m);
	return 0;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
using namespace std;
int main(void){
    string number;
    int sum;
    while(true){
        sum = 0;
        cin >> number;
        if (number[0] == '0'){
            break;
        }
        for ( int i = 0; i < number.size(); i++ ){
            sum += number[i] - '0';
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep(i,n) for(ll i=0; i<n; i++)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int n; cin >> n;
  vi a(n);
  rep(i,n){
    cin >> a[i];
  }
  int alice = 0, bob = 0;
  sort(all(a),greater<int>());
  rep(i,n){
    if(i % 2 == 0){
      alice += a[i];
    }else{
      bob += a[i];
    }
  }
  cout << alice - bob;
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>?): Unit {
    fun <T> List<T>.doubling(): List<T> = flatMap{listOf(it, it)}
    val (n, k) = readLine()!!.trim().split(' ').map(String::toInt)
    val areas = Array(n){
        val (x1, y1, d1, x2, y2, d2) = readLine()!!.trim().split(' ').map(String::toInt)
        Pair(Point(x1, y1, d1), Point(x2, y2, d2))
    }
    val points = areas.flatMap { listOf(it.first, it.second) }
    val width = points.map(Point::x).doubling().toIntArray().apply{sort()}
    val height = points.map(Point::y).doubling().toIntArray().apply{sort()}
    val depth = points.map(Point::z).doubling().toIntArray().apply{sort()}
    val space = Array(4 * n){Array(4 * n){IntArray(4 * n){0}}}
    fun Point.toCompressed(): Point {
        return Point(lowerBound(width, x), lowerBound(height, y), lowerBound(depth, z))
    }
    for ((l, r) in areas) {
        val cl = l.toCompressed()
        val cr = r.toCompressed()
        space[cl.x][cl.y][cl.z]++
        space[cr.x + 1][cl.y][cl.z]--
        space[cl.x][cr.y + 1][cl.z]--
        space[cl.x][cl.y][cr.z + 1]--
        space[cl.x][cr.y + 1][cr.z + 1]++
        space[cr.x + 1][cl.y][cr.z + 1]++
        space[cr.x + 1][cr.y + 1][cl.z]++
        space[cr.x + 1][cr.y + 1][cr.z + 1]--
    }
    for (x in 1 until 4 * n) for (y in 0 until 4 * n) for (z in 0 until 4 * n) space[x][y][z] += space[x - 1][y][z]
    for (x in 0 until 4 * n) for (y in 1 until 4 * n) for (z in 0 until 4 * n) space[x][y][z] += space[x][y - 1][z]
    for (x in 0 until 4 * n) for (y in 0 until 4 * n) for (z in 1 until 4 * n) space[x][y][z] += space[x][y][z - 1]
    println(
            (0 until 4 * n - 1).map{x -> (0 until 4 * n - 1).map{y -> (0 until 4 * n - 1).filter{z -> space[x][y][z] >= k }.map{z ->
                (width[x + 1].toLong() - width[x]) * (height[y + 1].toLong() - height[y]) * (depth[z + 1].toLong() - depth[z])
            }.sum()}.sum()}.sum()
    )
}
operator fun <T> List<T>.component6(): T = this[5]
data class Point(val x: Int, val y: Int, val z: Int)
fun lowerBound(array: IntArray, target: Int): Int {
    var left = 0
    var right = array.size
    while(left < right){
        val mid = (left + right) / 2
        if (array[mid] < target) left = mid + 1
        else right = mid
    }
    return right
}


Measured memory_bytes: 142008
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int ans = 0;
        if(K % 2 == 0){
            ans = (K/2)*(K/2);
        }else{
            ans = (K/2 + 1) * (K/2);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21588
/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)

ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll n=nxt();
	ll ans[n]={0};
	ll x[n];
	rep(a,1,n)
		cin>>x[a];
	rep(a,n,1)
	{
		ans[x[a]-1]++;
	}
	rep(a,0,n)
		cout<<ans[a]<<endl;
	printclock;
	return 0;
}


Measured memory_bytes: 6944
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define ll long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12



int main(void)
{
	//変数の宣言
	int n;
	int a[100010];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	
	
	//データの読み込み
	scanf("%d",&n);
//	scanf_s("%d",&n);

	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
//		scanf_s("%d",&a[i]);
	}

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理
	
	temp=0;
	ans=1;
	for(i=1;i<n;i++){
		if(temp==0){
			if(a[i]>a[i-1]){
				temp=1;
			}else if(a[i]<a[i-1]){
				temp=-1;
			}
		}else if(a[i]>a[i-1]&&temp==-1){
			ans++;
			temp=0;
		}else if(a[i]<a[i-1]&&temp==1){
			ans++;
			temp=0;
		}
	}

	//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",ans);

	//	printf("結果の出力終了\n");

	
	return 0;
}



Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a, b;

		ArrayList<Integer> abList = new ArrayList<Integer>();

		while (true) {
			a = sc.nextInt();
			b = sc.nextInt();

			if ((a == 0) && (b == 0))
				break;

			if (a > b) {
				abList.add(b);
				abList.add(a);
			} else {

				abList.add(a);
				abList.add(b);
			}
		}

		for (int i = 0; i < abList.size(); i += 2) {
			System.out.println(abList.get(i) + " " + abList.get(i + 1));
		}

	}
}

Measured memory_bytes: 37464
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
  }

  return sum;
}

//main.cpp----------------------------


void solve();

ll a, b, c;

int main() {
  cin >> a >> b >> c;

  solve();

  return 0;
}

void solve() {

  ll cnt = 0;

  if(b>=c) {
    cnt = c*2;
    cnt += b-c;
    cout << cnt << endl;
    return;
  }else if(b<c) {
    cnt = b*2;
    c -= b;
  }

  if(c<=0) {
    cout << cnt << endl;
    return;
  }

  if(a>=c) {
    cnt += c;
    cout << cnt << endl;
  }else if(a<c) {
    cnt += a + 1;
    cout << cnt << endl;
  }
}


Measured memory_bytes: 256
while 1:
    n,m = map(int,raw_input().split())
    if n == m == 0: break
    g = [map(float,raw_input().split()) for _ in range(n)]
    grow = [[0.0]*n for _ in range(m)]
    for i in range(n): grow[0][i] = 1.0
    
    for day in range(1,m):
        for cur in range(n):
            for prev in range(n):
                grow[day][cur] = max(grow[day][cur], grow[day-1][prev]*g[prev][cur])
                
    print "%.2f"%round(max(grow[m-1]),3)

Measured memory_bytes: 5012
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define MP make_pair
#define all(o) (o).begin(), (o).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define fr(i,n) for(lli i=0;i<n;++i)
#define rep(i,a,b) for(lli i=a;i<=b;++i)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#define endl '\n'
typedef long long int lli;
typedef long double ld;
typedef pair< lli,lli > ii;
typedef vector<lli> vi;
typedef vector<ii> vii;
typedef vector<vi> graph;
lli MOD=1000000007;long double EPS=1e-9;


void pre(){

}

void solve(){
	lli n,k;
	cin>>n>>k;
	lli arr[n];
	fr(i,n)cin>>arr[i];
	int pos=0;
	fr(i,n){
		if(arr[i]==1){pos=i;break;}
	}
	cout<<(n-1+k-2)/(k-1)<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	pre();
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

Measured memory_bytes: 1024
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, k = MAP()
a = LIST()

if n == 1:
    if a[0] == k:
        print("POSSIBLE")
        exit()
else:
    m = gcd(a[0], a[1])
    for x in a:
        m = gcd(m, x)
    for x in a:
        if x - k >= 0 and ( x - k ) % m == 0:
            print("POSSIBLE")
            exit()
print("IMPOSSIBLE")

Measured memory_bytes: 21828
#include<stdio.h>

#define MAX 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n , M[MAX][MAX];

void dijkstra(){
	int minv;
	int d[MAX] , color[MAX];
	
	for( int i = 0; i < n; i++ ){
		d[i] = INFTY;
		color[i] = WHITE;
	}
	
	d[0] = 0;
	color[0] = GRAY;
	
	while(1){
		minv = INFTY;
		int u = -1;
		for( int i = 0; i < n; i++ ){
			if( minv > d[i] && color[i] != BLACK ){
				u = i;
				minv = d[i];
			}
		}
		if( u == -1 ){
			break;
		}
		color[u] = BLACK;
		
		for( int v = 0; v < n; v++ ){
			if( color[v] != BLACK && M[u][v] != INFTY ){
				if( d[v] > d[u] + M[u][v] ){
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}
	
	for( int i = 0; i < n; i++ ){
		printf( "%d " , i );
		if( d[i] == INFTY ){
			printf( "-1\n" );
		}else{
			printf( "%d\n" , d[i] );
		}
		
	}
}

int main( void ){
	
	scanf( "%d" , &n );
	
	for( int i = 0; i < n; i++ ){
		for( int j = 0; j < n; j++ ){
			M[i][j] = INFTY;
		}
	}
	
	int k , c , u , v;
	
	for( int i = 0; i < n; i++ ){
		scanf( "%d" , &u );
		scanf( "%d" , &k );
		
		for( int j = 0; j < k; j++ ){
			scanf( "%d" , &v );
			scanf( "%d" , &c );
			M[u][v] = c;
		}
	}
	
	dijkstra();
	
	return 0;
}


Measured memory_bytes: 2048
import java.io.*;
import java.util.*;

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    public void go() throws IOException
    {
        ntok();
        int n = ipar();
        TreeMap<Integer, Integer> map = new TreeMap<>();
        ntok();
        for (int i = 0; i < (1 << n); i++)
        {
            int x = ipar();
            map.put(x, map.getOrDefault(x, 0) + 1);
        }
        boolean works = true;
        ArrayList<Integer> use = new ArrayList<>();
        use.add(map.floorKey(Integer.MAX_VALUE));
        map.put(use.get(0), map.get(use.get(0)) - 1);
        OUTER:
        for (int i = 0; i < n; i++)
        {
            int shift = 1 << i;
            for (int j = 0; j < shift; j++)
            {
                Integer x = map.floorKey(use.get(j)-1);
                if (x == null)
                {
                    works = false;
                    break OUTER;
                }
                use.add(x);
                map.put(x, map.get(x)-1);
                if (map.get(x) == 0)
                {
                    map.remove(x);
                }
            }
        }
        if (works)
        {
            out.println("Yes");
        }
        else
        {
            out.println("No");
        }

        out.flush();
        in.close();
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public int[] iapar(int n)
    {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = ipar();
        }
        return arr;
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public long[] lapar(int n)
    {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = lpar();
        }
        return arr;
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

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


Measured memory_bytes: 80544
<?php
#include <stdio.h>
# 整数の入力
$n = trim(fgets(STDIN));
$chars = trim(fgets(STDIN));

$array = explode(" ", $chars);
$sortedArray = rsort($array);

$a = 0; //Aliceの得点
$b = 0; //Bobの得点
$i = 0;

foreach($array as $key => $val){
  if($i % 2 == 0){
    $a = $a + $val;
  } else {
    $b = $b + $val;
  }
  $i++;
}

$result = $a - $b;

echo $result."\n";


Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();

		if (A == B) {
			System.out.println(0);
		} else if ((A + B) % 2 == 0) {
			System.out.println((A + B) / 2);
		} else {
			System.out.println("IMPOSSIBLE");
		}

	}

}


Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, m, a, b, c[112345];
    V g[112345];

    memset(c, -1, sizeof(c));

    cin >> n >> m;
    REP(i, m)
    {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    c[1] = 0;

    int w = 1;

    queue<int> q;
    q.push(1);

    while (q.size())
    {
        int i = q.front();
        q.pop();

        for (int j : g[i])
        {
            if (c[j] == c[i])
            {
                cout << ((ll)n * (n - 1) / 2 - m) << endl;
                return 0;
            }

            if (c[j] == -1)
            {
                c[j] = 1 - c[i];
                q.push(j);

                w += c[j] == 0;
            }
        }
    }

    cout << ((ll)w * (n - w) - m) << endl;

    return 0;
}

Measured memory_bytes: 6656
#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
double dp[100][100],g[100][100];
int main(){
  int n, m;
  while(cin >> n >> m , n){
    for(int i = 0 ; i < n ; i++ )
      for(int j = 0 ; j < n ; j++ ) cin >> g[i][j];
    fill_n( dp[0], n, 1.0);
    fill_n( dp[1], 9900, 0.0);
    for(int i = 1 ; i < m ; i++ ) //回
      for(int prev = 0 ; prev < n ; prev++ ) // prev
        for(int now = 0 ; now < n ; now++ ) // now
          dp[i][now] = max( dp[i][now], dp[i - 1][prev] * g[prev][now]);

    cout << fixed << setprecision(2) << *max_element( dp[m - 1], dp[m - 1] + n ) << endl;
  }
}

Measured memory_bytes: 1444
h,w,m=map(int,input().split())
d=dict()
a=[0]*h
b=[0]*w
for _ in range(m):
  x,y=map(int,input().split())
  x-=1
  y-=1
  a[x]+=1
  b[y]+=1
  d[x*10**6+y]=1

ma=max(a)
mb=max(b)

ind_x=[i for i,j in enumerate(a) if j==ma]
ind_y=[i for i,j in enumerate(b) if j==mb]


for x in ind_x:
  for y in ind_y:
    if not(x*10**6+y in d):
      print(ma+mb)
      exit()
print(ma+mb-1)


Measured memory_bytes: 169576
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,k;
cin>>a>>b>>k;
if(a>=k)
  cout<<a-k<<" "<<b;
 else
 {  if(b-(k-a)>0)
   cout<<0<<" "<<b-(k-a);
    else
      cout<<0<<" "<<0;
 } 
return 0;
}

Measured memory_bytes: 256
float a,b,c,d,e,f,g,h;main(){for(;~scanf("%f%f%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f,&g,&h);puts(a*d*h>b*c*h&h*e*b>h*f*a?"YES":"NO"))a-=g,b-=h,c-=g,d-=h,e-=g,f-=h,h=c*f-d*e;}

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

int main(){
	int N, M;
	cin >> N;
	int T[N], i, sum=0;
	for(i=1; i<=N; i++){
		cin >> T[i];
		sum += T[i];
	}
	cin >> M;
	int P[M], X[M];
	for(i=1; i<=M; i++){
		cin >> P[i] >> X[i];
	}
	
	for(i=1; i<=M; i++){
		cout << sum - T[P[i]] + X[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256