akhauriyash/Code-Regression huggingface dataset:
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
sA = T1*A1+T2*A2
sB = T1*B1+T2*B2
if sA == sB:
  print("infinity")
  exit()
hA = T1*A1
hB = T1*B1
if sA > sB:
  hA, sA, hB, sB = hB, sB, hA, sA
#print(hA, sA, hB, sB)
if hA < hB:
  print(0)
  exit()
if (hA-hB)%(sB-sA) == 0:
  r = 2*((hA-hB)//(sB-sA))
else:
  r = 2*((hA-hB)//(sB-sA))+1
print(r)


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

int main(){
    int n;
    long long int m;
    cin >> n >> m;

    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    int upper = 1e6, lower = 2, mid;
    while(upper - lower > 1){
        mid = (upper + lower) / 2;

        long long int count = 0;
        for(int i=0; i<n; i++){
            count += a.end() - lower_bound(a.begin(),a.end(),mid-a[i]);
        }
        if(count < m) upper = mid;
        else lower = mid;
    }
    //cout << lower << " " << count << endl;

    // cumulative sum
    vector<long long int> b(n+1);
    for(int i=0; i<n; i++){
        b[i+1] = b[i] + a[i];
    }

    long long int count = 0;
    for(int i=0; i<n; i++){
        count += a.end() - lower_bound(a.begin(),a.end(),lower-a[i]);
    }
    long long int ans = 0;
    for(int i=0; i<n; i++){
        //cout << a.end() - lower_bound(a.begin(),a.end(),lower-a[i]) << " "
        //     << b[n] - b[lower_bound(a.begin(),a.end(),lower-a[i]) - a.begin()] << endl;
        ans += a[i] * (a.end() - lower_bound(a.begin(),a.end(),lower-a[i])) 
            + (b[n] - b[lower_bound(a.begin(),a.end(),lower-a[i])-a.begin()]);
    }
    cout << ans - (count - m) * lower << endl;
    return 0;
}

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

const ll infll=9223372036854775806;
const int inf=2147483646;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i,s1=0,s2=0;
	string a;
	cin>>a;
	for (i=0;i<a.size();i++){
		if (i%2==0){
			s1+=(a[i]=='1')?1:0;
		}
		else {
			s1+=(a[i]=='0')?1:0;
		}
	}
	for (i=0;i<a.size();i++){
		if (i%2==0){
			s2+=(a[i]=='0')?1:0;
		}
		else {
			s2+=(a[i]=='1')?1:0;
		}
	}
	cout<<min(s1,s2);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int n, m;
vector<int> es[10];

int memo[10][1<<10];

int dfs(int now, int mask_past) {
	if(memo[now][mask_past] != 0) return memo[now][mask_past];
	int ret = 0;
	for(int i = 0; i < es[now].size(); i++) {
		int nxt = es[now][i];
		if(mask_past & (1 << nxt)) continue;
		int mask_nxt = mask_past | (1 << nxt);
		ret += dfs(nxt, mask_nxt);
	}
	if(mask_past == (1<<n)-1) ret = 1;
	return memo[now][mask_past] = ret;
}

int main(){
	cin >> n >> m;
	rep(i, m) {
		int a, b; 
		cin >> a >> b;
		a--;b--;
		es[a].pb(b);
		es[b].pb(a);
	}
	cout << dfs(0, 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 200000
#define INF (1LL<<63)
#define val first
#define poz second
#define zeros(x) (x&(-x))
long long v[MAXN+1];
std::pair <long long,int> vec[MAXN+1];
int aib[MAXN+1];
inline void update(int poz){
    for(int i=poz;i<=MAXN;i+=zeros(i))
      aib[i]++;
}
inline int query(int poz){
    int ans=0;
    for(int i=poz;i>0;i-=zeros(i))
      ans+=aib[i];
    return ans;
}
int main() {
    FILE * fi, * fout;
    int i,n;
    long long k;
    long long ans;
   // fi = fopen("A.in" ,"r");
   // fout = fopen("A.out" ,"w");
    fi=stdin;
    fout=stdout;
    fscanf(fi,"%d%lld" ,&n,&k);
    ans=0;
    for(i=1;i<=n;i++){
       fscanf(fi,"%lld" ,&v[i]);
       v[i]-=k;
       v[i]+=v[i-1];
       if(v[i]>=0)
         ans++;
    }
    for(i=1;i<=n;i++){
       vec[i].val=v[i];
       vec[i].second=i;
    }
    std::sort(vec+1,vec+n+1);
    int val=0;
    vec[0].val=-INF;
    for(i=1;i<=n;i++){
       if(vec[i].val!=vec[i-1].val)
         val++;
       v[vec[i].poz]=val;
    }
    for(i=1;i<=n;i++){
       ans+=query(v[i]);
       update(v[i]);
    }
    fprintf(fout,"%lld\n" ,ans);
    //fclose(fi);
    //fclose(fout);
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll Mod = 998244353;
int main() {
  int N;
  cin >> N;
  vector<P> Robot(N);
  for (int i = 0; i < N; i++) {
    cin >> Robot[i].F >> Robot[i].S;
  }
  sort(Robot.begin(),Robot.end());
  ll DP[N+1];
  for (int i = 0; i <= N; i++) {
    DP[i] = 0;
  }
  int at[N];
  int depend[N];
  for (int i = 0; i < N; i++) {
    at[i] = -1;
    depend[i] = -1;
  }
  for (int i = 0; i < N-1; i++) {
    ll s = Robot[i].S;
    bool fin = false;
    for (int j = i + 1; j < N; j++) {
      if (s > Robot[N-1].F - Robot[0].F) {
        at[i] = N-1;
        break;
      }
      ll d = Robot[j].F - Robot[j-1].F;
      s -= d;
      if (s <= 0) {
        at[i] = j-1;
        break;
      }
      if (s <= Robot[j].S) {
        depend[i] = j;
        break;
      }
      if (j == N-1) {
        fin = true;
      }
    }
    if (fin) {
      at[i] = N-1;
    }
  }
  at[N-1] = N-1;
  for (int i = 0; i < N-1; i++) {
    int a = i;
    vector<int> l = {};
    while (depend[a] != -1) {
      a = depend[a];
      l.push_back(a);
    }
    at[i] = at[a];
    for (int j = 0; j < (int)l.size() - 1; j++) {
      depend[l[j]] = a;
    }
  }
  DP[0] = 1;
  for (int i = 0; i < N; i++) {
    DP[i+1] += DP[i];
    DP[at[i]+1] += DP[i];
    DP[i+1] %= Mod;
    DP[at[i]+1] %= Mod;
  }
  cout << DP[N] << endl;
  return 0;
}

Measured memory_bytes: 9856
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

vector<int> p,e;
const ll M=inf;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}


void factorize(int N){
  int tmp=N;
  for(int i=2;i*i<=N;i++){
    int cnt=0;
    while(tmp%i==0){
      tmp/=i;
      cnt++;
      }
      if(cnt>0){
        p.push_back(i);
        e.push_back(cnt);
        }
    }
    if(tmp>1){
      p.push_back(tmp);
      e.push_back(1);
      }
  }

  int main(){
  int n,m;
  cin >> n >> m;
  factorize(m);
  ll ans=1;
  fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    rep(i,p.size()){
ans*=comb(e[i]+n-1,e[i]);
ans%=M;
      }
      cout << ans << endl;
  return 0;}

Measured memory_bytes: 4992
#include<stdio.h>

int main(void)
{
   int i,j,n,d,x,s;
   int a[100];

   scanf("%d%d%d",&n,&d,&x);
   for(i=0; i<n; i++)
    scanf("%d",&a[i]);

   s=0;

   for (i=0; i<n; i++) {
      for (j=1; j<=d; j=j+a[i]) s++;
   }

   printf("%d\n" , s+x);

   return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){

  int a,b;
  int result1;
  int result2;

  scanf("%d %d",&a,&b);

  result1 = a*b;
  result2 = (a+b)*2;

  printf("%d %d\n",result1,result2);

  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int bx[200], by[200] , rx[200], ry[200];

int n;
int ans = 0;

const int maxn = 500;
vector<int>graph[maxn];
bool vis[maxn];
int link[3*maxn];

bool dfs(int x)
{
	if(vis[x]) 
		return false;
        
	vis[x]=1;

    for(int i = 0; i < graph[x].size(); i++)
	{
        int y = graph[x][i];
        
	    if(link[y] == -1||dfs(link[y]))
		{
            link[y]=x;
            return true;
        }
    }
    return false;
}
 
int match(int n)
{
	int ans = 0;
    memset(link,-1,sizeof(link));
    for(int i = 0; i < n; i++)
	{
		memset(vis,0,sizeof(vis));
		ans += dfs(i);
    }
    return ans;
}

int main()
{
	ios::sync_with_stdio(0);
	cin >> n;
	
	for(int i = 0 ; i < n ; i++)
		cin >> rx[i] >> ry[i];
	
	for(int i = 0 ; i < n ; i++)
		cin >> bx[i] >> by[i];
	
	for(int i = 0 ; i < n ; i++)
	{
		for(int j = 0; j < n ; j++)
		{
			if(rx[i] < bx[j] && ry[i] < by[j])
			{
				graph[i].push_back(j+n);
			}
		}
	}
	cout << match(n) << '\n';
	return 0;
}


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

int main() {
  int n, m, tmp, sum, ans;
  cin >> n >> m;
  int A[m];
  sum = 0;
  rep(i, m) {
    cin >> tmp;
    sum += tmp;
  }
  ans = sum > n ? -1 : n - sum;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        r: i64, g: i64
    }

    println!("{}", 2*g - r);
}

Measured memory_bytes: 4352
import sys

def solve(N, a):
    balls = [0] * (N+1)
    for i in range(N, 0, -1):
        s = sum([ balls[j] for j in range(i, N+1, i) ])
        if s % 2 != a[i]:
            balls[i] = 1

    ans = []
    for i in range(1, N+1):
        if balls[i] == 1:
            ans.append(i)

    print(len(ans))
    for x in ans:
        print(x, end=' ')


def main():
    N = int(input())
    a = list(map(int, input().split()))
    a.insert(0, [])
    solve(N, a)


if __name__ == "__main__":
    main()

Measured memory_bytes: 12472
def div(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]

n = int(input())
ans = float("Inf")
lis = div(n)
y = 1
for x in lis:
    z = n//x
    ans = min(ans, max(len(str(z)), len(str(x))))

print(ans)

Measured memory_bytes: 9220
#include <cstdio>
#include <cstring>
using namespace std;

typedef int INT;
const int SIZE = 4194304;
bool HA[SIZE];

inline INT get( char c ) {
    char T[5] = "ACGT";
    for ( INT i = 0; i < 4; ++ i ) {
        if ( c == T[i] ) return i + 1;
    }
    return 0;
}

int main() {
    INT n, sum, t, c;
    while ( scanf("%d", &n) != EOF ) {
        memset( HA, false, sizeof(HA) );
        while ( getchar() != '\n' );
        for ( register INT i = 0; i < n; ++ i ) {
            sum = 0;
            t = 1;
            bool flag = getchar() == 'i';
            while ( ( c = getchar() ) != ' ' );
            while ( ( c = get( getchar() ) ) != 0 ) {
                sum += c * t;
                t *= 4;
            }
            if ( flag ) {
                HA[sum] = true;
            } else {
                puts( HA[sum] ? "yes" : "no" );
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4832
use std::io::*;
use std::str::FromStr;
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
 
#[allow(non_snake_case, unused_variables)]
fn main() {
    let S: String = read();
    println!("{}", S.chars().filter(|&c| c=='1').count());
}



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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];
  sort(v.begin(), v.end());
  cout << v[N - 1] - v[0] << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Console.ReadLine();
		if(p.Length == 2)
		{
			Console.WriteLine(p);
		}
		else
		{
			Console.WriteLine("{2}{1}{0}", p[0], p[1], p[2]);
		}
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

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

struct Problem {
	vector<UL> E[100000];
	bool F[100000] = {};
	bool ans[100000] = {};
	UL D[100000];

	UL DFS(UL p) {
		F[p] = true;
		UL tmp = D[p];
		for (UL e : E[p]) {
			if (F[e]) {
				tmp = min(tmp, D[e]);
			}
			else {
				D[e] = D[p] + 1;
				UL res = DFS(e);
				if (res >= D[p]) if (p != 0) ans[p] = true;
				tmp = min(tmp, res);
			}
		}
		if (p == 0) {
			UL cnt = 0;
			for (UL e : E[p]) if (D[e] == 1) cnt++;
			if (cnt >= 2) ans[0] = true;
		}
		return tmp;
	}

	void Solve() {
		UL N, M; scanf("%d%d", &N, &M);
		rep(i, M) {
			UL u, v; scanf("%d%d", &u, &v);
			E[u].push_back(v);
			E[v].push_back(u);
		}
		D[0] = 0;
		DFS(0);
		rep(i, N) if (ans[i]) printf("%d\n", i);
	}
};
int main() {
	unique_ptr<Problem> p(new Problem());
	//cout << fixed << setprecision(10);
	p->Solve();
	return 0;
}




Measured memory_bytes: 7124
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>

typedef long long ll;
using namespace std;
const int mod = 1000000007;

int main() {

    ll H, N; cin >> H >> N;

    ll sum = 0;
    for (int i = 0; i < N; i++) {
        ll x; cin >> x;
        sum += x;
    }
    if (H - sum <= 0) {
        cout << "Yes" << '\n';
    }
    else {
        cout << "No" << '\n';
    }

}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int maN = 1e6+5;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    
    for(int i = 0; i< n; ++i)
    {
        cin >> a[i];
    }
    vector<ll> def(n,0);
    ll sum = 0;
    
    
    for(int i = 1; i < n; ++i)
    {
        if(a[i] < a[i-1] )
        {
            sum += a[i-1]-a[i];
            a[i] += a[i-1]-a[i];
        }
    }
    cout << sum;
	return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
const long long int N = 200000;
long long int dp[N + 1], h[N + 1], v[N + 1], bit[N + 1];
long long int sgtr[4 * N + 5];
int n;
void update(int s, int e, int node, int i, long long int y) {
	if (i < s || i > e)
		return;
	if (s == e && s == i) {
		sgtr[node] = y;
		return;
	}
	long long int mid = (s + e) / 2;
	if (i <= mid)
		update(s, mid, 2 * node + 1, i, y);
	else
		update(mid + 1, e, 2 * node + 2, i, y);
	sgtr[node] = max(sgtr[2 * node + 1] , sgtr[2 * node + 2]);
	return;
}
long long int query (int s, int e, int node, int i, int j) {
	if (s >= i && e <= j)
		return sgtr[node];
	if (e < i || s > j)
		return -1;
	long long int mid = (s + e) / 2;
	long long int ans1 = query(s, mid, 2 * node + 1, i, j);
	long long int ans2 = query(mid + 1, e, 2 * node + 2, i, j);
	return max(ans1, ans2);
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> h[i];
	for (int i = 1; i <= n; i++) cin >> v[i];
	for (int i = 1; i <= n; i++) {
		if (h[i] != 1)
			dp[h[i]] = query(1, n, 0, 1, h[i] - 1);
		dp[h[i]] += v[i];
		update(1, n, 0, h[i], dp[h[i]]);
	}
	long long int ans = 0;
	for ( long long int i = 1; i <= n; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans;
	return 0;
}

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

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


Measured memory_bytes: 78336
#include <stdio.h>
#include <math.h>

int main(void)
{
	int n, i, x[1000], y[1000];
	double p2, p3, max = 0;
	double dp1, dp2, dp3;

	dp1 = dp2 = dp3 = 0;
	p2 = p3 = 0;

	scanf("%d", &n);

	for (i = 0;i < n;i++)
	{
		scanf("%d", &x[i]);
	}
	for (i = 0;i < n;i++)
	{
		scanf("%d", &y[i]);
	}
	for (i = 0;i < n;i++)
	{
		dp1 += abs(x[i] - y[i]);
		p2 += pow((x[i] - y[i]), 2);
		p3 += pow(abs(x[i] - y[i]), 3);
	}
	dp2 = sqrt(p2);
	dp3 = cbrt(p3);
	for (i = 0;i < n;i++)
	{
		if (max < abs(x[i] - y[i]))
		{
			max = abs(x[i] - y[i]);
		}
	}
	printf("%.6f\n%.6f\n%.6f\n%.6f\n", dp1, dp2, dp3, max);

	return 0;
}


Measured memory_bytes: 2112
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int n;
int v[101010];
map<int, int> even, odd;
vector<pair<int, int>> evens, odds;

int main()
{
    cin >> n;
    repe(i, 1, n)
    {
        cin >> v[i];
    }

    for (int i = 1; i <= n; i += 2)
    {
        odd[v[i]]++;
    }

    for (int i = 2; i <= n; i += 2)
    {
        even[v[i]]++;
    }

    for (auto e : odd)
    {
        odds.push_back(make_pair(e.second, e.first));
    }

    for (auto e : even)
    {
        evens.push_back(make_pair(e.second, e.first));
    }

    sort(odds.begin(), odds.end(), greater<pair<int, int>>());
    sort(evens.begin(), evens.end(), greater<pair<int, int>>());

    auto o1 = odds[0];
    auto e1 = evens[0];
    if (o1.second != e1.second)
    {
        cout << n - o1.first - e1.first << endl;
        return 0;
    }
    else
    {
        if (odds.size() == 1)
        {
            auto e2 = evens[1];
            cout << n - o1.first - e2.first << endl;
            return 0;
        }
        else if (evens.size() == 1)
        {
            auto o2 = odds[1];
            cout << n - o2.first - e1.first << endl;
            return 0;
        }
        else
        {
            auto e2 = evens[1];
            auto o2 = odds[1];
            cout << min(n - o1.first - e2.first, n - o2.first - e1.first) << endl;
        }
    }
}


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

using namespace std;
#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__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll H;
  cin >> H;
  
  ll pow2 = 1;
  ll ans = 0;
  while(H > 0){

    H = H / 2;
    ans += pow2;

    pow2 = pow2 * 2;

  }

  cout << ans << endl;


  return 0;
}


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

using namespace std;

int main(void) {
    int W, H, N;
    cin >> W >> H >> N;
    vector< vector<int> > grid(W, vector<int>(H, 1));
    while(N--) {
        int x, y, a;
        cin >> x >> y >> a;
        if(a == 1) {
            for(int i=0; i<x; i++) {
                for(int j=0; j<H; j++) {
                    grid[i][j] = 0;
                }
            }
        } else if(a == 2) {
            for(int i=x; i<W; i++) {
                for(int j=0; j<H; j++) {
                    grid[i][j] = 0;
                }
            }
        } else if(a == 3) {
            for(int j=0; j<y; j++) {
                for(int i=0; i<W; i++) {
                    grid[i][j] = 0;
                }
            }
        } else {
            for(int j=y; j<H; j++) {
                for(int i=0; i<W; i++) {
                    grid[i][j] = 0;
                }
            }

        }
    }

    int ans = 0;
    for(auto e: grid) {
        ans += count(e.begin(), e.end(), 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
x, y = map(int, input().split())
if x >= y:
    while True:
        a,b = divmod(x,y)
        if b == 0:
            print(y)
            break
        else:
            x = y
            y = b
elif x < y:
    while True:
        a,b = divmod(y,x)
        if b == 0:
            print(x)
            break
        else:
            y = x
            x = b
            


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

using namespace std;

#define endl '\n'

int task[100002][3];
int dp[100002][3];

int solve(int idx, int l, int n) {
  if (l == n) return 0;
  int ans = -1e9;
  if (idx == 0) {
    if (dp[l][1] == -1) dp[l][1] = task[l][1] + solve(1, l + 1, n);
    if (dp[l][2] == -1) dp[l][2] = task[l][2] + solve(2, l + 1, n);
    ans = max(dp[l][1], dp[l][2]);
  } else if (idx == 1) {
    if (dp[l][0] == -1) dp[l][0] = task[l][0] + solve(0, l + 1, n);
    if (dp[l][2] == -1) dp[l][2] = task[l][2] + solve(2, l + 1, n);
    ans = max(dp[l][0], dp[l][2]);
  }
  else {
    if (dp[l][1] == -1) dp[l][1] = task[l][1] + solve(1, l + 1, n);
    if (dp[l][0] == -1) dp[l][0] = task[l][0] + solve(0, l + 1, n);
    ans = max(dp[l][1], dp[l][0]);
  }
  return ans;
}

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

  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> task[i][0] >> task[i][1] >> task[i][2];
    dp[i][0] = dp[i][1] = dp[i][2] = -1;
  }
  int ans = -1e9;
  for (int i = 0; i < 3; i++) {
    ans = max(ans, task[0][i] + solve(i, 1, n));
  }
  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 12080
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{	
		boolean not[] = new boolean[100000];
		
		not[0] = true;
		not[1] = true;
		
		for (int i = 2; i * i < 100000; i++)
		{
			if (not[i]) continue;
			for (int x = (i << 1); x < 100000; x += i)
			{
				if (not[x]) continue;
				not[x] = true;
			}
		}
		
		Scanner sc = new Scanner(System.in);
		while(true)
		{
			int n;
			try
			{
				n = sc.nextInt();
			}
			catch(Exception e)
			{
				break;
			}
			for (int i = n-1; i >= 2; i--)
			{
				if (not[i] == false)
				{
					System.out.print(i);
					break;
				}
			}
			System.out.print(" ");
			for (int i = n+1; i < 100000; i++)
			{
				if (not[i] == false)
				{
					System.out.println(i);
					break;
				}
			}
		}
	}
}

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

N = int(input())
A = list(map(int, input().split()))

INF = 10**18

if 0 in A:
    ans = 0
else:
    ans = 1
    for a in A:
        ans *= a
        if ans > INF:
            ans = -1
            break
print(ans)

Measured memory_bytes: 82768
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;

struct UF {
	vector<int> v;
	UF(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

int main() {
	vector<p_ii>all;
	int n, k, l;
	cin >> n >> k >> l;
	int i, j;
	struct UF s(n), t(n);
	for (i = 0; i < k; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		s.unite(a, b);
	}
	for (i = 0; i < l; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		t.unite(a, b);
	}
	for (i = 0; i < n; i++)all.push_back({ s.find(i),t.find(i) });
	sort(all.begin(), all.end());

	for (i = 0; i < n; i++) {
		p_ii tmp = { s.find(i), t.find(i) };
		int ans = upper_bound(all.begin(), all.end(), tmp) - lower_bound(all.begin(), all.end(), tmp);
		if (i != 0)printf(" ");
		printf("%d", ans);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 3956
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int c[3];

void aaa(int i){
  c[2]=i%10;
  i/=10;
  c[1]=i%10;
  i/=10;
  c[0]=i%10;
}

int main(){
  int N; cin >> N;
  string S; cin >> S;
  ll ans=0;
  for(int i=0;i<1000;i++){
    aaa(i);
    int id=0;
    rep(j,N){
      if(int(S[j]-'0')==c[id]){id++;}
      if(id==3) break;
    }
    if(id==3) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;

typedef long long lld;

lld N, M, gap=1;

int main(){
	scanf("%lld%lld", &N, &M);
	if(N>M) swap(N,M);
	if(M-N>1) puts("0");
	else{
		for(lld i=1; i<=N; i++) gap=gap*i%1000000007;
		for(lld i=1; i<=M; i++) gap=gap*i%1000000007;
		if(N==M) gap=gap*2%1000000007;
		printf("%lld\n", gap);
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>


int main(){
    long a;
    scanf("%ld", &a);

    long sum = 0;
    for (long i=1; i<=a; i++){
        if (i%15 == 0 || i%3 == 0 || i%5 == 0){
            continue;
        }
        else{
            sum += i;
        }
    }
    
    printf("%ld\n", sum);
    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    int N,M,C;
    cin >> N >> M >> C; 
    int A[N][M],B[M];
    for(int i=0;i<M;i++){
        cin >> B[i];
    }
    int ans=0;
    int count=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin >> A[i][j];
            ans = ans+A[i][j]*B[j];
        }
        if(ans+C>0){
            count++;
        }
        ans=0;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
  
  
int main()
{
    int a,b,bb;
    cin>>a>>b;
    long long sum=0;
    for(int i=0;i<b;i++){
        cin>>bb;
        sum+=bb;
    }
    if(sum>=a){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> p;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  combination comb(n);
  mint ans = 0;
  rep(ii, 2) {
    mint s = 0;
    rep(i, n) {
      s +=  comb(i, k - 1) * a[i];
    }
    reverse(a.begin(), a.end());
    if(ii == 0) ans += s;
    else ans -= s;
  }
  cout << ans << endl;
}


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

const int MX = 1e5 + 5;
bool dp[MX];

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

    int N, K;
    cin >> N >> K;

    vector<int> arr(N);
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }

    for (int i = 0; i <= K; i++) {
        bool res = 0;
        for (int j = 0; j < N && !res; j++) {
            int x = i - arr[j];
            if (x < 0) continue;
            res = !dp[x];
        }
        dp[i] = res;
    }

    cout << (dp[K] ? "First" : "Second") << "\n";
}



Measured memory_bytes: 384
#![allow(non_snake_case)]
#![allow(dead_code)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

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

fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T, T) {
    let v: Vec<T> = read_vec();
    (v[0], v[1], v[2])
}

fn floyd_warshall(d: &mut Vec<Vec<usize>>) {
    let v = d.len();
    for k in 0..v {
        for i in 0..v {
            for j in 0..v {
                d[i][j] = std::cmp::min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

fn main() {
    loop {
        let n: usize = read_line().parse().unwrap();
        if n == 0 {
            break;
        }
        let mut info = Vec::new();
        let mut v = 1;
        for i in 0..n {
            let (a, b, c) = read_tuple::<usize>();
            v = std::cmp::max(v, std::cmp::max(a+1, b+1));
            info.push((a, b, c));
        }

        let mut d = vec![vec![usize::max_value() / 3; v]; v];
        for i in 0..v {
            d[i][i] = 0;
        }
        for &(a, b, c) in &info {
            d[a][b] = c;
            d[b][a] = c;
        }

        floyd_warshall(&mut d);
        let total: Vec<usize> = d.iter().map(|dist| dist.iter().sum()).collect();
        let min_dist = *total.iter().min().unwrap();
        println!("{} {}", total.iter().position(|&t| t == min_dist).unwrap(), min_dist);
    }
}



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

int main() {
  ll h,w;
  cin >> h >> w;
  vector<string> s(h);
  for(ll i=0;i<h;i++) {
    cin >> s[i];
  }
  vector<vector<ll>> hn(h,vector<ll>(w));
  vector<vector<ll>> wn(h,vector<ll>(w));
  ll f=-1;
  ll temp=0;
  for(ll i=0;i<w;i++) {
    f=-1;
    temp=0;
    for(ll j=0;j<h;j++) {
      if(s[j][i]=='#') {
        for(ll k=f+1;k<j;k++) {
          hn[k][i]=temp;
        }
        f=j;
        temp=0;
      }
      else {
        temp++;
        if(j==h-1) {
          for(ll k=f+1;k<=j;k++) {
            hn[k][i]=temp;
          }
        }
      }
    }
  }
  for(ll i=0;i<h;i++) {
    f=-1;
    temp=0;
    for(ll j=0;j<w;j++) {
      if(s[i][j]=='#') {
        for(ll k=f+1;k<j;k++) {
          wn[i][k]=temp;
        }
        f=j;
        temp=0;
      }
      else {
        temp++;
        if(j==w-1) {
          for(ll k=f+1;k<=j;k++) {
            wn[i][k]=temp;
          }
        }
      }
    }
  }
  ll ans=0;
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      ans=max(ans,hn[i][j]+wn[i][j]-1);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 67072
#include<bits/c++io.h>
#include<math.h>

using namespace std;

int main()
{
    int i,j,m;
    long long int n;
    int temp;
    scanf("%lld",&n);
    printf("%d: ",n);
    for(i=2;i<=sqrt(n);i++)
        {
            if(n%i==0)
            {
                printf("%d ",i);
                n=n/i;
                temp=i;
                i=1;
            }

        }
        printf("%lld\n",n);



    return 0;
}




Measured memory_bytes: 2740
#include <iostream>
#define NO {cout<<"No"; return 0;}
using namespace std;
int a, b;
string s;
int main() {
	int i;
	cin>>a>>b>>s;
	if(s.size()!=a+b+1) NO;
	for(i=0; i<a; i++) if(s[i]=='-') NO;
	if(s[a]!='-') NO;
	for(i=a+1; i<a+b+1; i++) if(s[i]=='-') NO;
	cout<<"Yes";
	return 0;
}

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

using namespace std;

int main(){
    long a,b,n;
    scanf("%ld%ld%ld", &a, &b, &n);

    long max = 0L;
    if(n < b){
        max = a*n / b;
    }else{
        max = a*(b-1) / b;
    }
    cout << max << endl;
}

Measured memory_bytes: 3764
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

const i64 MAXN = 100005;

i64 n, m;

i64 dp[MAXN];
tuple<i64, i64, i64> e[MAXN];

vector<i64> q[MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> m;

    for (i64 i = 0; i < m; i++) {
        i64 l, r, c;
        cin >> l >> r >> c;
        e[i] = make_tuple(l, r, c);
    }

    for (i64 i = 0; i < m; i++) {
        i64 l, r, c;
        tie(l, r, c) = e[i];
        q[l].push_back(i);
    }

    for (i64 i = 0; i < m; i++) {
        i64 l, r, c;
        tie(l, r, c) = e[i];
        q[r].push_back(i);
    }

    dp[1] = 0;
    for (i64 i = 2; i <= n; i++) {
        dp[i] = inf;
    }

    map<i64, i64> z;
    for (i64 i = 1; i <= n; i++) {
        if (!z.empty()) {
            dp[i] = min(dp[i], z.begin()->first);
        }

        for (i64 j = 0; j < q[i].size(); j++) {
            i64 l, r, c;
            tie(l, r, c) = e[q[i][j]];

            i64 t = dp[l] + c;
            if (i == l) {
                z[t] += 1;
            }
            else if (i == r) {
                z[t] -= 1;
                if (!z[t]) {
                    z.erase(t);
                }
            }
            else {
                throw 1;
            }
        }
    }

    if (dp[n] >= inf) {
        cout << -1 << endl;
    }
    else {
        cout << dp[n] << endl;
    }



    return 0;
}


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

int main(void){
    
    string s, t;
    ll u=0;
    
    cin >> s;
    cin >> t;
    
    u = s.size();
    
    for(ll i=0; i<=u-1; i++){
        
        if(s.at(i)!=t.at(i)){
            
            cout << "No" << endl;
            return 0;
            
        }
        
    }
    
    cout << "Yes" << endl;
    
    return 0;
    
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
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()
{
  //input
  int N; cin >> N;
  vector<int> L(N);
  for(int i=0; i<N; i++){ cin >> L[i]; }
  sort(L.begin(), L.end());

  //main
  ll ans = 0;
  for(int i=N-1; i>=2; --i){//最長辺
    for(int j=i-1; j>=1; --j){
      int count = next(L.begin(), j) - (upper_bound(L.begin(), L.end(), L[i]-L[j]));
      if(count > 0){ ans += count;}
    }
  }
  
  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  int N,i; cin>>N>>i;
  cout << N-i+1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz 100005
#define all(x) x.begin(),x.end()
#define l_b lower_bound
#define u_b upper_bound
#define pb push_back
#define MOD 1000000007
void fastio(void);

int main(){
    fastio();
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ll n,d,la,cnt=0,x,y;
    cin>>n>>d;
    for(la=1;la<=n;la++){
        cin>>x>>y;
        if(x*x+y*y<=d*d)
            cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}

void fastio(void){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

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

int main() {
	ios_base::sync_with_stdio(false);
	int N; cin >> N;

	unordered_map<string, int> freq;
	for (string line; getline(cin, line);) {
		freq[line]++;
	}

	for (string status: {"AC", "WA", "TLE", "RE"})
		cout << status << " x " << freq[status] << '\n';
}


Measured memory_bytes: 3648
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

type Good struct {
	value  int
	weight int
	typ    string
	date   int
	name   string
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	goods := make([]Good, n)
	for i := 0; i < n; i++ {
		goods[i] = Good{
			value:  nextInt(),
			weight: nextInt(),
			typ:    nextString(),
			date:   nextInt(),
			name:   nextString(),
		}
	}

	sort.Slice(goods, func(i, j int) bool {
		if goods[i].value != goods[j].value {
			return goods[i].value < goods[j].value
		} else {
			if goods[i].weight != goods[j].weight {
				return goods[i].weight < goods[j].weight
			} else {
				if goods[i].typ != goods[j].typ {
					return goods[i].typ < goods[j].typ
				} else {
					if goods[i].date != goods[j].date {
						return goods[i].date < goods[j].date
					} else {
						return goods[i].name < goods[j].name
					}
				}
			}
		}
	})

	for i := 0; i < n; i++ {
		g := goods[i]
		fmt.Println(g.value, g.weight, g.typ, g.date, g.name)
	}
}



Measured memory_bytes: 15628
n, k = list(map(int, input().split()))

MAX = 2*10**5+1
MOD = 10**9+7
fact = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
invfact = [0 for i in range(MAX)]

def comb_build(n):
  fact[0] = inv[0] = invfact[0] = 1
  fact[1] = inv[1] = invfact[1] = 1
  for i in range(2, n):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = inv[MOD%i]*(MOD-MOD//i)%MOD
    invfact[i] = invfact[i-1]*inv[i]%MOD

def nCk(n, k):
  if n<k or n<0 or k<0:
    return 0
  return (((fact[n]*invfact[k])%MOD)*invfact[n-k])%MOD

comb_build(2010)

for i in range(1, k+1):
  print((nCk(k-1, i-1)*nCk(n-k+1, i))%MOD)

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

using namespace std;

const int inf = 2000000000;

void solve() {
    int n, k, h[100100], dp[100100];
    
    cin >> n >> k;
    
    for(int i = 1;i <= n;++i){
        cin >> h[i];
        dp[i] = inf;
    }
    
    dp[1] = 0;
    
    for(int i = 2;i <= n;++i){
        for(int j = 1;j <= k && i - j > 0;++j){
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }
    
    cout << dp[n];
}

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

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

int main(){
    long long int a,b;
    cin >> a >> b;
    if(a > 0 ){
        cout << "Positive" << endl;
    }else if(a * b < 0){
        cout << "Zero" << endl;
    }else if(b < 0){
        if((b-a) % 2 == 0){
            cout << "Negative" << endl;
        }else{
            cout << "Positive" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
/*節点xを根とする部分木の中で最小のキーを持つ節点を返す*/
Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}
 
Node treeSearch(Node u, int k){
  while((u != NIL) && (k != u->key)){
    if (k < u->key){
    u = u->left;
    }
    else u = u->right;
  }
  return u;
}

 /*２分探索木の節点xに次節点がある場合はその次節点を返す*/
/*ただし、木の中でxが最大のキーを持つ場合はNILを返す*/
Node treeSuccessor(Node x){
  Node y;
 
  if(x->right != NIL)
    return treeMinimum(x->right);
  y = x->parent;
 
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}
 
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
 /* 削除する節点yを決定する */
  if(z->left == NIL || z->right ==NIL)
    y = z;   /* 削除する節点yを決定する */
  else y = treeSuccessor(z);  /* 削除する節点yを決定する */
 
  if(y->left != NIL)/*xをyのNILではない子またはyが子を持たない場合はNILに設定 */
    x = y->left;
  else x = y->right;

 /*yの親とxのポインタを変更しyを削除する*/
  
  if(x != NIL)
    x->parent = y->parent;/*yの親とxのポインタを変更しyを削除する*/
  if(y->parent == NIL)
    root = x;/*yの親とxのポインタを変更しyを削除する*/
  else if(y == y->parent->left)/*yの親とxのポインタを変更しyを削除する*/
    y->parent->left = x;
  else /* y が右の子の場合 */
    y->parent->right = x;

 /* zの次節点が削除されたときにyの内容をzに移動する*/
  if(y != z)
    z->key = y->key;
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
   
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
   

  while(x != NIL){
    y = x;
    if (z->key < x->key)
    x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if (y == NIL)
  root = z;  // if T is empty
  else if(z->key < y->key)
    y->left = z;
  else y->right = z;
}
 
void inorder(Node u){
  if(u != NIL) {
    if(u->left != NIL) inorder(u->left);
    printf(" %d",u->key);
    if(u->right != NIL) inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL) {
    printf(" %d",u->key);
    if(u->left != NIL) preorder(u->left);
    if(u->right != NIL) preorder(u->right);
  }
}
 
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
 
  return 0;
}

Measured memory_bytes: 19364
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	m := make(map[string]int)
	for i := 0; i < n; i++ {
		sc.Scan()
		m[sc.Text()]++
	}
	var mc int
	for _, v := range m {
		mc = max(mc, v)
	}
	ss := make([]string, 0)
	for k, v := range m {
		if v == mc {
			ss = append(ss, k)
		}
	}
	sort.Strings(ss)
	for i := range ss {
		fmt.Println(ss[i])
	}
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 31104