akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
from decimal import Decimal

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def prime_fact(N):
    n = 2
    prime = []
    while n * n <= N:
        i = 0
        while N % n == 0:
            N //= n
            i += 1
        if i > 0:
            prime.append((n, i))
        n += 1
    if N != 1:
        prime.append((N, 1))
    return prime


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

    N = ii()
    prime = prime_fact(N)

    ret = 0
    for p, e in prime:
        i = 1
        while e >= i:
            e -= i
            i += 1
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10720
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map(String::toLong)
    val bList = readLine()!!.split(' ').map(String::toLong)
    val aSum = aList.sum()
    val bSum = bList.sum()
    if (aSum < bSum) {
        println(-1)
        return
    }
    val diffList = (0 until n).map { aList[it] - bList[it] }.sortedDescending()
    val minusDiffList = diffList.filter { it < 0 }
    val minusCount = minusDiffList.size
    val minusSum = minusDiffList.sum()
    var offsetSum = 0L
    if (minusCount == 0) {
        print(0)
    } else {
        for (i in 0..diffList.size) {
            offsetSum += diffList[i]
            if (offsetSum >= - minusSum) {
                print(minusCount + i + 1)
                return
            }
        }
    }
}


Measured memory_bytes: 84596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    string ans = "Yes";
    rep(i, a+b+1) {
        if (i==a) {
            if (s[i]!='-') ans = "No";
        }
        else {
            if (s[i]=='-') ans = "No";
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}




int main(){
    long long L, R;
    cin >> L >> R;

    int ans = 2020;
    if(R-L >2018){
        cout << 0 << endl;
        return 0;
    }

    for(long long i = L; i<R ;i++){
        for(long long j = i+1; j<=R; j++){
            int a = (i*j)%2019;
            ans = min(ans,a);
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int sum;
int main() {
	int n;
	cin >> n;
	int t = n;
	while(t) {
		sum += t % 10;
		t /= 10;
	}
	if(n % sum == 0) cout << "Yes\n";
	else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
k, n = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

max = k -A[n-1] + A[0]
for i in range(n-1):
    if (A[i + 1] - A[i]) > max:
        max = (A[i + 1] - A[i])

print(k-max)


Measured memory_bytes: 26436
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

  int H,W;
  int sy,sx;
  int cnt;
  boolean[][] map;
  int[] dy = {-1,0,1,0}, dx = {0,1,0,-1}; 
  public static void main(String[] args) {
    new Main().run();
  }
  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out) ) {

      String[] lines;
      // StringBuilder buf = new StringBuilder();
      while(true) {
        lines = in.readLine().split(" ");
        W = Integer.parseInt(lines[0]);
        H = Integer.parseInt(lines[1]);

        if( W==0 && H==0) break;

        map = new boolean[H][W];

        String line;
        for(int y=0; y<H; y++) {
          char ch;
          line = in.readLine();
          for(int x=0; x<W; x++) {
            ch = line.charAt(x);
            map[y][x] = ch == '#' ? false : true;
            if(ch == '@') {
              sy = y; sx = x;
            }
          }
        }

        cnt = 0;
        dfs(sy,sx);
        // buf.append(cnt).append("\n");
        out.println(cnt);
      }

      // System.out.print(buf);
      out.flush();
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  private void dfs(int y, int x) {
    map[y][x] = false;
    cnt++;

    for(int i=0; i<4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if(0 <= ny && ny < H && 0 <= nx && nx < W && map[ny][nx]) {
        dfs(ny,nx);
      }
    }
    return;
  }
}


Measured memory_bytes: 26848
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::min;

fn main() {
    input!{
        n: u64,
        a: u64,
        b: u64,
    };
    let m = n / (a + b);
    let c = n % (a + b);
    println!("{}", a * m + min(a, c));
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
using namespace std;
 
 
int main() {
    double a, b, c, d, e, f;
     
    while(cin >> a >> b >> c >> d >> e >> f){
        double x = (e*c-b*f)/(a*e-b*d);
        double y = (-c*d+a*f)/(a*e-b*d);
        if(x==0) x=0;
        if(y==0) y=0;
        printf("%.3f %.3f\n",x,y);
    }
 
}

Measured memory_bytes: 3196
arp = list(" abcdefghijklmnopqrstuvwxyz")
ans = []
N = int(input())
while N != 0:
    K = N % 26
    if K == 0:
        K = 26
    ans.append(arp[K])
    N -= K
    N = N // 26
ans.reverse()
print("".join(ans))

Measured memory_bytes: 9196
n, k, s = gets.split.map(&:to_i)
result = []

if n == k
  n.times do
    result << s
  end

  puts result.join(' ')
  exit

end

if s.even?
  if k > 0
    (k + 1).times do
      result << s / 2
    end

    (n - (k + 1)).times do
      result << s / 2 + 3
    end
  else
    n.times do
      result << s / 2 + 3
    end
  end
end

if s.odd?
  if s == 1
    (n - k).times do
      result << 2
    end
    k.times do
      result << 1
    end
    puts result.join(' ')
    exit

  end

  if k > 0
    flag = false
    (k + 1).times do
      tmp = flag ? s / 2 : s / 2 + 1
      result << tmp
      flag = !flag
    end

    (n - (k + 1)).times do
      result << s / 2 + 3
    end
  else
    n.times do
      result << s / 2 + 3
    end
  end
end

puts result.join(' ')


Measured memory_bytes: 5628
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#define mk make_pair
#define pii pair<int,int>
using namespace std;
const int N = 1000 + 3;
char s[N][N];
int n,m;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int high[N][N];
queue <pii> q;
int ans;
inline void bfs(){
	while(!q.empty()){
		pii k = q.front();
		q.pop();
		for(int i = 0;i < 4;++i){
			int xx = k.first + dx[i],yy = k.second + dy[i];
			if(xx < 1 || xx > n || yy < 1 || yy > m || high[xx][yy] != -1) continue;
			high[xx][yy] = high[k.first][k.second] + 1;
			ans = max(ans,high[xx][yy]);
			q.push(mk(xx,yy));
		}
	}
}
int main(){
	memset(high,-1,sizeof(high));
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;++i) scanf("%s",s[i] + 1);
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= m;++j){
			if(s[i][j] == '#')	high[i][j] = 0,q.push(mk(i,j));
		}
	bfs();
	printf("%d\n",ans);
	return 0;	
}

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

int main(){
  int N;
  string S;
  cin>>N>>S;
  vector <int> E(N,0);
  vector <int> W(N,0);
  int tempE=0;
  int tempW=0;
  
  for (int i=0;i<N;i++){
    if(S.at(i)=='E'){
      tempE++;
    }
    E[i]=tempE;
  }
   for (int i=N-1;i>-1;i--){
    if(S.at(i)=='W'){
      tempW++;
    }
    W[i]=tempW;
  } 
  int ans=0;
  int minans=N;
  for (int i=0;i<N;i++){
    ans=abs(E[N-1]-E[i])+abs(W[0]-W[i]);
    minans=min(minans,ans);
    //cout<<abs(E[N-1]-E[i])<<"#"<<abs(W[0]-W[i])<<"$"<<minans<<endl;
  }
  cout<<minans<<endl;
}

               
    


    
      
      

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    while (1) {
        int n, q; cin >> n >> q;
        if (!n) break;

        vector<int> conv(101);
        rep(i, 0, n) {
            int m; cin >> m;
            rep(j, 0, m) {
                int t; cin >> t;
                conv[t]++;
            }
        }
        int best = 0;
        rep(i, 1, 101) if (conv[i] >= q && conv[i] > conv[best]) best = i;
        cout << best << endl;
    }
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.14159265359
#define all(v) v.begin(),v.end()
#define vil vector<long int>
#define vi vector<int> 
#define pb(x) push_back(x)
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ub upper_bound
#define lb lower_bound
#define INF 1000000007 
#define MOD 998244353
void solve(ll T){
    ll n,k;
    cin>>n>>k;
    vil a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
  ll dp[n+1];
  dp[0]=0;
  dp[1]=0;
  dp[2]=abs(a[1]-a[0]);
  for(int i=3;i<=n;i++){
      dp[i]=INF;
      for(int j=1;j<=k&&j<i;j++){
          dp[i]=min(dp[i],dp[i-j]+abs(a[i-1]-a[i-1-j]));
      }
  }
cout<<dp[n]<<endl;
   return;
}
int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
ll T;
T=1;
//cin>>T;
while(T--){
   solve(T);
return 0;
}
}

Measured memory_bytes: 4760
#include<iostream>

using namespace std;

int main()
{

	int a,b,c,d;
	cin >> a >> b >> c >> d;
	
	int life_T = a;
	int life_A = c;
		
	while(life_T > 0 && life_A > 0){

		life_A = life_A - b;
		if(life_A > 0){
			life_T = life_T - d;
		}

	}

	if(life_T > 0){
	
	cout << "Yes" << endl;
	}

	else{

	cout << "No" << endl;
	
	}

	return 0;



}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include <stdio.h>
#include <iostream>
#include <vector>
#include <set>
#include <math.h>
using namespace std;
using ll = long long;

using Graph = vector<vector<int>>;

int main(){
    int n;
    cin >>n;
    int m = n%10;
    if(m==2|m==4|m==5|m==7|m==9)
        cout << "hon" << endl;
    else if(m==3)
        cout << "bon" << endl;
    else
        cout << "pon" <<endl;
    
    return 0;
}




Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n , q ;
  string s ;
  cin >> n >> q >> s  ;
  int A[n] ={0};
  int now = 0 ;
  
  for(int i=1;i<n;i++){
    if(s.at(i-1) == 'A' && s.at(i) =='C') 
      now ++ ;
    A[i] = now ;
  }
  
  rep(i,q){
    int l , r ;
    cin >> l >> r ;
    cout << A[r-1] - A[l-1] <<endl ;
  }
  
  
  
}


