akhauriyash/Code-Regression huggingface dataset:
#if defined(__GNUC__)
#include <bits/stdc++.h>
#define __int32 __int32_t
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(ALL(x), greater<decltype(x)::value_type>())
#define RSORT2(x, T) sort(ALL(x), greater<T>())
#define REVERSE(x) reverse(ALL(x))
#define ACM(x, y) accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)
#define FCT(x) [](int a) -> int {int r = 1; REP(i, a){r *= i;} return r;}(x)

// デバッグ用
#define PUT_LIST(x, y) std::copy(ALL(x), ostream_iterator<decltype(x)::value_type>(cout, y))

const int kMod = 1e9 + 7;

itn main() {
	ios::sync_with_stdio(false);

	string a, b, c;

	cin >> a >> b >> c;

	swap(a, b);
	swap(a, c);

	cout << a << ' ' << b << ' ' << c;

	return 0;
}


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

using namespace std;

#define int long long
#define reg register
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a )
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a )
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a )
#define debug(x) cerr<<#x<<" = "<<x<<endl;

template<class T>inline bool Max(T &a,T b) {
	return a<b?a=b,1:0;
}
template<class T>inline bool Min(T &a,T b) {
	return a>b?a=b,1:0;
}

inline int Read(void) {
	int res=0,flag=1;
	char c;
	while(c=getchar(),c<48||c>57)if(c=='-')flag=0;
	do res=(res<<1)+(res<<3)+(c^48);
	while(c=getchar(),c>=48&&c<=57);
	return flag?res:-res;
}

const int N=2e3+5,M=1e6+5,mod=1e9+7;
const int dx[4]= {1,-1,0,0},dy[4]= {0,0,1,-1};

int Ans;

signed main(void) {
	int a=Read()-1,b=Read(),c=Read(),d=Read();
	if(c>d)swap(c,d);
	Ans+=b/c-a/c;
	Ans+=b/d-a/d;
	Ans-=b/(c*d/__gcd(c,d))-a/(c*d/__gcd(c,d));
	printf("%lld",b-a-Ans);
	return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.first,", ",x.second,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int block_size = 710;
vi arr;

int cur = 0;
int occ [500100] = {0};

inline void add(int val) {
	if (occ[val] == 0) ++cur;
	occ[val]++;
}

inline void remove(int val) {
	if (occ[val] == 1) --cur;
	occ[val]--;
}

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

	int N, T; cin >> N >> T;
	arr.resize(N);
	F0R(i, N) cin >> arr[i];
	vector<pair<pii, int>> queries (T);
	F0R(i, T) {
		int l, r; cin >> l >> r; --l; --r;
		queries[i] = {{l, r}, i};
	}

	sort(queries.begin(), queries.end(), [] (const auto& lhs, const auto& rhs) {
		pii q1 = lhs.first;
		pii q2 = rhs.first;
		if ((q1.first / block_size) != (q2.first / block_size)) 
			return (q1.first / block_size) < (q2.first / block_size);
		return q1.second < q2.second;
	});
	
	vi ans (T);

	int curL = 0;
	int curR = 0;
	add(arr[0]);
	for (pair<pii, int> qu : queries) {
		pii q = qu.first;
		
		while (curL < q.first) {
			remove(arr[curL]);
			++curL;
		}
		while (curL > q.first) {
			--curL;
			add(arr[curL]);
		}
		while (curR < q.second) {
			++curR;
			add(arr[curR]);
		}
		while (curR > q.second) {
			remove(arr[curR]);
			--curR;
		}
		ans[qu.second] = cur;
	}
	for (int x : ans) print(x);
}

Measured memory_bytes: 15480
n=gets.to_i
a=gets.split.map(&:to_i)
b=gets.split.map(&:to_i).reverse
sum=0
dp_a=a.map{|k|sum+=k}
sum=0
dp_b=b.map{|k|sum+=k}
puts n.times.map{|i|dp_a[i]+dp_b[n-i-1]}.max

Measured memory_bytes: 1788
/** By @ZhakudaMagzhan **/
# include  <bits/stdc++.h>

# define mp  make_pair
# define pb  push_back

# define   sz(x)  (int)x.size()
# define  all(x)  x.begin(), x.end()
# define  bit(x)  __builtin_popcountll(x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair <int,int> pii;

const int inf = (int) 1e9+50, mod = 999983ll;
const ll linf = (ll) 2e18;

int kob (int x, int y) { return ((ll)x * y) % mod; } 
int aza (int x, int y) { x -= y; if (x < 0) return x + mod; return x; } 
int kos (int x, int y) { x += y; if (x >= mod) return x - mod; return x; }

const int maxn = (int) 1e5 + 777, maxn2 = (int) 1e6 + 777;    

//temp.cpp

