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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, c;
  while (cin >> a >> b >> c) {
    cout << (b - a == c - b ? "YES" : "NO") << endl;
  }
  
  return 0;
}


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

using namespace std;

int main() {
	int n, p;
	cin >> n >> p;
	string s;
	cin >> s;
	if (p == 5 || p == 2) {
		long long ans = 0;
		for (int i = 0; i < s.size(); i++) {
			if ((s[i] - '0') % p == 0) {
				ans += i + 1;
			}
		}
		cout << ans << endl;
		return 0;
	}
	vector<vector<int>> st(p, vector<int>(20, 0));
	for (int i = 0; i < p; i++) {
		st[i][0] = i * 10 % p;
	}
	for (int k = 1; k < 20; k++) {
		int b = 1 << k;
		for (int i = 0; i < p; i++) {
			int j = st[i][k - 1];
			st[i][k] = st[j][k - 1];
		}
	}
	map<int, int> r;
	int x = 0;
	long long ans = 0;
	for (int i = 0; i < s.size(); i++) {
		x = (x * 10 + s[i] - '0') % p;
		if (x == 0) {
			ans++;
		}
		int y = x, k = s.size() - i;
		for (int j = 0, b = 1; b <= k; j++, b <<= 1) {
			if ((b & k) == b) {
				y = st[y][j];
			}
		}
		if (!r.count(y)) {
			r[y] = 0;
		}
		ans += r[y];
		r[y]++;
	}
	cout << ans << endl;
	return 0;
}

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

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(1e6 + 10), Mod(924844033);
struct edge { int next, to; } e[N << 1];
int n, head[N], e_num, size[N], f[N], g[N], w[N], r[N], fac[N], inv[N], c[N];
int C(int x, int y) { return 1ll * fac[x] * inv[y] % Mod * inv[x - y] % Mod; }
inline void add_edge(int from, int to)
{
	e[++e_num] = (edge) {head[from], to};
	head[from] = e_num;
}

int fastpow(int x, int y)
{
	int ans = 1;
	for (; y; y >>= 1, x = 1ll * x * x % Mod)
		if (y & 1) ans = 1ll * ans * x % Mod;
	return ans;
}

void dfs(int x, int fa)
{
	size[x] = 1;
	for (int i = head[x]; i; i = e[i].next)
	{
		int to = e[i].to; if (to == fa) continue;
		dfs(to, x), size[x] += size[to], ++g[size[to]];
	}
	++g[n - size[x]];
}

void FFT(int *p, int N)
{
	for (int i = 0; i < N; i++) if (i < r[i]) std::swap(p[i], p[r[i]]);
	for (int i = 1, s = 2, t = N >> 1; i < N; s <<= 1, t >>= 1, i <<= 1)
		for (int j = 0; j < N; j += s) for (int k = 0, o = 0; k < i; ++k, o += t)
		{
			int x = p[j + k], y = 1ll * w[o] * p[i + j + k] % Mod;
			p[j + k] = (x + y) % Mod, p[i + j + k] = (x - y + Mod) % Mod;
		}
}