Measured memory_bytes: 1408
n = int(input())
h = list(map(int, input().split()))
cost = [0 for _ in range(n)]
cost[1] = abs(h[1] - h[0])
for i in range(2, n):
    cost[i] = min([cost[i-1] + abs(h[i] - h[i-1]),
                   cost[i-2] + abs(h[i] - h[i-2])])
print(cost[-1])


Measured memory_bytes: 13928
a, b, c, x = [int(input()) for _ in range(4)]
count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 * j + 50 * k == x:
                count += 1
print(count)

Measured memory_bytes: 39536
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long H, W;
    cin >> H >> W;
    std::vector<std::vector<char>> mat(H, vector<char>(W));
    for(size_t i=0;i<H; i++)
    {
        string line;
        cin >> line;
        for(size_t c=0;c<line.size(); c++)
        {
            mat[i][c] = line[c];
        }
    }
    vector<int> row_skip;
    vector<int> col_skip;

    for(size_t i=0;i<H; i++)
    {
        bool skip = true;
        for(size_t j=0;j<W; j++)
        {
            if(mat[i][j] == '#')
            {
                skip = false;
                break;
            }
            //cerr << mat[i][j] << " ";
        }
        if(!skip) row_skip.push_back(i);
        //cerr << endl;
    }

    for(size_t j=0;j<W; j++)
    {
        bool skip = true;
        for(size_t i=0;i<H; i++)
        {
            if(mat[i][j] == '#')
            {
                skip = false;
                break;
            }
        }
        if(!skip) col_skip.push_back(j);
    }

    for(size_t i=0;i<row_skip.size(); i++)
    {
        for(size_t j=0;j<col_skip.size(); j++)
        {
            cout << mat[row_skip[i]][col_skip[j]];
        }
        cout << endl;
    }
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