int main () {
	#define FN "" 
	#ifdef lcl	
		freopen (FN".in", "r", stdin);
		freopen (FN".out", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 
	ll q, h, s, d, l;
	cin >> q >> h >> s >> d;
	cin >> l;
	h = min (h, q * 2);
	s = min (s, h * 2);
	d = min (d, s * 2);


	cout << (l / 2) * d + (l % 2) * s;
	return 0;
}

Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
typedef long long ll;
using namespace std;

int r, g, b;
const int INF = 10e8;
void CountingRoads(){
	ll n, k;
	cin >> n >> k;
	ll t[100050];
	fill(t, t + 100050, 0);
	for (size_t i = 0; i < n; i++)
	{
		ll a, b;
		cin >> a >> b;
		t[a] += b;
	}

	ll c = 0;
	for (size_t i = 0; i < 100050; i++)
	{
		c += t[i];
		if (k <= c) {
			cout << i << endl;
			return;
		}
	}
}

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


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int N;
  int X;
  int a=0;
  int kotae=1;
  cin >> N >> X;

  int L[110];
  for(int i=0;i<N;i++){
    cin >> L[i];
    a=a+L[i];
    if(X>=a){
      kotae++;
    }
  }
  cout << kotae << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> h(n);
  int ans=0;
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  int t=h[0];
  int i;
  int mode=0;
  for(i=0;i<n-1;i++){

	if(mode){
      if(h[i]<h[i+1]){
        ans+=t-h[i];
        mode=0;
        t=0;
      }
    }else{
      if(h[i]>h[i+1]){
        t=h[i];
        mode=1;
      }
    }
        //cout<<i<<' '<<mode<<' '<<t<<' '<<ans<<endl;
  }
  if(h[n-1]<t){
    ans+=t;
  }else{
    ans+=h[n-1];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Yulian
 */

#include <iostream>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>


#include <iostream>

#include <fstream>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <algorithm>
#include <map>
//#include "../../library/lib.hpp"


using namespace std;

class TaskC {
public:
public:
  void dfs(int i, set<int> visited, const vector<set<int>> &a, vector<set<int>> &result) {
    visited.insert(i);
    bool end = true;
    if (visited.size() == a.size()) {
      end = true;
    } else {
      for (auto it = a[i].begin(); it != a[i].end(); ++it) {
        if (visited.find(*it) == visited.end()) {
          dfs(*it, visited, a, result);
          end = false;
        }
      }
    }
    if (end) {
      result.push_back(visited);
    }
  }

  void solve(std::istream &in, std::ostream &out) {
    ios::sync_with_stdio(false);
    int n, m, x, y;
    in >> n >> m;
    vector<set<int>> a(n + 1);
    for (int i = 0; i < m; ++i) {
      in >> x >> y;
      a[x].insert(y);
      a[y].insert(x);
    }
    vector<set<int>> result;
    dfs(1, {}, a, result);

    int cnt = 0;
    for (auto &path : result) {
      if (path.size() == n) {
        ++cnt;
//        tmp.clear();
//        for (auto &el : path) {
//          tmp.insert(el);
//        }
//        if (tmp.size() == n) {
//          ++cnt;
//        }
      }
    }
    out << cnt << endl;
  }
};


int main() {
	TaskC solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 2364
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)
 
#define MN 100005
int n;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
 
    cin >> n;
    if(__builtin_popcount(n) == 1){
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";
    cout << "1 2\n2 3\n1 " << 3+n << "\n" << 3+n << " " << 2+n << "\n" << 2+n << " " << 1+n << "\n";
    int mx = n-1+n%2;
    for(int i=4; i<mx; i+=2){
        cout << "1 " << i << "\n" << i << " " << i+1 << "\n";
        cout << "1 " << n+i+1 << "\n" << n+i+1 << " " << n+i << "\n";
    }
    if(n % 2 == 0){
        int mx = 1;
        while(mx*2 < n) mx *= 2;
        int o = n ^ mx ^ 1;
        cout << mx << " " << n << "\n";
        cout << n+o << " " << 2*n << "\n";
    }
 
    return 0;
}

Measured memory_bytes: 2304
#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 <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    PUTS(k==1 ? 0 : n-k);
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
xx = int(n // 1.08 - 5)
for x in range(xx, xx + 10):
    if int(x * 1.08) == n:
        print(x)
        exit()
print(':(')

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

#define int long long

void solve();
void make_edge(int o);

typedef pair<int,int> pii;
typedef pair<pii,int> ppiii;
typedef pair<int,pii > pipii;

int M,N,K;
ppiii room[200010];
vector<pii> V[200010][2];
int D[200010][2] = {0};

signed main()
{
    scanf("%lld%lld%lld",&M,&N,&K);
    for(int i = 0; i < K; i++)
    {
        scanf("%lld%lld",&room[i].first.first,&room[i].first.second);
        room[i].second = i;
    }
    solve();
    return 0;
}

void solve()
{
    int ans = 1000000000000000;
    sort(room,room + K);
    make_edge(0);
    for(int i = 0; i < K; i++)
    {
        int mem;
        mem = room[i].first.first;
        room[i].first.first = room[i].first.second;
        room[i].first.second = mem;
    }
    sort(room,room + K);
    make_edge(1);
    priority_queue<pipii, vector<pipii>, greater<pipii> > Q;
    for(int i = 0; i < K; i++)
    {
        int mem;
        mem = room[i].first.first;
        room[i].first.first = room[i].first.second;
        room[i].first.second = mem;
    }
    sort(room,room + K);
    int I = 0;
    while(room[I].first.first == 1)
    {
        if(room[I].first.second == 1)
        {
            Q.push(make_pair(1,make_pair(room[I].second,1)));
            I++;
            continue;
        }
        Q.push(make_pair(room[I].first.second - 1,make_pair(room[I].second,0)));
        I++;
    }
    while(Q.size())
    {
        pipii now = Q.top();
        Q.pop();
        if(D[now.second.first][now.second.second] <= now.first && D[now.second.first][now.second.second])
        {
            continue;
        }
        D[now.second.first][now.second.second] = now.first;
        Q.push(make_pair(now.first + 1,make_pair(now.second.first,(now.second.second + 1) % 2)));
        for(int i = 0; i < V[now.second.first][now.second.second].size(); i++)
        {
            Q.push(make_pair(now.first + V[now.second.first][now.second.second][i].second,make_pair(V[now.second.first][now.second.second][i].first,now.second.second)));
        }
    }
    for(int i = 0; i < K; i++)
    {
        if(room[i].first.first == M && D[room[i].second][0] != 0)
        {
            ans = min(ans,(long long)(N - room[i].first.second + D[room[i].second][0]));
        }
        if(room[i].first.second == N && D[room[i].second][1] != 0)
        {
            ans = min(ans,(long long)(M - room[i].first.first + D[room[i].second][1]));
        }
    }
    if(ans == 1000000000000000)
    {
        printf("-1\n");
        return;
    }
    printf("%lld\n",ans);
    return;
}

void make_edge(int o)
{
    int mem1 = 0,mem2;
    for(int i = 0; i < K; i++)
    {
        if(mem1 != room[i].first.first)
        {
            mem1 = room[i].first.first;
            mem2 = room[i].first.second;
            continue;
        }
        V[room[i - 1].second][o].push_back(make_pair(room[i].second,room[i].first.second - mem2));
        V[room[i].second][o].push_back(make_pair(room[i - 1].second,room[i].first.second - mem2));
        mem2 = room[i].first.second;
    }
    return;
}

Measured memory_bytes: 39996
N=int(input())
t=dict()
ans=list()
for i in range(N):
    tmp=input()
    if tmp in t:
        t[tmp]+=1
    else:
        t[tmp]=1
max_v=max(t.values())
ans=[kv[0] for kv in t.items() if kv[1] == max_v]
ans.sort()
for i in ans:
    print(i)

Measured memory_bytes: 35404
x[]={1,2,1,2,1,4,1,4},o[]={0,2,6,4,1,3,7,5},a[8];
main(i,j,v,V,m,t){for(;;){
for(i=0;i<8;i++)if(scanf("%d",a+i)==-1)exit(0);
for(v=1e9,V=0,i=0;i<8;i++){for(m=j=0;j<8;j++)t=a[j]-x[(o[i]+j)%8],m+=t<0?0:t;if(m<v)v=m,V=o[i];}
for(j=0;j<8;j++)printf(j<7?"%d ":"%d\n",x[(V+j)%8]);
}}

Measured memory_bytes: 600
import math
from collections import Counter, defaultdict

def ncr(p):
	return p*(p-1)//2

n = int(input())

dct = defaultdict(int)

for i in range(n):
	counter = Counter(input().strip())
	tpl = tuple(sorted(counter.items()))
	dct[tpl] += 1


ans = sum(ncr(val) for val in dct.values() if val>1)
print(ans)

Measured memory_bytes: 74768
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n, k;
vector<int> a, f, t;

bool che(int x)
{
    int cnt = 0;
    rep(i, n) if (t[i] > x)
    {
        int d = t[i] - x;
        cnt += (d + f[i] - 1) / f[i];
    }
    return cnt <= k;
}

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

    cin >> n >> k;
    a.resize(n);
    f.resize(n);
    t.resize(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];
    sort(all(a));
    sort(all(f));
    reverse(all(f));
    rep(i, n) t[i] = a[i] * f[i];
    int l = -1, r = INF;
    while (r - l > 1)
    {
        int mid = (r + l) / 2;
        if (che(mid))
            r = mid;
        else
            l = mid;
    }
    cout << r << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(d2 == 1) {
        output(1);
    }
    else output(0);
    return 0;
}


Measured memory_bytes: 256
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>

using namespace std;

typedef long long LL;
static const LL MOD = 1000000007LL;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<int> b(n);
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
	}
	vector<int> ans;
	for (int i = 0; i < n; ++i) {
		int j;
		for (j = b.size() - 1; j >= 0; --j) {
			if (b[j] == j + 1) {
				ans.push_back(j + 1);
				b.erase(b.begin() + j);
				break;
			}
		}
		if (j < 0) {
			cout << "-1" << endl;
			return 0;
		}
	}
	for (int i = n - 1; i >= 0; --i) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef complex <double> cp;
#define debug(a) cout<<#a<<":"<<a<<endl;
#define fr freopen("in.txt","r",stdin);
#define for0(i,a,b) for (ll i=a;(i<b);i++)
#define for1(i,a,b) for (ll i=a;(i<=b);i++)
#define dec0(i,a,b) for (ll i=a;(i>b);i--)
#define dec1(i,a,b) for (ll i=a;(i>=b);i--)
#define Fill(x,a) memset(x,a,sizeof(x))
#define cpy(a,b) memcpy(a,b,sizeof(a))
const double PI = acos(-1);
const ll INF=0x3f3f3f3f;
const ll N=1e6+7;
const ll mod=1e9+7;
ll maxn,minn;
ll T,n,m,q;
 
vector<ll>arr[N];
ll a[N];
ll d[N];
ll dp[N];
 
ll cnt;
 
void dfs(ll u,ll p){
	ll len=arr[u].size();
	for(ll i=0;i<len;i++){
		ll inx,flag=0;
		int gg=cnt;
		ll v=arr[u][i];
		if(v==p)	continue;
		if(a[v]>d[cnt]){
			d[++cnt]=a[v];
		}
		else{
			flag=lower_bound(d+1,d+cnt+1,a[v])-d;
			inx=flag;
			flag=d[inx];
			d[inx]=a[v];
		}
		dp[v]=cnt;
		dfs(v,u);
		cnt=gg;
		if(flag)
			d[inx]=flag;
	}
	return ;
}
 
int main(){
	ll u,v;
	cin>>n;
	for(ll i=1;i<=n;i++){
		scanf("%lld",a+i);
	}
	for(ll i=1;i<n;i++){
		scanf("%lld%lld",&u,&v);
		arr[u].push_back(v);
		arr[v].push_back(u);
	}
	d[1]=a[1];
	dp[1]=1;
	cnt=1;
	dfs(1,0);
	for(ll i=1;i<=n;i++){
		printf("%lld\n",dp[i]);
	}
 
	return 0;
}
 

Measured memory_bytes: 53776
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int x = stdIn.nextInt();
		int y = stdIn.nextInt();
		while (true) {
			  if (x==0 && y==0) break;
			  if (x>y) System.out.println(y + " " + x);
			  else System.out.println(x + " " + y);
			  x = stdIn.nextInt();
			  y = stdIn.nextInt();
		}
        stdIn.close();
	}
}



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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

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

    int sum = 0;

    rep(i, n-1) sum += a.at(i+1)-a.at(i);

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
from fractions import Fraction
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 998244353