int main()
{
	n = read(), fac[0] = inv[0] = 1;
	for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
	inv[n] = fastpow(fac[n], Mod - 2);
	for (int i = n - 1; i; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % Mod;
	for (int i = 1, a, b; i < n; i++)
		a = read(), b = read(), add_edge(a, b), add_edge(b, a);
	dfs(1, 0), g[0] = 0;
	for (int i = 1; i <= n; i++) c[i] = 1ll * n * C(n, i) % Mod;
	for (int i = 1; i <= n; i++) g[i] = 1ll * g[i] * fac[i] % Mod;
	for (int i = 0; i <= n; i++) f[i] = inv[i];
	std::reverse(g, g + n + 1); int N = 1, P = -1;
	while (N <= ((n + 1) << 1)) N <<= 1, ++P;
	for (int i = 1; i < N; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << P);
	w[0] = 1, w[1] = fastpow(5, (Mod - 1) / N);
	for (int i = 2; i < N; i++) w[i] = 1ll * w[i - 1] * w[1] % Mod;
	FFT(f, N), FFT(g, N), w[1] = fastpow(554906420, (Mod - 1) / N);
	for (int i = 2; i < N; i++) w[i] = 1ll * w[i - 1] * w[1] % Mod;
	for (int i = 0; i < N; i++) f[i] = 1ll * f[i] * g[i] % Mod;
	FFT(f, N); int invn = fastpow(N, Mod - 2);
	for (int i = 0; i < N; i++) f[i] = 1ll * f[i] * invn % Mod;
	for (int i = 1; i <= n; i++) f[i] = 1ll * f[i] * inv[n - i] % Mod;
	for (int i = 1; i <= n; i++) printf("%d\n", (c[i] - f[n - i] + Mod) % Mod);
	return 0;
}


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

int main(){

  char a,b;
  cin >> a >> b;
  
  if(a=='H'){
  	if(b=='H')cout << 'H';
    else cout << 'D';
  }else{
  	if(b=='H')cout << 'D';
    else cout << 'H';
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
		
		Map<String, Operation> operations = new HashMap<String, Operation>();
		operations.put("+", new Add());
		operations.put("-", new Subtract());
		operations.put("*", new Multiply());
		operations.put("/", new Divide());

		Stack<Double> stack = new Stack<Double>();
		String line;
		while(true) {
			line = sc.readLine();
			if(line == null) {break;}
			
			for(String str : line.split(" ")) {
				if(operations.containsKey(str)) {
					operations.get(str).calc(stack);
				} else {
					stack.push(Double.valueOf(str));
				}
			}
			System.out.println(stack.pop());
		}
	}
}

interface Operation {
	void calc(Stack<Double> stack);
}
class Add implements Operation {
	public void calc(Stack<Double> stack) {
		double b = stack.pop().doubleValue();
		double a = stack.pop().doubleValue();
		stack.push(Double.valueOf(a + b));
	}
}
class Subtract implements Operation {
	public void calc(Stack<Double> stack) {
		double b = stack.pop().doubleValue();
		double a = stack.pop().doubleValue();
		stack.push(Double.valueOf(a - b));
	}
}
class Multiply implements Operation {
	public void calc(Stack<Double> stack) {
		double b = stack.pop().doubleValue();
		double a = stack.pop().doubleValue();
		stack.push(Double.valueOf(a * b));
	}
}
class Divide implements Operation {
	public void calc(Stack<Double> stack) {
		double b = stack.pop().doubleValue();
		double a = stack.pop().doubleValue();
		stack.push(Double.valueOf(a / b));
	}
}

Measured memory_bytes: 16968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll>PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e4+7;
int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if ( !(abs(a-b)&1) ) cout << abs(a-b)/2 << endl;
    else                 cout << min(a-1, n - b) + 1 + ( b - a - 1) / 2 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

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

    ll n,m;
    cin >> n >> m;
    unordered_map <ll,ll> lis;
    for (ll i=0;i<n;i++){
        ll k;
        cin >> k;
        for (ll j=0;j<k;j++){
            ll a;
            cin >> a;
            lis[a]++;
        }
    }
    ll ans = 0;
    for (auto itr = lis.begin(); itr != lis.end(); itr++){
        if(itr -> second == n){
            ans++;
        }
    }
    cout << ans << endl;

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
int ans = 0;
int n, ma, mb;
int dp[40][405][405];
vector<pair<ii, int> >a;
int solve(int idx, int sa, int sb){
  if(idx == n){
    if(!sa || !sb)return 1e8;
    return (sa/__gcd(sa,sb) == ma && sb/__gcd(sa,sb) == mb) ? 0 : 1e8;
  }
  int &ret = dp[idx][sa][sb];
  if(ret != -1)return ret;
  ret = 1e8;
  ret  = min(solve(idx + 1, sa + a[idx].F.F, sb + a[idx].F.S) + a[idx].S,solve(idx+1,sa,sb));
  ret = min(ret, 100000000);
  return ret;
}
int main(){
  memset(dp, -1, sizeof dp);
  cin >> n >> ma >> mb;
  a.resize(n);
  for(int i = 0 ;i < n; i++)
    cin >> a[i].F.F >> a[i].F.S >> a[i].S;
  if(solve(0,0,0) == 1e8)puts("-1");
  else cout << solve(0,0,0) << endl;
}


Measured memory_bytes: 25856
import sys
input = sys.stdin.readline

def linput():
	return list(map(int,input().split()))

def pad(mxy, wall="#"):
	w = len(mxy[0])
	gp = wall*(w+2)
	re = [gp,]
	re_app = re.append
	for vx in mxy:
		re_app(wall+vx+wall)
	re_app(gp)
	return re

def main():
	H,W = linput()
	mM = [input().rstrip() for _ in [0,]*H]
	mM = pad(mM,".")
	mV = [[0,]*(W+2) for _ in [0,]*(H+2)]
	
	vD = [(0,1),(1,0)]
	
	res = False
	cnt = 0
	
	vQ = []
	vQ_app, vQ_pop = vQ.append, vQ.pop
	if mM[1][1]=="#":
		vQ_app((1,1))
	while vQ:
		x,y = vQ_pop()
		#print(x,y)
		if (x,y)==(W,H):
			res = True; mV[H][W] = 1; break
		
		
		t = 0
		for dx,dy in vD:
			nx,ny = x+dx, y+dy
			if mM[ny][nx]=="#" and \
			not mV[ny][nx]:
				t += 1
				vQ_app((nx,ny))
		
		if t>0:
			mV[y][x] = 1

		cnt += 1
		#print(res,cnt,X,Y,H)
		if cnt>999999: break
	
	if res:
		for vm,vv in zip(mM,mV):
			#print(vm,vv)#
			if not all(v for m,v in 
			  zip(vm,vv) if m=="#"):
				res = False; break
	
	print(("Impossible","Possible")[res])
	#print(res)

if __name__ == "__main__":
	main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repp(i,a,b) for(int i=a;i<=b;i++)
#define endl '\n'
bool sortt(const pair<int,string> &a,  
               const pair<int,string> &b) 
{ 
       return (a.first > b.first); 
} 
signed main()   
{
    fast
    int n; cin>>n;
    int arr[n],dp[n+5];
    rep(i,0,n) cin>>arr[i];
    dp[0]=0;dp[1]=abs(arr[1]-arr[0]);
    rep(i,2,n){
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,K=get_i
A=get_i
r=A.inject(0){|res,x| res.gcd(x)}
(N-K).times do|i|
    if A[i]<A[i+K]
        puts "Yes"
    else
        puts "No"
    end
end

Measured memory_bytes: 36112
tmp = input()
l = len(tmp)
N = int(tmp)

ans = 0
if l%2 != 0:
    ans = N - 10**(l-1) + 1
    l -= 1

for i in range(1, l, 2):
    ans += 10**i - 10**(i-1)


print(ans)


Measured memory_bytes: 2940
#include<stdio.h>

int main(void)
{
    int x, y; 

    do{
	scanf("%d %d", &x, &y);
	if(x > y ){
	if(x > 0 || y > 0) printf("%d %d\n", y, x);
	}
	if(x < y){
	if(x > 0 || y > 0) printf("%d %d\n", x, y);
	}
	if(x == y){
	if(x > 0 || y > 0) printf("%d %d\n", x, y);
	}
    }while(x > 0 || y > 0);
    
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/
int main(){
    vector<int> ans(0);
    while(true){
        int N; cin >> N;
        if (N == 0) break;
        string s; 
        int res = 0;
        int now = 0; // 0なら床、1なら台上
        int left = 0,right = 0;
        for (int i = 0; i < N; i++){
            cin >> s;
            if (s == "lu"){
                left = 1;
            } else if (s == "ru"){
                right = 1;
            } else if (s == "ld"){
                left = 0;
            } else if (s == "rd"){
                right = 0;
            }

            if (right == left && right == 1 && now == 0){
                res++;
                now = 1;
            } else if (right == left && right == 0 && now == 1){
                res++;
                now = 0;
            }
        }
        ans.push_back(res);
    }
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3112
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int 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;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//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) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) 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(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

//myfuncs
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

int main(int argc, char const* argv[])
{
	string s;
	int k;
	cin >> s >> k;
	set<string> ss;
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < s.length() - i; j++) {
			ss.insert(s.substr(j,i+1));
		}
	}
	auto itr = ss.begin();
	for (int i = 0; i < k-1; i++) {
		itr++;
	}
	cout << *itr << endl;
	return 0;
}


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

int main(void)
{
    double v, t, y, N;
    
    while(cin >> v)
    {
        t = v / 9.8;
        y = 4.9 * t * t;
        N = (y+5)/5;
        cout << (int)++N << endl;
    }
    return 0;
}

Measured memory_bytes: 1224
#include<cstdio>

const int MOD = 1e9 + 7, MAX_N = 2e5;
int n, a, b;

int po(int x, int y) {
    int ans = 1;
    while (y > 0) {
        if (y & 1) ans = static_cast<long>(ans) * x % MOD;
        x = static_cast<long>(x) * x % MOD;
        y >>= 1;
    }
    return ans;
}

int fac[MAX_N + 1], inv[MAX_N + 1];

int main() {
    scanf("%d %d %d", &n, &a, &b);
    fac[0] = 1;
    for (int i = 1; i <= MAX_N; i++) {
        fac[i] = static_cast<long>(fac[i - 1]) * i % MOD;
    }
    inv[MAX_N] = po(fac[MAX_N], MOD - 2);
    for (int i = MAX_N - 1; i >= 0; i--) {
        inv[i] = static_cast<long>(inv[i + 1]) * (i + 1) % MOD;
    }
    
    int ans = po(2, n) - 1;    
    int c = inv[a], d = inv[b];
    for (int i = 0; i < a; i++) c = static_cast<long>(c) * (n - i) % MOD;
    for (int i = 0; i < b; i++) d = static_cast<long>(d) * (n - i) % MOD;
    ans = (static_cast<long>(ans + MOD - c) % MOD + MOD - d) % MOD;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1664
import sys

n, t = map(int, sys.stdin.readline().split())
l = [tuple(map(int, sys.stdin.readline().split())) for _ in range(n)]

ans = 10000000000000000000
flag = False
for cost, time in l:
    if time > t:
        continue

    if cost < ans:
        ans = cost
        flag = True

if flag:
    print(ans)
else:
    print("TLE")

Measured memory_bytes: 3060
#include <stdio.h>
#pragma warning(disable:4996)
//FILE *in = fopen("input.txt", "r"), *out = fopen("output.txt", "w");
FILE *in = stdin, *out = stdout;
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 0x7fffffff
#define NM 100005
#define MOD 1000000007
#define FOR(i,n,m) for (int i=(n);i<=(m);i++)
#define si(n) fscanf(in,"%d",&n)
#define sd(n) fscanf(in,"%lf",&n)
typedef long long int ll;
struct LIST {
	int x, y;
	LIST() {}
	LIST(int x, int y) :x(x), y(y) {}
	bool operator<(const LIST& rhs) {
		return x < rhs.x;
	}
}Q1[NM], Q2[NM];
int N1, N2;
vector<int> Y1[NM], Y2[NM];
int a[NM], n, m;
ll ans[NM];
void input() {
	si(n); si(m);
	FOR(i, 1, n) {
		si(a[i]);
		if (i == 1) continue;
		if (a[i] > a[i - 1]) {
			Q1[++N1] = LIST(a[i - 1], a[i]);
		}
		else {
			Q2[++N2] = LIST(a[i], a[i - 1]);
		}
	}
	sort(Q1 + 1, Q1 + 1 + N1);
	sort(Q2 + 1, Q2 + 1 + N2);
	FOR(i, 1, N1) Y1[Q1[i].y].push_back(i);
	FOR(i, 1, N2) Y2[Q2[i].y].push_back(i);
}
void solve_inc(LIST Q[], vector<int> Y[], int N) {
	int HN = 0;
	ll tot = 0;
	FOR(i, 1, N) tot += Q[i].y - Q[i].x;
	int last = 1, cnt = 0;
	FOR(i, 1, m) {
		while (last <= N && Q[last].x == i - 1) {
			tot -= Q[last].y - Q[last].x;
			tot += Q[last].y;
			cnt++; last++;
		}
		ans[i] += tot - (ll)cnt * (i - 1);
		for (auto &idx:Y[i]){
			tot -= Q[idx].y;
			tot += Q[idx].y - Q[idx].x;
			cnt--;
		}
	}
}
void solve_dec(LIST Q[], vector<int> Y[], int N) {
	ll tot = 0, cnt = N;
	FOR(i, 1, N) tot += Q[i].x;
	ans[1] += tot;

	int last = 1;
	FOR(i, 2, m) {
		while (last <= N && Q[last].x == i - 1) {
			tot -= Q[last].x;
			tot += (m - Q[last].y) + Q[last].x;
			cnt--; last++;
		}
		ans[i] += tot + cnt * (1 - i);
		for (auto &idx : Y[i]) {
			tot -= (m - Q[idx].y) + Q[idx].x;
			tot += m + Q[idx].x;
			cnt++;
		}
	}
}
int main() {
	input();
	solve_inc(Q1, Y1, N1);
	solve_dec(Q2, Y2, N2);
	ll res = 1e18;
	FOR(i, 1, m) res = min(res, ans[i]);
	fprintf(out, "%lld", res);
	return 0;
}

Measured memory_bytes: 9216
x, k, d = map(int,input().split())

a = abs(x % d)
a_sho = abs(x // d)
b = abs(a-d)

if k <= a_sho:
    ans = abs(x) - (k*d)
else:
    #if a < b:
    if (k - a_sho) %2 == 0:
        ans = a
    else:
        ans = b
print(ans)


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int N, M, K, H, W, L, R;
string S, T;
signed main(){
  cin >> N;
  vi x(N), y(N), h(N);
  rep(i,N) cin >> x[i] >> y[i] >> h[i];
  
  int h0;
  if(h[0] == 0){
    rep2(i,1,N){
      if(h[i] != 0) {h0 = i; break;}
    }
    swap(x[0],x[h0]);
    swap(y[0],y[h0]);
    swap(h[0],h[h0]);
  }
  
  vvi field(101,vi(101,0));
  rep(i,101){ // data0からのpeak を計算
    rep(j,101){
      field[i][j] = h[0]+ abs(x[0]-i)+abs(y[0]-j);
    }
  }
  bool chk = true;
  rep(i,101){ 
    rep(j,101){
      chk = true;
      rep2(k,1,N){
        int H = field[i][j] -abs(i-x[k]) - abs(j-y[k]);
        if(H<0) H = 0;
        if( H != h[k] ) {
          chk = false;
          break;
        }
      }
      if(chk){
        cout << i << " " << j << " " << field[i][j] << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3700
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip> 
using namespace std;
bool cmp (char a,char b){
	return a>b;
}
int main(){
	string a,b;
	getline(cin,a);
	getline(cin,b);
	sort(a.begin(),a.end());
	sort(b.begin() ,b.end() ,cmp);
	if(a<b)
	cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
n, m = map(int,input().split())
s = []
for i in range(n):
    s.append(input())
t = []
for i in range(m):
    t.append(input())
found = False
for i in range(0,n-m+1):
    for j in range(0,n-m+1):
        f = True
        for k in range(m):
            for l in range(m):
                if t[k][l] != s[i+k][j+l]:
                    f = False
                    break
        if f == True:
            found = True

if found :
    print("Yes")
else:
    print("No")


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

#define M 1000000007

using namespace std;

typedef pair<int, int> P;

vector<int> v[200001];
vector<P> sect;
long dp[200001];

int main(){
    int N;
    int C[200000];
    long sum[200001] = {0};
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> C[i];
        v[C[i]].push_back(i);
    }
    for(int i = 1; i <= 200000; i++){
        for(int j = 1; j < v[i].size(); j++){
            if((v[i][j]-v[i][j-1]) > 1) sect.push_back(P(v[i][j], v[i][j-1]));
        }
    }
    sort(sect.begin(), sect.end());
    
    dp[0] = 1;
    sum[0] = 1;
    int idx = 0;
    for(int i = 0; i < sect.size(); i++){
        int l = sect[i].second;
        int r = sect[i].first;
        if(idx < l){
            for(int j = idx+1; j <= l; j++){
                sum[j] = (sum[j-1]+dp[j])%M;
            }
            idx = l;
        }
        dp[r] = sum[l];
        for(int j = idx+1; j <= r; j++){
            sum[j] = (sum[j-1]+dp[j])%M;
            //cout << "sum:" << sum[j] << endl;
        }
        idx = r;
    }
    long ans = 0;
    for(int i = 0; i <= N; i++){
        //cout << dp[i] << ' ';
        ans = (ans+dp[i])%M;
    }
    //cout << endl;
    cout << ans << endl;
}

Measured memory_bytes: 13568
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <tuple>

int tsurai(int r, int g, int b) {
  return r*r + g*g + b*b;
}

int testcase_ends() {
  char c;
  scanf(" %c", &c);
  if (c == '0') return 1;

  int r, g, b;
  scanf("%2x%2x%2x", &r, &g, &b);

  std::vector<std::pair<std::string, std::tuple<int, int, int>>> col;
  int f = 255;
  
  col.emplace_back("black", std::make_tuple(0, 0, 0));
  col.emplace_back("blue", std::make_tuple(0, 0, f));
  col.emplace_back("lime", std::make_tuple(0, f, 0));
  col.emplace_back("aqua", std::make_tuple(0, f, f));
  col.emplace_back("red", std::make_tuple(f, 0, 0));
  col.emplace_back("fuchsia", std::make_tuple(f, 0, f));
  col.emplace_back("yellow", std::make_tuple(f, f, 0));
  col.emplace_back("white", std::make_tuple(f, f, f));

  int d = 1e9;
  std::string res;
  for (auto const& p: col) {
    std::string cur;
    std::tuple<int, int, int> rgb;
    std::tie(cur, rgb) = p;
    int r0, g0, b0;
    std::tie(r0, g0, b0) = rgb;

    int cur_d = tsurai(r0-r, g0-g, b0-b);
    if (d > cur_d) {
      d = cur_d;
      res = cur;
    }
  }
  printf("%s\n", res.c_str());
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2724
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef pair<int, int> Pii;
typedef vector<int> Vi;
const int INF = (1<<30);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

int main() {
  int n;
  while( cin >> n, n ) {
    int data[10][10], h[10]={0}, w[10]={0};
    int sum = 0;
    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) {
	cin >> data[i][j];
	h[i] += data[i][j];
	w[j] += data[i][j];
	sum += data[i][j];
      }
    }

    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) {
	printf("%5d", data[i][j]);
      }
      printf("%5d\n", h[i]);
    }

    for(int i=0; i<n; i++) printf("%5d", w[i]);
    printf("%5d\n", sum);
  }
}

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


int main(){
	
	int n,k;
	cin>>n>>k;
	int ans = 0;
	int h;
	for(int i =0;i<n;i++){
		
		cin>>h;
		if(h>= k)
			ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
N , K = map(int,input().split())
lst = []
for _ in range(N):
    a , b = map(int,input().split())
    lst.append([a , b])
lst.sort()
for i in range(N):
    if K <= lst[i][1]:
        print(lst[i][0])
        exit()
    else:
        K -= lst[i][1]


Measured memory_bytes: 58840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

const int Max = 1e7;
vector<int> mps(Max+1);

void mpsinit(){//O(NloglogN)
    for(int i = 0; i <= Max; i++) mps[i] = i;
    for(ll i = 2; i*i <= Max; i++){
        if(mps[i] == i){
            for(ll j = i*i; j <= Max; j += i){
                if(mps[j] == j) mps[j] = i;
            }
        }
    }
}
template<typename T>
unordered_set<T> prime_factorization(T n){//O(logN)
    unordered_set<T> ret;
    while(mps[n] != n){
        ret.insert(mps[n]);
        n = n/mps[n];
    }
    ret.insert(mps[n]);
    return ret;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    mpsinit();
    unordered_map<int,bool> seen;
    bool pc = true;

    for(int i = 0; i < n; i++){
        if(a[i] == 1) continue;
        unordered_set<int> fp = prime_factorization(a[i]);
        for(auto p:fp){
            if(seen[p]) pc = false;
            seen[p] = true;
        }
    }

    int g = __gcd(a[0],a[1]);
    for(int i = 0; i < n; i++) g = __gcd(g,a[i]);

    if(pc) cout << "pairwise coprime" << endl;
    else if(g == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
}

Measured memory_bytes: 49532
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <cstdio>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
const int INF=1<<30;
int dx[5]={0,1,0,-1,0}, dy[5]={1,0,-1,0,0};
using namespace std;
typedef pair<int,int> pr;
typedef pair<int,pr> ppr;
typedef vector<int> vi;
typedef vector<pr> vpr;
vpr to[100000];
int froms[100000];
bool able[100000][101];
int main() {
	int V,E,w;
	cin >>V >> E >>w;
	REP(i,E){
		int a,b,l;
		scanf("%d%d%d",&a,&b,&l);
		to[a].push_back(pr(b,l));
		froms[b]++;
	}
	queue<int> qu;
	REP(i,V)
		if(!froms[i])
			qu.push(i);
	while(!qu.empty()){
		int now=qu.front();
		qu.pop();
		REP(j,to[now].size()){
			int cost=to[now][j].second,next=to[now][j].first;
			able[next][cost]=true;
			FORE(i,cost+1,100)
			able[next][i]|=able[now][i-cost];
			froms[next]--;
			if(froms[next]==0)
			qu.push(next);
		}
	}
	int maxim=-INF;
	REP(i,V)
		FOR(j,0,-w)
			if(able[i][j])
			maxim=max(maxim,j);
	if(maxim==-INF)
	cout <<"NA" << endl;
	else
	cout <<maxim+w << endl;
	// your code goes here
	return 0;
}


Measured memory_bytes: 21484
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

struct RW {
    ll s,t,x;
    RW(){}
    RW(ll s, ll t, ll x): s(s),t(t),x(x){}
    bool operator<(const RW &r) const {
        return (s!=r.s) ? s < r.s : t > r.t;
    }
};


int main(int argc, char const *argv[]) {
    int n,q; cin>>n>>q;
    vector<RW> r(n), ev;
    vector<ll> d(q);
    rep(i,n) cin>>r[i].s>>r[i].t>>r[i].x;
    rep(i,q) cin>>d[i];

    rep(i,n) {
        int s = r[i].s; int t = r[i].t; int x = r[i].x;
        RW tmp1 = RW(s-x, 0, x); RW tmp2 = RW(t-x, 1, x);
        ev.push_back(tmp1); ev.push_back(tmp2);
    }

    ev.push_back(RW(LINF,0,LINF));
    sort(ev.begin(), ev.end());

    set<ll> st;
    int ind = 0;

    for (auto &&e: ev) {
        ll s = e.s; ll t = e.t; ll x = e.x;
        // printf("s = %lld, t = %lld, x = %lld\n",s,t,x);

        while (s > d[ind] && ind < q) {
            // printf("d[%d] = %lld\n",ind,d[ind]);
            if (!st.empty() && *st.begin()!=LINF) cout << *st.begin() << endl;
            else cout << -1 << endl;
            ++ind;
        }

        if (!t) st.insert(x);
        else st.erase(x);
    }
    
    return 0;
}

Measured memory_bytes: 26600
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100010;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int main(){
    int x; cin >> x;
    int y = 360;
    while(true){
        if(y % x == 0){
            cout << y / x << endl;
            return 0;
        }
        y += 360; 
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define in auto&it
#define out auto it 
#define rep(i,si,n) for(int i=si;i<n;++i)
#define all ar.begin(),ar.end()
const double pi=acos(-1);
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		//freopen("error.txt","w",stderr);
	#endif
	fastio
	int n;
	cin>>n;
	string s;
	cin>>s;
	int cnt=0,ans=0;
	for(int i=0;i<n;++i) if(s[i]=='R') ++ cnt;
	for(int i=0;i<cnt;++i) if(s[i]=='W') ++ans;
		cout<<ans;
	//cerr<<"time:  "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<'\n';
	return 0;
}


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

int main(int argc, char const *argv[])
{
	int nums;
	while(~scanf("%d",&nums)){
		int fr[nums],bk[nums],arr[nums];
		for (int i = 0; i < nums; ++i)
			scanf("%d",&arr[i]);
		fr[0]=arr[0];
		bk[nums-1]=arr[nums-1];
		for (int i = 1; i < nums; ++i)
			fr[i]=__gcd(arr[i],fr[i-1]);
		for (int i = nums-2; i >= 0; --i)
			bk[i]=__gcd(arr[i],bk[i+1]);

		// for (int i = 0; i < nums; ++i)
		// {
		// 	printf("fr[%d]==%d\n",i,fr[i] );
		// }

		// for (int i = 0; i < nums; ++i)
		// {
		// 	printf("bk[%d]==%d\n",i,bk[i] );
		// }

		int ans=0;
		for (int i = 0; i < nums; ++i)
		{
			if (i==0)
				ans=max(ans,bk[i+1]);
			else if (i==nums-1)
				ans=max(ans,fr[i-1]);
			else{
				ans=max(ans, __gcd( bk[i+1],fr[i-1]) );
			}

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

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> x(n), y(n + 1, 0);
  rep(i, 0, n) {
    cin >> x[i];
    y[i + 1] = y[i] + x[i];
  }
  int ans = 0;
  rep(i, 0, n - 1) {
    int now = y[n] - y[i + 1];
    now %= mod1;
    ans += now * x[i];
    ans %= mod1;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 6336
from heapq import heappop, heappush

N, M = map(int, input().split())
adj = [[] for _ in range(N)]

for i in range(N-1):
    adj[i+1].append((i,0))

for i in range(M):
    L, R, C = map(int, input().split())
    adj[L-1].append((R-1,C))

q = [] # 始点のコストとindex
heappush(q,0)
INF = 10**18
d = [INF] * N
d[0] = 0

while len(q) > 0:
    u = heappop(q)
    for v in adj[u]:
        tmp = d[u] + v[1]
        if tmp < d[v[0]]:
            d[v[0]] = tmp
            heappush(q, v[0])

print(d[N-1]) if d[N-1] < INF else print(-1)


Measured memory_bytes: 111644
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str  = sc.nextLine();
        String[] astr = str.split(" ");
        int n = 0;
        int l = 0;
        Boolean flag  = true;
        int[] in_data = Stream.of(astr).mapToInt(x->{
            try{
                return Integer.parseInt(x);
            }
            catch(Exception e){
                e.printStackTrace();
            }
            return 0;
        }).toArray();
        sc.close();

        n = in_data[0];
        l = in_data[1];
        int[] vaule = new int[n];
        for(int i=0;i<n;i++){
            vaule[i] = l + i;
        }
        int sum = java.util.Arrays.stream(vaule).sum();
        int min_vaule = min(vaule);
        if(sum <= 0){
            System.out.println(sum + min_vaule);
        }
        else{
            System.out.println(sum - min_vaule);
        }

    }

    public static int min(int [] hoge){
        int min = Math.abs(hoge[0]);
        for(int i =0;i< hoge.length;i++){
            if(min > Math.abs(hoge[i])){
                min = Math.abs(hoge[i]);
            }
        }
        return min;
    }
}

Measured memory_bytes: 28500
N = int(input())
word_count = {}
for i in range(N):
  word = input()
  if word in word_count.keys():
    word_count[word] += 1
  else: 
    word_count[word] = 1
sorted_word_count = sorted(word_count.items(), key=lambda x:x[1], reverse=True)
answer = []
first = True
max_count = 0
for word in sorted_word_count:
  if (first):
    answer.append(word[0])
    max_count = word[1]
    first = False
  else:
    if (max_count == word[1]):
      answer.append(word[0])
    else:
      break
sorted_answer = sorted(answer)
for a in sorted_answer:
  print(a)

Measured memory_bytes: 155040
#include <iostream>
#include <cmath>
#include <complex>
#include <vector>
#include <set>
#include <iomanip>


using namespace std;
typedef long double ld;
typedef long long ll;
const int MAX = 60;
typedef complex<long double> Point;


namespace std {
    bool operator<(const Point &lhs, const Point &rhs) {
        return lhs.real() == rhs.real() ? lhs.imag() < rhs.imag() : lhs.real() < rhs.real();
    }
}

struct Circle {
    Point c;
    ld r;

    vector<Point> cross(const Circle &other) {
        vector<Point> ret;
        ld dist = abs(c - other.c);
        ld rc = (dist * dist + r * r - other.r * other.r) / (2 * dist);
        ld dfr = r * r - rc * rc;
        if (abs(dfr) < 1e-6) dfr = 0.0;
        if (dfr < 0.0) {
            return ret;
        }
        ld rs = sqrt(dfr);
        Point diff = (other.c - c) / dist;
        ret.push_back(c + diff * Point{rc, rs});
        if (dfr != 0.0) {
            ret.push_back(c + diff * Point{rc, -rs});
        }
        return ret;
    }
};

const ld eps = 1e-9;
int n, k;
Circle m[MAX + 1];
int c[MAX + 1];


int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    cin >> n >> k;

    set<Point> centers;
    for (int i = 0; i < n; ++i) {
        ld xc, yc;
        cin >> xc >> yc >> c[i];
        m[i] = {Point{xc, yc}};
        centers.insert(m[i].c);
    }

    ld hi = 1e6;
    ld lo = 0;
    for (int ii = 0; ii < 100; ++ii) {
        ld t = lo + (hi - lo) / 2;
        set<Point> candidate(centers);

        for (int i = 0; i < n; ++i) {
            m[i].r = (ld) t / (ld) c[i];
            for (int j = 0; j < n; ++j) {
                if (i == j) continue;
                m[j].r = (ld) t / (ld) c[j];
                auto ret = m[i].cross(m[j]);
                for (auto pt : ret) {
                    candidate.insert(pt);
                }
            }
        }

        int mc = 0;
        for (auto pt : candidate) {
            int count = 0;
            for (int i = 0; i < n; ++i) {
                ld diff = abs(m[i].c - pt);
                if (diff < m[i].r + eps) {
                    ++count;
                }
            }
            mc = max(mc, count);
        }

//        if (mc < k) {
//            lo = t + eps;
//        } else {
//            hi = t;
//        }
        if (mc >= k) {
            hi = t;
        } else {
            lo = t;
        }
    }

    cout << hi;

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#define MAX 100001
#define max2(a,b) a<b?b:a
#define max3(a,b,c) max2((max2(a,b)),c)
#define max4(a,b,c,d) max3((max2(a,b)),c,d)

int main(){
	int i,a,b,c,q,w,e,r,t,y;
	int n;
	char s[MAX];
	q=w=c=e=0;
	
	scanf("%d%d%d%s",&n,&a,&b,s);
	for(i=0;i<n;i++){
		switch(s[i]){
			case 'a':
			if(c<a+b){
				c++;
				puts("Yes");
				continue;
			}
			break;
			case 'b':
			if(c<a+b){
				if(e<b){
					c++;
					e++;
				puts("Yes");
				continue;
				}
			}
			break;
		}
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int,input().split()))

flag=True
count=0
while flag:
    flag=False
    for j in range(n-1, 0, -1):
        if (a[j] < a[j-1]):
            (a[j-1], a[j]) = (a[j], a[j-1])
            flag=True
            count += 1
print(' '.join(map(str,a)))
print(count)



Measured memory_bytes: 5600
from collections import defaultdict
N=int(input())

xlist,ylist=[],[]
for i in range(N):
  xs,ys,d=input().split()
  x=int(xs)
  y=int(ys)
  if d=="L":
    xlist.append((x,-1))
    ylist.append((y,0))
  elif d=="R":
    xlist.append((x,1))
    ylist.append((y,0))
  elif d=="U":
    xlist.append((x,0))
    ylist.append((y,1))
  else:
    xlist.append((x,0))
    ylist.append((y,-1))
#print(xlist,ylist)

xdic=defaultdict(set)
for x,d in xlist:
  xdic[d].add(x)
#print(xdic)
xlist2=[]
for d in [-1,0,1]:
  if len(xdic[d]):
    min_d=min(xdic[d])
    max_d=max(xdic[d])
    xlist2.append((min_d,d))
    xlist2.append((max_d,d))
  
ydic=defaultdict(set)
for y,d in ylist:
  ydic[d].add(y)
#print(ydic)
ylist2=[]
for d in [-1,0,1]:
  if len(ydic[d]):
    min_d=min(ydic[d])    
    max_d=max(ydic[d])
    ylist2.append((min_d,d))
    ylist2.append((max_d,d))
#print(xlist2,ylist2)

def cand_time(plist):
  ret=set()
  for i in range(len(plist)):
    p1,d1=plist[i]
    for j in range(i+1,len(plist)):
      p2,d2=plist[j]
      if d1==d2:
        continue
        
      if d1==-1:
        if d2==0:
          t=p1-p2
        else:
          t=(p1-p2)/2
      elif d1==0:
        if d2==-1:
          t=p2-p1
        else:
          t=p1-p2
      else:
        if d2==-1:
          t=(p2-p1)/2
        else:
          t=p2-p1
       
      if t>0:
        ret.add(t)
  return ret

cand_time_x=cand_time(xlist2)
cand_time_y=cand_time(ylist2)
#print(cand_time_x,cand_time_y)
cand_t=[0]+list(cand_time_x)+list(cand_time_y)
#print(cand_t)

def get_pos(pd,t):
  p,d=pd
  return p+d*t

answer=float("inf")
for t in cand_t:
  pos_min_x=float("inf")
  pos_max_x=-float("inf")
  for x2 in xlist2:
    pos_min_x=min(pos_min_x,get_pos(x2,t))
    pos_max_x=max(pos_max_x,get_pos(x2,t))
    
  pos_min_y=float("inf")
  pos_max_y=-float("inf")
  for y2 in ylist2:
    pos_min_y=min(pos_min_y,get_pos(y2,t))
    pos_max_y=max(pos_max_y,get_pos(y2,t))

  #print(t,pos_min_x,pos_max_x,pos_min_y,pos_max_y)
  t_ans=abs(pos_max_x-pos_min_x)*abs(pos_max_y-pos_min_y)
  if answer>=t_ans:
    answer=t_ans
    #print(answer,t,abs(pos_max_x-pos_min_x),abs(pos_max_y-pos_min_y))
  
print(answer)

Measured memory_bytes: 37128
import bisect
import math
def solve():
  s = int(input())
  if s == 0:
    print("NA")
    exit()
  
  if s//100 != 0 and s//100 <= 12:
    tp = s%100
    if 1<= tp and tp <= 12:
      print("AMBIGUOUS")
    elif tp == 0:
      print("MMYY")
    elif 13 <= tp and tp <= 99:
      print("MMYY")
    else:
      print("NA")
  else:
    tp = s%100
    if 1<= tp and tp <= 12:
      print("YYMM")
    else:
      print("NA")
solve()


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

using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
int arr[12];

vector<int> ss;

int main(){
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    ss.push_back(0);

    int prod = 1;
    int all = 1;
    for(int i = 0; i < n; i++){
        all*=3;
    }
    for(int i = 0; i < n; i++){
        int l;
        cin >> l;
        if(l%2 == 0){
            prod*=2;
        }
    }
    cout << all - prod;

    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define INF 1e9

int n;
int a,b,c;
vi l;
int ans = INF;

void dfs(int idx, int A, int B, int C, int cost)
{
    if (idx==n){
        if (A==0 || B==0 || C==0) return;
        cost-=30;
        cost += abs(A-a)+abs(B-b)+abs(C-c);
        chmin(ans, cost);
        return;
    }
    dfs(idx+1,A+l[idx],B,C,cost+10);
    dfs(idx+1,A,B+l[idx],C,cost+10);
    dfs(idx+1,A,B,C+l[idx],cost+10);
    dfs(idx+1,A,B,C,cost);
}

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    cin>>a>>b>>c;
    l.resize(n);
    rep(i,n) cin>>l[i];
    dfs(0,0,0,0,0);
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace AtcoderExpress
{


    class Program2
    {
        static long mod = 1000000007;
        static void Main(string[] args)
        {
            var NXY = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var N = NXY[0];
            var X = NXY[1];
            var Y = NXY[2];
            var sa = Y - X-1;

            var map = new long[N + 1, N + 1];
            
            //init
            for (int i = 1; i <= N; i++)
            {
                for (int j = 1; j <= N; j++)
                {
                    map[i, j] = Abs(j - i);
                }
            }
            map[X, Y] = 1;
            for (int i = 1; i <= N; i++)
            {
                for (int j = 1; j <= N; j++)
                {
                    map[i, j] = Min(map[i, j], map[i, X] + map[Y, j] + 1);
                    map[i, j] = Min(map[i, j], map[i, Y] + map[X, j] + 1);
                }
            }

                    var ans = new long[N];
            for (int i = 1; i <= N; i++)
            {
                for (int j = i+1; j <= N; j++)
                {
                    //if(i <= X && j >= Y)
                    //{
                    //    map[i, j] -= sa;

                    //}
                    if (map[i, j] > 0)
                    {
                        ans[map[i, j]]++;
                    }
                    //Console.Write(map[i, j]);
                }
               // Console.WriteLine();
            }


            for (int i = 1; i < N; i++)
            {
                Console.WriteLine(ans[i]);
            }
            
        }
    }
}


Measured memory_bytes: 44384