int main(){
	string s; cin>>s;
	int a = 0, b = 0;
	for(int i=0; i<s.size(); ++i){
		if(s[i]=='0')++a;
		if(s[i]=='1')++b;
	}
	cout<< min(a,b)*2 <<endl;
}

Measured memory_bytes: 512
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n = 0
for i in range(a[0]):
    c = list(map(int, input().split()))
    p = a[2]
    for j in range(a[1]):
        p += c[j] * b[j]
    if(p > 0):
        n += 1
print(n)

Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):b[a[i]-1]=i
ans=0
l,r=[i for i in range(n+1)],[i for i in range(n+1)]
for i in range(n-1,-1,-1):
  ans+=(i+1)*(b[i]-l[b[i]]+1)*(r[b[i]]-b[i]+1)
  l[r[b[i]]+1],r[l[b[i]]-1]=l[b[i]],r[b[i]]
print(ans)

Measured memory_bytes: 35812
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define PI          3.1415926535897932384626433832795l

#define pb push_back
#define mp make_pair
#define lb lower_bound // First element which is not less than val
#define ub upper_bound // First element greater than val
#define f first
#define s second

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;

using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define endl '\n'
#define re return
#define repz(i, a) for (ll i = 0; i < (a); i++)
#define vecin(n,v) for(ll i = 0; i < n; i++) cin>>v[i];
#define full(v) v.begin(),v.end()

void solve()
{
  ll n,c;
  cin >> n >> c;
  vll x(n+1);
  vll v(n+1);

  for (int i =1; i <= n; i++)
  {
    cin >> x[i] >> v[i];
  }

  ll dp[n][2];
  memset(dp,0,sizeof(dp));
  ll curr = 0;
  for (int i = 1; i <= n; i++)
  {
    curr += v[i];
    dp[i][0] = max(dp[i-1][0],curr-x[i]);
    dp[i][1] = max(dp[i-1][1],curr-x[i]*2);
  }

  ll ans = dp[n][0];
  curr =0;

  for (int i = n; i > 0; i--)
  {
    curr += v[i];
    ans = max(ans,curr+dp[i-1][0] - (c-x[i])*2);
    ans = max(ans,curr+dp[i-1][1] - (c-x[i]));
  }

  cout << ans << endl;
  
}

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

  ll t = 1;
  //cin >> t;
  while (t--)
  {
    solve();
  }
}



Measured memory_bytes: 6348
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	long A, B, K;
	cin >> A >> B >> K;

	if(K <= A){
		cout << A - K << " " << B <<endl;
	}else if(K <= A+B){
		cout << 0 << " " << A + B - K <<endl;
	}else{
		cout << 0 << " " << 0 <<endl;
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long N, M, R;
int main(){
    cin>>N>>M>>R;
    if(N%2 == 1 && M%2 == 1 && R%2 == 1){
        printf("%lld\n", min(R*N, min(N*M, M*R)));
    }else{
        printf("0\n");
    }
}


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

const int M = 2e5 + 100;
const int mod = 1e9 + 7;

vector<int> e[M];
int n, sz[M], ans[M];
int fac[M], inv[M];

LL mul(LL a, LL b) {
    return a * b % mod;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i <= n; i++) fac[i] = mul(fac[i - 1], i);
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = mul((mod - mod / i), inv[mod % i]);
}

void dfs(int u, int fa) {
    sz[u] = 1;
    for (int v : e[u]) {
        if (v != fa) {
            dfs(v, u);
            sz[u] += sz[v];
        }
    }
}

void reroot(int u, int fa) {
    ans[u] = mul(mul(ans[fa], sz[u]), inv[n - sz[u]]);
    for (int v : e[u]) {
        if (v != fa) {
            reroot(v, u);
        }
    }
}