N,K = map(int,input().split())
move = []
for i in range(K):
    L,R = map(int,input().split())
    move.append((L,R))

dp = [0]*N
dp[0] = 1
Sum = [0]*(N+1)
Sum[1] = 1

for i in range(1,N):
    """
    print(i)
    print(dp)
    print(Sum)
    """
    for j in move:
        l,r = j[0],j[1]
        left = max(0,i-r)
        right = i-l

        if right >= 0:
            #print(i,right+1,left)
            dp[i] += Sum[right+1]-Sum[left]
            dp[i] %= MOD

        Sum[i+1] = Sum[i] + dp[i]
        Sum[i+1] %= MOD
"""
print(dp)
print(Sum)
"""
print(dp[-1])

Measured memory_bytes: 76528
import Data.List
main = do
  getLine
  w <- lines <$> getContents
  let double = solve $ sort w
      seq = siritori w
  if double && seq
    then putStrLn "Yes"
    else putStrLn "No"

solve :: [String] -> Bool
solve (_:[]) = True
solve (x:y:ys) = if x == y
                   then False
                   else solve (y:ys)

siritori :: [String] -> Bool
siritori (_:[]) = True
siritori (x:y:ys) = if (last x) == (head y)
                      then siritori (y:ys)
                      else False


Measured memory_bytes: 636
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define REP(i, k) for (std::decay_t<decltype(k)> i = 0; i < k; i++)
#define LOOP(k) REP (ngtkana_is_a_genius, k)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    u64 n; std::cin >> n;
    std::map<u64, u64> map;
    u64 ans = 0;
    while (n--) {
        u64 x; std::cin >> x;
        map[x]++;
        ans += x;
    }

    u64 q; std::cin >> q;
    while (q--) {
        u64 b, c; std::cin >> b >> c;
        auto it = map.find(b);
        if (it!=map.end()) {
            u64 x = it->second;
            ans -= b * x;
            ans += c * x;
            map.erase(it);
            map[c] += x;
        }
        std::cout << ans << '\n';
    }
}


Measured memory_bytes: 7468
#include <algorithm>
#include <vector>
#include <iostream>
#include "stdio.h"

using namespace std;

static const int NIL = -1;
static const int MAX = 1000000;

class Node{
public:
    int location;
    int p,l,r;
    Node(){
        location = p = l = r = NIL;
    }
};

class Point{
public:
    int id,x,y;
    Point(){
        id = x = y = 0;
    }
    Point(int id,int x,int y):id(id),x(x),y(y){
        
    }
    
    bool operator < (const Point &p) const {
        return id < p.id;
    }
    
    void outPutId(){
        //cout << id << endl;
        printf("%d\n",id);
    }
};

int N;
Point point[MAX];
Node tree[MAX];
int np = 0;

bool lessX(const Point &p1,const Point &p2){
    return p1.x < p2.x;
}

bool lessY(const Point &p1,const Point &p2){
    return p1.y < p2.y;
}

int makeKDTree(int l,int r,int depth){
    if(l >= r) return NIL;
    int mid = (l + r) / 2;
    int t = np++;
    
    if(depth % 2 == 0){
        sort(point + l,point + r,lessX);
    }else{
        sort(point + l,point + r,lessY);
    }
    tree[t].location = mid;
    tree[t].l = makeKDTree(l,mid, depth + 1);
    tree[t].r = makeKDTree(mid + 1,r,depth + 1);
    
    return t;
}