int main() {
    cin >> n;
    init();
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs(1, 0);
    ans[1] = fac[n];
    for (int i = 1; i <= n; i++) ans[1] = mul(ans[1], inv[sz[i]]);
    for (int v : e[1]) reroot(v, 1);
    for (int i = 1; i <= n; i++) cout << ans[i] << "\n";
}


Measured memory_bytes: 17012
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,k,a[500010],tag[500010];
int main(){
	cin>>n>>k;
	FOR(i,1,n) getint(a[i]);
	while (k--){
		bool fi=1;
		FOR(i,1,n) if (a[i]!=n) fi=0;
		if (fi) break;
		FOR(i,0,n+1) tag[i]=0;
		FOR(i,1,n){
			int l=i-a[i],r=i+a[i];
			l=max(l,1);
			r=min(r,n);
			if (l>r) continue;
			++tag[l],--tag[r+1];
		}
		FOR(i,1,n){
			tag[i]+=tag[i-1];
			a[i]=tag[i];
		}
	}
	FOR(i,1,n) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 5260
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

struct UnionFind{
    vector<int> d;
    UnionFind(int n = 0):d(n,-1){};

    int find(int x){
        if(d[x] < 0) {
            return x;
        }
        else{
            return d[x] = find(d[x]);
        }
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);

        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    int size(int x){
        return -d[find(x)];
    }

};

int main() {
    int N;
    scanf("%d",&N);

    int X[N];
    rep(i,N)scanf("%d",&X[i]);
    int ans = 1000000;
    int souwa[100];
    rep(i,100){
        souwa[i] = 0;
        rep(j,N){
            souwa[i] += ((i+1)-X[j])*((i+1)-X[j]);
        }
        if(ans > souwa[i]){
            ans = souwa[i];
        }
    }
    printf("%d",ans);


}

int A(){
    int N,K;
    scanf("%d %d",&N,&K);
    if(N < 10){
        printf("%d",K+100*(10-N));
    }
    else{
        printf("%d",K);
    }
    return 0;
}

int B(){
    long long int N,K;
    scanf("%lld %lld",&N,&K);
    long long int count = 0;
    long long int digit = 1;
    while(1){
        digit = digit*K;
        count++;
        if(N == digit ){
            printf("%lld",count+1);
            return 0;
        }
        else if(N/digit == 0){
            printf("%lld",count);
            return 0;
        }
    }
}

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

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

int main(void){
    ll a, b;
    cin >> a >> b;
    cout << lcm(a,b) << endl;
    return 0;
}


Measured memory_bytes: 256
num = int(input())

lists = []

for i in range(1, num+1):
  inpu = input()
  name = inpu.split()[0]
  score = int(inpu.split()[1])
  a = [int(i), name, int(score)]
  lists.append(a)
  
sor = sorted(lists, key=lambda x:(x[1], -x[2]))

for a in sor:
  print(a[0])

Measured memory_bytes: 3064
k, n = (int(x) for x in input().split())
arr = [int(x) for x in input().split()]

def dist(x, y):
    v = abs(x -y)
    return min(v, k-v)

arr.sort()

if n == 2:
    sol = dist(*arr)
else:
    sol = k - max(dist(arr[i-1], arr[i]) for i in range(n))

print(sol)



Measured memory_bytes: 26444
#define _overload3(_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(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int a[] = {0, 0, 0, 0, 0};
    rep(i, 5) cin >> a[i];

    int sum = 0;
    rep(i, 5){
        sum += a[i];
        if(a[i] % 10 != 0){
            sum += 10-(a[i] % 10);
        }
    }

    int min = 10;
    int mod;
    rep(i, 5){
        mod = a[i] % 10;
        if(mod != 0){
            min = std::min(min, mod);
        }
    }
    sum -= (10 - min);
    cout << sum << endl;
}

Measured memory_bytes: 256
def main():
    nvertices, nedges = map(int, input().split())
    adj = [[0] * nvertices for j in range(nvertices)]
    for i in range(nedges):
        u, v, c = map(int, input().split())
        adj[u][v] = c

    INF = float('inf')
    ans = 0
    while True:
        parents = bfs(0, nvertices - 1, adj)
        if parents is None:
            break
        v = nvertices - 1
        f = INF
        while parents[v] != -1:
            u = parents[v]
            f = min(f, adj[u][v])
            v = u

        ans += f
        v = nvertices - 1
        while parents[v] != -1:
            u = parents[v]
            adj[u][v] -= f
            adj[v][u] += f
            v = u

    print(ans)


def bfs(s, t, adj):
    nvertices = len(adj)
    visited = [False] * nvertices
    visited[s] = True
    que = [s]
    parents = [-1] * nvertices
    while que:
        u = que.pop(0)
        if u == t:
            return parents

        for v in range(nvertices):
            if not visited[v] and adj[u][v] > 0:
                parents[v] = u
                visited[v] = True
                que.append(v)

    return None


main()