void find(int v,int sx,int tx,int sy,int ty,int depth,vector<Point> &ans){
    int x = point[tree[v].location].x;
    int y = point[tree[v].location].y;
    
    // 範囲内なら領域を入れる
    if(sx <= x && x <= tx && sy <= y && y <= ty){
        ans.push_back(point[tree[v].location]);
    }
    
    // 偶数x
    if(depth % 2 == 0){
        if(tree[v].l != NIL){
            if(sx <= x){
                find(tree[v].l,sx,tx,sy,ty,depth + 1,ans);
            }
            
        }
        if(tree[v].r != NIL){
            if(x <= tx){
                find(tree[v].r,sx,tx,sy,ty,depth + 1,ans);
            }
        }
    // 奇数がy
    }else{
        if(tree[v].l != NIL){
            if(sy <= y){
                find(tree[v].l,sx,tx,sy,ty,depth + 1,ans);
            }
            
        }
        if(tree[v].r != NIL){
            if(y <= ty){
                find(tree[v].r,sx,tx,sy,ty,depth + 1,ans);
            }
        }
    }
    
}

int main(void){
    int x,y,q,root;
    cin >> N;
    
    for(int i = 0;i < N;++i){
        //cin >> x >> y;
        scanf("%d %d",&x,&y);
        point[i] = Point(i,x,y);
    }
    root = makeKDTree(0, N, 0);
    //cin >> q;
    scanf("%d",&q);
    
    int sx,sy,tx,ty;
    vector<Point>ans;
    
    for(int i = 0;i < q;++i){
        //cin >> sx >> tx >> sy >> ty;
        scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
        ans.clear();
        find(root,sx,tx,sy,ty,0,ans);
        sort(ans.begin(),ans.end());
        for(int j = 0;j < ans.size();++j){
            ans[j].outPutId();
        }
        //cout << endl;
        printf("\n");
    }
}



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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0);

const int TMP = 1000000007;

int fact(int n) {
  int ans = 1;
  REP(i, n) {
    ans = (ans * (i+1)) % TMP;
  }
  return ans;
}

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, m; cin >> n >> m;
  int ans = 0;
  if(abs(n - m) > 1) {
    ans = 0;
  } else if(n == m) {
    ans = (2 * fact(n) * fact(m)) % TMP;
  } else {
    ans = (fact(n) * fact(m)) % TMP;
  }

  cout << ans << endl;
}


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

using namespace std;

int main(){
  
  long long n,tar;
  cin>>n>>tar;
  
  long long w[n],v[n];
  for(int i=0;i<n;i++)cin>>w[i]>>v[i];
  
  long long dp[n+1][tar+1];
  for(int i=0;i<=n;i++)dp[i][0]=0;
  for(int i=0;i<=tar;i++)dp[0][i]=0;
  
  for(int i=1;i<=n;i++){
    for(int j=1;j<=tar;j++){
      if(w[i-1]>j)
        dp[i][j]=dp[i-1][j];
      else
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
      
      //cout<<dp[i][j]<<" ";
    }
   // cout<<endl;
  }
  
  cout<<dp[n][tar]<<endl;
  
 return 0; 
}

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