Measured memory_bytes: 7856
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    string s;
    cin >> s;
    int k;
    cin >> k;
    vector<string> d;
    int n = s.size();
    rep(i,n) {
        string tmp;
        rep(j,k) {
            if (i+j >= n) break;
            tmp += s[i+j];
            d.push_back(tmp);
        }
    }
    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());
    string ans = d[k-1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4316
from math import sqrt
N = int(input())
# Cが固定されAxBを入れ替えるときは省略したい

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

ans = 0
""" for C in range(1,N):
    ans += len(make_divisors(N-C)) """

for A in range(1,N):
    ans += (N-1)//A

print(ans)

Measured memory_bytes: 63228
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

int getAbs(int x);

int main(){
    int x, a, b;
    cin >> x >> a >> b;
    char c = (getAbs(x - a) < getAbs(x - b))? 'A' : 'B';
    cout << c << endl;
    return 0;
}

int getAbs(int x){
    return (x > 0)? x : -x;
}

Measured memory_bytes: 256
def find_equal(lis, n):
    sum_l = 0
    sum_r = 0
    r_c = n - 1
    l_c = 0
    all_processed = 0
    while True:
        if sum_l <= sum_r:
            sum_l += lis[l_c]
            l_c += 1
            all_processed += 1
        elif sum_r < sum_l:
            sum_r += lis[r_c]
            r_c -= 1
            all_processed += 1
        if all_processed == n:
            break
    return sum_l, sum_r


n = int(input())
nums = list(map(int, input().split()))
ans = find_equal(nums, len(nums))
print(max(ans) - min(ans))


Measured memory_bytes: 26220
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;
typedef pair<int, double> P;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		double min_BMI = 99999999;
		vector<P> data;
		for(int i = 0; i < n; ++i)
		{
			int a;
			cin >> a;
			double h, w;
			cin >> h >> w;
			double BMI = 10000 * w / (h * h);
			data.push_back(P(a, fabs(22 - BMI)));
			if(fabs(22 - BMI) < min_BMI)
			{
				min_BMI = fabs(22 - BMI);
			}
		}
		int min_number = 999999999;
		for(int i = 0; i < n; ++i)
		{
			if(data[i].second == min_BMI)
			{
				if(data[i].first < min_number)
				{
					min_number = data[i].first;
				}
			}
		}
		cout << min_number << endl;
	}
}

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

Measured memory_bytes: 1264
#include <stdio.h>
#include <string.h>
int main(void) {
	char strT[105];
	char strH[105];
	int tro=0,hanako=0;
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s %s",strT,strH);
		for(int j=0;j<(strlen(strT)>=strlen(strH)?strlen(strT):strlen(strH));j++){
			//printf("%c %c\n",strT[j],strH[j]);
			if(strT[j]>strH[j]){
				if(strT[j])
				tro+=3;
				break;
			}else if(strT[j]<strH[j]){
				hanako+=3;
				break;
			}else if(j+1 == ((strlen(strT)>=strlen(strH))?strlen(strT):strlen(strH))){
				tro++;
				hanako++;
				break;
			}
		}//printf("%d %d\n",tro,hanako);
	}
	printf("%d %d\n",tro,hanako);
	return 0;
}



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

int main(){  
	string s;
	cin >> s;
	int A;
	int Z;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'A'){
			A = i;
			break;
		}
	}
	for(int i = 0; i < s.size(); i++){
		if(s[s.size() - i - 1] == 'Z'){
			Z = s.size() - i - 1;
			break;
		}
	}
	cout << Z - A + 1 << endl;
}

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

int main()
{
	string s;
	int q;
	cin>>s>>q;
	int isReverse = 0;
	string strAdds[2];
	for( int i=0; i<q; i++ )
	{
		int ti;
		cin>>ti;
		if( ti == 1 )
		{
			isReverse = !isReverse;
		}
		else
		{
			int fi;
			char ci;
			cin>>fi>>ci;
			if( ( fi==1 && !isReverse ) || (fi==2 && isReverse) )
			{
				strAdds[0]+=ci;
			}
			else
			{
				strAdds[1] += ci;
			}
		}
	}
	reverse(strAdds[isReverse].begin(),strAdds[isReverse].end());
	if( isReverse )
	{
		reverse(s.begin(),s.end());
	}	
	s = strAdds[isReverse] + s + strAdds[!isReverse];
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 1348
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var row1 = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray();
            var row2 = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray();
            var row3 = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray();

            var board = new Board(row1, row2, row3);

            var n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                var num = int.Parse(Console.ReadLine());
                board.SetNum(num);
            }

            Console.WriteLine(board.GetResult() ? "Yes": "No");
        }
    }

    class Board
    {
        IReadOnlyList<Cell> cells;

        public Board(int[] row1, int[] row2, int[] row3)
        {
            var list = new List<Cell>();
            list.AddRange(row1.Select((r, i) => new Cell(0, i, r)));
            list.AddRange(row2.Select((r, i) => new Cell(1, i, r)));
            list.AddRange(row3.Select((r, i) => new Cell(2, i, r)));
            this.cells = list;
        }

        internal bool GetResult()
        {
            //縦
            for (int i = 0; i <= 2; i++)
            {
                if (cells.Where(c => c.ClmIdx == i).All(c => c.IsSet)) return true;
            }
            //横
            for (int i = 0; i <= 2; i++)
            {
                if (cells.Where(c => c.RowIdx == i).All(c => c.IsSet)) return true;
            }
            //斜め
            if (new[] { cells[0], cells[4], cells[8] }.All(c => c.IsSet)) return true;
            if (new[] { cells[2], cells[4], cells[6] }.All(c => c.IsSet)) return true;

            return false;
        }

        internal void SetNum(int num)
        {
            var target = cells.FirstOrDefault(c => c.Num == num);
            if (target != null)
            {
                target.IsSet = true;
            }
        }
    }

    class Cell
    {
        public bool IsSet { get; set; }
        public int Num { get; }

        public int RowIdx { get; }
        public int ClmIdx { get; }

        public Cell(int row, int clm, int num)
        {
            this.RowIdx = row;
            this.ClmIdx = clm;
            this.Num = num;
        }
    }

}


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

using namespace std;

int main(){
    int h,w; cin >> h >> w;
    char str[h+2][w+2];
    
    for(int i = 1 ; i < h + 1 ; i++){
        for(int j = 1 ; j < w + 1 ; j++){
            cin >> str[i][j];
        }
    }
    
    for(int i = 0 ; i < h + 2 ; i++){
        str[i][0] = '#';
        str[i][w+1] = '#';
    }
    
    for(int j = 0 ; j < w + 2 ; j++){
        str[0][j] = '#';
        str[h+1][j] = '#';
    }
    
    for(int i = 0 ; i < h + 2 ; i++){
        for(int j = 0 ; j < w + 2 ; j++){
            cout << str[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class UnionFind {
	vector<int> data, data2;
	public:
	UnionFind(int size) : data(size, -1), data2(size, 0) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
			data2[x] += data2[y]; data2[y] = 0;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
	bool add(int x){
		if(-data[root(x)] > data2[root(x)]){
			data2[root(x)]++;
			return true;
		}
		return false;
	}
};

class Solution {
public:
	void solve() {
		int n, h, w;
		cin >> n >> h >> w;
		using cd = tuple<int, int, int>;
		vector<cd> cds(n);
		for(int i=0; i < n; i++){
			int r, c, a;
			cin >> r >> c >> a;
			cds[i] = make_tuple(a, r-1, c-1);
		}
		sort(cds.begin(), cds.end(), greater<tuple<int, int, int>>());
		long long ret = 0;
		UnionFind uf(h + w);
		for(int i=0; i < n; i++){
			int a,r,c;
			tie(a,r,c) = cds[i];
			uf.unionSet(r, h+c);
			if(uf.add(r))ret += a;
		}
		cout << ret << "\n";
		return;
	};
};
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h> 
using namespace std; 
int mod = 1000000007;

int main() 
{ 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        long long h,w,m;cin>>h>>w>>m;
        vector <pair<long long,long long>> hh;
        for(int i=0;i<m;i++){
            int x,y;cin>>x>>y;
            hh.push_back({x,y});
        }
        map <int,int> cnt[2];
        for(auto x:hh){
            cnt[0][x.first]++;
            cnt[1][x.second]++;
        }
        int maxcnt[2]={0,0};
        for(auto x:cnt[0])
            maxcnt[0]=max(maxcnt[0],x.second);
        for(auto x:cnt[1])
            maxcnt[1]=max(maxcnt[1],x.second);
        set <int> s[2];
        for(auto x:cnt[0])if(maxcnt[0]==x.second)s[0].insert(x.first);
        for(auto x:cnt[1])if(maxcnt[1]==x.second)s[1].insert(x.first);
        int count=0;
        for(auto x:hh){
            if(s[0].find(x.first)!=s[0].end() && s[1].find(x.second)!=s[1].end())count++;
        }
        if(count==s[0].size()*s[1].size())cout<<maxcnt[0]+maxcnt[1]-1<<"\n";
        else cout<<maxcnt[0]+maxcnt[1]<<"\n";
    }
    return 0; 
} 

Measured memory_bytes: 64060
n, x, m = map(int, input().split())
L = []
used = set()
while x not in used:
    used.add(x)
    L.append(x)
    x = x*x%m
cnt = 0
while L[cnt] != x:
    cnt += 1
l = len(L)
if n <= l:
    print(sum(L[:n]))
    exit()
s = sum(L)
t = sum(L[cnt:])
q, r = divmod(n-l, l-cnt)
ans = s + q*t
for i in range(r):
    ans += L[cnt]
    cnt += 1
print(ans)

Measured memory_bytes: 77232
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
const int M = 1e9 + 7;
const int N = 5005;
int dp[N][N];
void solve() {
    for (int i = 1; i < N; ++i) {
        dp[i][0] = dp[i][i] = 1;
    }
    for (int i = 2; i < N; ++i) {
        for (int j = 1; j < i; ++j) {
            dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % M;
        }
    }
    int s;
    cin >> s;
    int ans = 0;
    for (int t = 1; t <= s; ++t) {
        int nsum = s - 3 * t;
        if (nsum < 0) {
            continue;
        }
        else if (nsum == 0) {
            ans += 1;
            ans %= M;
            continue;
        }
        // nsum = 0, t = 1
        // s - 2 * t - 1
        // nsum + t - 1 choose t - 1
        ans += dp[nsum + t - 1][t - 1];
        ans %= M;
    }
    cout << ans;
}

Measured memory_bytes: 120488
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int D, G, p[11], c[11];
    cin >> D >> G;
    for (int i = 0; i < D; i++)
    {
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for (int mask = 0; mask < (1 << D); ++mask)
    {
        int s = 0, num = 0, rest_max = -1;
        for (int i = 0; i < D; i++)
        {
            if (mask >> i & 1)
            {
                s += 100 * (i + 1) * p[i] + c[i];
                num += p[i];
            }
            else
            {
                rest_max = i;
            }
        }
        if (s < G)
        {
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if (need >= p[rest_max])
            {
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pb push_back
#define ll long long
#define F first
#define S second
#define ld long double
 
using namespace std;
 
void data() {
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
}
 
const int N = 1e6 + 100;
const ll mod = 998244353; //1e9 + 7

int main () 
{
    data();                                 
    int n;
    cin >> n;
    int a[n + 1];
    for (int i = 1; i <= n; i++)
    {
    	cin >> a[i];
    }
    ll ans = 0;
    for (int i = 2; i <= n; i++)
    {
    	ans += max(0, a[i - 1] - a[i]);
    	if (a[i] < a[i - 1])
    	{
    		a[i] = a[i - 1];
    	}
    }
    cout << ans;
}


Measured memory_bytes: 4376
#include <iostream>
#include <cstdio>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
int n,sx,sy,tx,ty,xx1[50],yy1[50],x2[50],y2[50],h[50];
double eps=1e-8;
inline D dot(P a,P b){
	return real(conj(a)*b);
}
inline D cro(P a,P b){
	return imag(conj(a)*b);
}
inline int ccw(P a,P b,P c){
	if(cro(b-a,c-a)>eps) return 1;
	if(cro(b-a,c-a)<-eps) return -1;
	if(abs(abs(a-c)+abs(c-b)-abs(a-b))<eps) return 0;
	if(abs(abs(a-b)+abs(b-c)-abs(a-c))<eps) return -2;
	if(abs(abs(c-a)+abs(a-b)-abs(c-b))<eps) return 2;
}
inline P perp(L l,P p){
	D t=dot(p-l.fs,l.fs-l.sc)/norm(l.fs-l.sc);
	return l.fs+t*(l.fs-l.sc);
}
inline bool iSP(L s,P p){
	return abs(abs(s.fs-p)+abs(p-s.sc)-abs(s.fs-s.sc))<eps;
}
inline bool iSS(L a,L b){
	return ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0 && ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0;
}
inline D dSP(L s,P p){
	P q=perp(s,p);
	return iSP(s,q) ? abs(p-q) : min(abs(p-s.fs),abs(p-s.sc));
}
inline D dSS(L a,L b){
	if(iSS(a,b)) return 0;
	return min(min(dSP(a,b.fs),dSP(a,b.sc)),min(dSP(b,a.fs),dSP(b,a.sc)));
}
L otama;
bool ok(double r){
//	cout << r << endl;
	bool ok=true;
	rep(i,n){
//		cout << i << endl;
		double hi=min(r,(double)h[i]),dis=sqrt(2*r*hi-hi*hi);
/*		cout << sx << " " << sy << "   " << tx << " " << ty << endl;
		cout << xx1[i] << " " << yy1[i] << "   " << xx1[i] << " " << y2[i] << endl; 
		cout << dSS(otama,L(P(xx1[i],yy1[i]),P(xx1[i],y2[i]))) << endl;
		cout << dSS(otama,L(P(xx1[i],y2[i]),P(x2[i],y2[i]))) << endl;
		cout << dSS(otama,L(P(x2[i],y2[i]),P(x2[i],yy1[i]))) << endl;
		cout << dSS(otama,L(P(x2[i],yy1[i]),P(xx1[i],yy1[i]))) << endl;*/
		if(dSS(otama,L(P(xx1[i],yy1[i]),P(xx1[i],y2[i])))<dis) ok=false;
		if(dSS(otama,L(P(xx1[i],y2[i]),P(x2[i],y2[i])))<dis) ok=false;
		if(dSS(otama,L(P(x2[i],y2[i]),P(x2[i],yy1[i])))<dis) ok=false;
		if(dSS(otama,L(P(x2[i],yy1[i]),P(xx1[i],yy1[i])))<dis) ok=false;
		if(xx1[i]<sx && sx<x2[i] && yy1[i]<sy && sy<y2[i]) ok=false;
	}
	return ok;
}
int main(){
	while(true){
		cin >> n;
		if(n==0) break;
		cin >> sx >> sy >> tx >> ty;
		otama=L(P(sx,sy),P(tx,ty));
		rep(i,n) cin >> xx1[i] >> yy1[i] >> x2[i] >> y2[i] >> h[i];
		double ub=1000,lb=0;
		while(ub-lb>1e-5){
			double m=(ub+lb)/2;
			if(ok(m)) lb=m;
			else ub=m;
		}
		printf("%.6f\n",ub);
	}
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1000000007, inf = 1000000007;
int main() {
	ll i,j,k,l,m,n,t;
	ios_base::sync_with_stdio(false);
  cin.tie(NULL);
	t=1;
	while(t--)
	{
		cin>>n>>k;
		ll a[n];
    vector<ll> ans(n, inf);
    for (i = 0; i < n; i++)
    {
			cin>>a[i];
		}
    ans[0] = 0;
    for (i = 0; i < n - 1; i++)
    {
      for (j = i + 1; j <= min(i + k, n - 1); j++)
      {
        ans[j] = min(ans[j], abs(a[i] - a[j]) + ans[i]);
      }
    }
    cout << ans[n - 1] << endl;
  }
  return 0;
}

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

#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define scani(x) scanf("%d", &x)
#define scanll(x) scanf("%lld", &x)
#define printi(x) printf("%d", x)
#define printll(x) printf("%lld", x)
typedef long long ll;
using namespace std;

long long GCD(long long x, long long y) {
	return y ? GCD(y, x % y) : x;
}

long long LCM(long long x, long long y) {
	return x * y / GCD(x, y);
}

int A() {
	string s, t;
	cin >> s >> t;

	t.pop_back();
	YesNo(s == t);
	return 0;
}

int Main() {
	ll a, b, c, k;
	scanll(a);
	scanll(b);
	scanll(c);
	scanll(k);
	ll ans = 0;

	//for (;k != 0; k--) {
	//	if (0 < a) {
	//		if (k <= a) {
	//			ans += a;
	//			break;
	//		}
	//		a--;
	//		ans++;
	//	}
	//	else if (0 < b) {
	//		if (k <= b) {
	//			k -= b;
	//			break;
	//		}
	//		b--;
	//	}
	//	else {
	//		ans -= k;
	//		break;
	//	}
	//}

	if (k <= a) {
		ans = k;
	}
	else if (k <= a + b) {
		ans = a;
	}
	else {
		ans = a - (k - a - b);
	}

	printll(ans);

	return 0;
}

int C() {
	return 0;
}

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


Measured memory_bytes: 3788
#include <stdio.h>

int main(){
    int a, b;
    char op;
    while(1){
        scanf("%d %c %d", &a, &op, &b);
        if(op=='?'){
            break;
    	}else if(op=='+'){
    	    printf("%d\n", a+b);
    	}else if(op=='-'){
    	    printf("%d\n", a-b);
    	}else if(op=='*'){
    	    printf("%d\n", a*b);
    	}else if(op=='/'){
    	    printf("%d\n", a/b);
        }
    }
    return 0;
}


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

using namespace std;
#define F first
#define S second
#define dafuq(c) ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
typedef pair<int,int>ii;
typedef long long ll;
const int N = 1e5 + 50;
const int INF = 1e9;


int n,m,u,v;
vector<int>adj[N];
int in_degree[N];
bool visited[N];
int dp[N];
void dfs(int u){
        visited[u] = true;
        for(auto v : adj[u]){
                    dp[v] = max(dp[v],dp[u] + 1);
                    in_degree[v]--;
                    if(in_degree[v] == 0)
                            dfs(v);
        }

}
int main()
{
        scanf("%d%d",&n,&m);
        for(int i = 0; i < m; ++i){
                scanf("%d%d",&u,&v);
                adj[u].push_back(v);
                in_degree[v]++;
        }
        for(int i = 1; i <= n; ++i){
                if(!visited[i] && in_degree[i] == 0){
                        dfs(i);
                }
        }
        int ans = 0;
        for(int i = 1; i <= n; ++i)
                ans = max(ans,dp[i]);
        cout << ans << "\n";


    return 0;
}


Measured memory_bytes: 9728
#include<algorithm>
#include<cmath>
#include<climits>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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()
{
	int N;
	cin >> N;

	vector<int> A(N + 1);
	rep(i, N) cin >> A[i + 1];

	vector<int> B(N + 1);
	vector<int> pos;

	for(int i = N; i >= 1; i--)
	{
		int s = 0;

		for (int j = 2 * i; j <= N; j += i)
		{
			s += B[j];
		}

		if (s % 2 == A[i])
		{
			B[i] = 0;
		}
		else
		{
			B[i] = 1;
			pos.push_back(i);
		}
	}


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

	for (auto x : pos) cout << x << " ";

	return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long MOD = 1e9+7;

int main(){
    int n,m;
    cin >> n >> m;
    int a[m];
    
    //n+1個を１で初期化
    vector<ll> x(n+1,1);
    for(int i = 0; i < m; i++){
        cin >> a[i];
        x[a[i]] = 0;
    }
    //dpで変遷を管理する
    ll cnt[n+1] = {};
    cnt[0] = 1;

    for(int i = 0; i < n; i++){
        //穴ぬけしない部分だけ足す
        for(int j = i+1;j <= min(n,i+2); j++){
            //0以外の時に実行（最大2回できる）
            if(x[j]){
                cnt[j] += cnt[i];
                cnt[j] %= MOD;
            }
            //二回連続で0になるときそこから先は0になる
        }
    }

    cout << cnt[n] << endl;
    return 0;
}

Measured memory_bytes: 2176