signed main(){
       int n,k;
       cin >> n>>k;
       int h[n],a[n];
       cin >> h[0]>>h[1];
       a[0]=0;
       a[1]=abs(h[0]-h[1]);
       int j;
       for(int i=2;i<n;i++){
           cin >>h[i];
           j=i-1;
           a[i]=a[i-1]+abs(h[i-1]-h[i]);
           j--;
           while(j>=max(0,i-k)){
               if(a[i]>a[j]+abs(h[j]-h[i]))a[i]=a[j]+abs(h[j]-h[i]);
               j--;
           }

       }
       cout << a[n-1];


    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/03  Problem: ABC 047 D / Link: http://abc047.contest.atcoder.jp/tasks/abc047_d  ----- */


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

	LL N, T; cin >> N >> T;
	vector<LL> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	map<LL, LL>M;
	map<LL, LL>diffcnt;
	FOR(i, 0, N) {
		M[a[i]]++;
		auto it = M.begin();
		LL diff = a[i] - it->first;
		diffcnt[diff]++;
	}
	cout << diffcnt.rbegin()->second << endl;

	return 0;
}


Measured memory_bytes: 13568
a,b = list(map(int,input().split()))

count = 0

for i in range(a,b+1):
    S = []
    t = i
    while t!=0:
        s = t%10
        S.append(s)
        t//=10
    if S[0]==S[4] and S[1]==S[3]:
        count += 1

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  ll H, W;
  cin >> H >> W;

  auto f = [&](int H, int W) {
    ll ret = INFLL;
    for (ll h = 1; h <= H-1; ++h) {
      ll sa = h*W;
      ll sb = (H-h)/2*W;
      ll sc = (H-h-(H-h)/2)*W;
      ll smax = max({sa,sb,sc});
      ll smin = min({sa,sb,sc});
      ret = min(ret, smax-smin);

      sb = (H-h)*(W/2);
      sc = (H-h)*(W-W/2);
      smax = max({sa,sb,sc});
      smin = min({sa,sb,sc});
      ret = min(ret, smax-smin);
    }
    return ret;
  };

  ll ans;
  ans = min(f(H,W),f(W,H));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int gcd(int,int);
int main(){
  int x,y,GCD;
  scanf("%d%d",&x,&y);
  GCD = gcd(x,y);
  printf("%d\n",GCD);
  return 0;
}
int gcd(int x,int y){
  int z,temp;
  if(x < y){
    temp = y;
    y = x;
    x = temp;
  }
  z = x % y;
  while(z != 0){
    x = y;
    y = z;
    z = x % y;
  }
  return y;
}



Measured memory_bytes: 2144
#include<stdio.h>

int H, A[10000000];

void maxHeapify(int i){
    int l, r, largest;
    int tmp;
    l = 2*i;
    r = 2*i+1;

    if(l<=H && A[i] < A[l]) largest = l;
    else largest = i;

    if(r<=H && A[r] > A[largest]) largest = r;

    if(largest != i){
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        maxHeapify(largest);
    }
}
int main(){
    int i;
    scanf("%d", &H);

    for(i=1; i<=H; i++) scanf("%d", &A[i]);

    for(i=H/2; i>=1; i--) maxHeapify(i);

    for(i=1; i<=H; i++){
        printf(" %d", A[i]);
    }
    printf("\n");

    return 0;

}


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

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    string s;
    cin >> s;
    bool has_1 = false;
    valarray<int> vals(N);
    for (int i = 0; i < N; i++) {
        vals[i] = s[i] - '1';
        has_1 |= vals[i] == 1;
    }
    if (has_1)
        vals %= 2;
    else
        vals /= 2;
    bool parity = 0;
    for (int i = 0; i < N; i++) {
        parity ^= vals[i] && ((N - 1) | i) == N - 1;
    }
    cout << (parity ? (has_1 ? 1 : 2) : 0) << endl;
}


Measured memory_bytes: 5276
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int cnt[26],n,k;
string s;
int main()
{
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> s;
		cnt[s[0]-'A']++;
	}
	int ret = 0;
	while(1){
		sort(cnt,cnt+26,greater<int>());
		for(int i=0;i<k;i++){
			if(!cnt[i]){cout << ret << endl; return 0;}
			cnt[i]--;
		}
		ret++;
	}
}

Measured memory_bytes: 256
N = input()

s = str(N)
if s[-1] == "2" or s[-1] == "4" or s[-1] == "5" or s[-1]== "7" or s[-1]== "9":
    print("hon")
elif s[-1] == "0" or s[-1]== "1" or s[-1] == "6" or s[-1] == "8":
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9064
#include <stdio.h>

int main() {
    
    long double t;
    long double j;
    int n;
    scanf("%d", &n);
    
    n = abs(n);
    
    t = (n / 3);
    j = n % 3;
    t = (t + (j/3))*(t + (j/3))*(t + (j/3));
 
    printf("%Lf\n", t);

    return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	mod := 1000000007
	var n int
	fmt.Scanf("%d", &n)
	arr := make([]int, n, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &arr[i])
	}
	var sum int
	var tmp int
	for i := 0; i < n; i++ {
		tmp += arr[i]
		tmp %= mod
	}
	for i := 0; i < n-1; i++ {
		tmp -= arr[i]
		if tmp < 0 {
			tmp += mod
		}
		sum += arr[i] * tmp
		sum %= mod
	}

	fmt.Println(sum)
}


Measured memory_bytes: 6496
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

sys.setrecursionlimit(10000)
INF = float('inf')



A, P  = list(map(int, input().split()))
print((A * 3+P) // 2)


Measured memory_bytes: 22040
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int k, s;

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

    void run() {
        FastReader sc = new FastReader();
        k = sc.nextInt();
        s = sc.nextInt();
        solve();
    }

    void solve() {
        long count = 0;
        for (int x = 0; x <= k; x++) {
            for (int y = 0; y <= k; y++) {
                int z = s - x - y;
                if (z >= 0 && z <= k) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    int ans = 0;
    int cnt = 0;
    rep(i,n-1){
        if(a[i] >= a[i+1]){
            cnt++;
        }else{
            ans = max(ans,cnt);
            cnt = 0;
        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
//G.cpp
#include<bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
using namespace std;


int main(){
	int n, m;
	cin >> n;
	vector< vector<double> > dp(n, vector<double> (n+1,  0));

	double p;
	vector < double > prob(n, 0);

	double ans = 0;
	for(int i = 0; i < n; i++){
		cin >> p;
		prob[i] = p;
		if(!i)
			dp[i][0] = 1 - p;
		else
			dp[i][0] = dp[i-1][0] * (1 - p);
		

	}
	dp[0][1] = prob[0];
	if(n == 1){
		cout <<  dp[0][1] << endl;
		return 0;
	}

	for(int i = 1; i < n; i++){
		for(int j = 1; j <= n; j++){
			if(i+1 < j)
				continue;
			dp[i][j] = dp[i-1][j-1]*prob[i] + dp[i-1][j]*(1 - prob[i]);
			if(i == (n - 1) && j > n/2){
				ans += dp[n-1][j];
			}

		}
		
	}

	// for(int i = 0; i < n; i++){
	// 	for(int j = 0; j <= n; j++){
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
		
	// }
	cout << setprecision(10) << ans << endl;

	return 0;
}

Measured memory_bytes: 74152
E = 10 ** -9
MOD = 100000007
fact_result = {}

while True:
  n = int(input())
  if n == 0: break
  plst = []
  wlst = []
  diff = []
  to = [None for _ in range(n)]
  for i in range(n):
    p, Id, w = input().split()
    to[i] = int(Id)
    plst.append(float(p))
    wlst.append(float(w))
    diff.append(1 / float(w) - 1 / float(p))

  def elapsed_time(group):
    ret = 0
    ret += 1 / plst[group[0]]
    for g in group[1:]:
      ret += 1 / wlst[g]
    return ret

  def init_comb(group):
    d = diff[group[0]]
    ret = 0
    for g in group:
      if abs(diff[g] - d) < E:
        ret += 1
    return ret

  def fact(n):
    if n == 0:
      return 1
    if n in fact_result:
      return fact_result[n]
    fact_result[n] = n * fact(n - 1)
    return fact_result[n]

  used = [False] * n
  time = 0
  comb = fact(n)
  group_cnt = 0
  for i in range(n):
    if used[i]: continue
    group_cnt += 1
    group = [i]
    used[i] = True
    nex = to[i]
    while not used[nex]:
      group.append(nex)
      used[nex] = True
      nex = to[nex]
    group.sort(key=lambda x:-diff[x])
    time += elapsed_time(group)
    comb //= fact(len(group))
    comb *= init_comb(group)
  print(time, comb % MOD)


Measured memory_bytes: 5672
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let nm: Vec<usize> = read_vec();
    let n = nm[0];
    let m = nm[1];
    let mut xyz: Vec<Vec<i64>> = read_vec2(n);

    let mut ans = -1000000000000000;

    for i in vec![-1, 1] {
        for j in vec![-1, 1] {
            for k in vec![-1, 1] {
                xyz.sort_by(|xyz1, xyz2| {
                    (i * xyz2[0] + j * xyz2[1] + k * xyz2[2])
                        .partial_cmp(&(i * xyz1[0] + j * xyz1[1] + k * xyz1[2]))
                        .unwrap()
                });

                let mut tmp = 0;
                for l in 0..m {
                    tmp += i * xyz[l][0] + j * xyz[l][1] + k * xyz[l][2];
                }
                if tmp > ans {
                    ans = tmp;
                }
            }
        }
    }

    println!("{}", ans);
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

int vmap[110][110];

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int W, H, N;
	cin >> W >> H >> N;
	int X, Y, A;
	rep(i, 0, N)
	{
		cin >> X >> Y >> A;
		switch (A)
		{
		case 1:
			rep(y, 0, H)rep(x, 0, X)vmap[y][x] = 1;
			break;
		case 2:
			rep(y, 0, H)rep(x, X, W)vmap[y][x] = 1;
			break;
		case 3:
			rep(y, 0, Y)rep(x, 0, W)vmap[y][x] = 1;
			break;
		case 4:
			rep(y, Y, H)rep(x, 0, W)vmap[y][x] = 1;
			break;
		}
	}

	int ans = 0;
	rep(i, 0, H)rep(j, 0, W)
	{
		if (vmap[i][j] == 0)ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
using System;
class A_Harmony{
	static void Main(string[] args){
		String[] AB = Console.ReadLine().Split(' ');
		int A = int.Parse(AB[0]);
		int B = int.Parse(AB[1]);
		if(Math.Abs(A + B) % 2 == 0)Console.WriteLine((A + B) / 2);
		else Console.WriteLine("IMPOSSIBLE");
	}
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

ll n, k, w[110], v[110], ans, dp[110][100010];

int main(){
	cin >> n >> k;
	for(int i=1;i<=n;i++){
		cin >> w[i] >> v[i];
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=100000;j++){
			if(i!=0||j!=0) dp[i][j] = -1;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<=100000;j++){
			if(j-v[i]>=0&&dp[i-1][j-v[i]]!=-1){
				dp[i][j] = dp[i-1][j-v[i]] + w[i];
			}
			if(dp[i-1][j]!=-1){
				if(dp[i][j]!=-1){
					dp[i][j] = min(dp[i][j], dp[i-1][j]);
				}else{
					dp[i][j] = dp[i-1][j];
				}
			}
		}
	}
	for(ll i=0;i<=100000;i++){
		if(dp[n][i]<=k&&dp[n][i]!=-1) ans = max(ans, i);
	}
	cout << ans << endl;
	return 0;
}

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

const int N = 100005;
const int mod = 1e9 + 7;

int n, m;
int a[N], b[N];

void add(int &x, int y) {
	x += y; while(x >= mod) x -= mod; while(x < 0) x += mod;
}

struct FenwickTree {
	int t[N];
	
	void upd(int x, int v) {
		for (; x < N; x += x & -x) {
			add(t[x], v);
		}
	}

	int get(int x) {
		int ret = 0;
		for (; x > 0; x -= x & -x) {
			add(ret, t[x]);
		}
		return ret;
	}
} bit;

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

	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	for (int i = 1; i <= m; ++i) {
		cin >> b[i];
	}

	vector < pair<int,int> > p;
	vector <int> z;
	int ptr = 1;

	for (int i = 1; i <= n; ++i) {
		while(ptr <= m && b[ptr] < a[i]) ++ptr; --ptr;
		if (ptr == 0 || ptr == m) continue;
		int x = a[i] - b[ptr];
		int y = b[ptr + 1] - a[i];
		p.push_back({x, y});
		z.push_back(y);
	}

	sort(p.begin(), p.end());
	z.push_back(0);
	sort(z.begin(), z.end());
	z.erase(unique(z.begin(), z.end()), z.end());

	bit.upd(1, 1);
	for (int i = 0; i < p.size(); ++i) {
		if (i > 0 && p[i] == p[i - 1]) continue;
		int y = lower_bound(z.begin(), z.end(), p[i].second) - z.begin() + 1;
		int r = bit.get(y - 1);

		if (i > 0 && p[i].first == p[i - 1].first) {
			int prev_y = lower_bound(z.begin(), z.end(), p[i - 1].second) - z.begin() + 1;
			add(r, -bit.get(prev_y - 1));
		}
		bit.upd(y, r);
	}

	cout << bit.get(N - 1) << endl;
}

Measured memory_bytes: 2932
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))

def insertionSort(l,n,g):
    cnt=0
    for i in range(g,n):
        v=l[i]
        j=i-g
        while j>=0 and l[j]>v:
            l[j+g]=l[j]
            j=j-g
            cnt+=1
        l[j+g]=v
    return l,cnt

def SP(l):
    for i in range(len(l)):
        if i !=len(l)-1:
            print(l[i],end=' ')
        else:
            print(l[i]) 

def shellSort(l,n):
    cnt=0
    G=[1]
    while True:
        if G[-1]*3+1<=n:
            G.append(G[-1]*3+1)
        else:
            G.reverse()
            break
    print(len(G))
    SP(G)
    for i in G:
        l,c=insertionSort(l,n,i)
        cnt+=c
    print(cnt)
    for i in l:
        print(i)

shellSort(a,n)


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

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  
  if(s == u) cout << a-1 << " " << b << endl;
  else cout << a << " " << b-1 << endl;
  }

Measured memory_bytes: 256