akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define pll     pair<long long, long long>
#define ll      long long

static const int INF = 0x3f3f3f3f;

struct edge {
        int to, cap, cost, rev;
};
int V;
vector<edge> g[101010];
int dist[101010];
int prevv[101010];
int preve[101010];
void add_edge(int from, int to, int cap, int cost) {
        g[from].push_back((edge) { to, cap, cost, (int)g[to].size() });
        g[to].push_back((edge) { from, 0, -cost, (int)g[from].size() - 1 });
}
int MinCostFlow(int s, int t, int f) {
        int res = 0;
        while (f > 0) {
                fill(dist, dist + V, INF);
                dist[s] = 0;
                bool update = true;
                while (update) {
                        update = false;
                        for (int v = 0; v < V; v ++) {
                                if (dist[v] == INF) continue;
                                for (int i = 0; i < g[v].size(); i ++) {
                                        edge &e = g[v][i];
                                        if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
                                                dist[e.to] = dist[v] + e.cost;
                                                prevv[e.to] = v;
                                                preve[e.to] = i;
                                                update = true;
                                        }
                                }
                        }
                }
                if (dist[t] == INF) return -1;
                int d = f;
                for (int v = t; v != s; v = prevv[v]) {
                        d = min(d, g[prevv[v]][preve[v]].cap);
                }
                f -= d;
                res += d * dist[t];
                for (int v = t; v != s; v = prevv[v]) {
                        edge &e = g[prevv[v]][preve[v]];
                        e.cap -= d;
                        g[v][e.rev].cap += d;
                }
        }
        return res;
}

int main() {
        int v, e, f;
        scanf("%d%d%d", &v, &e, &f);
        V = v;
        for (int i = 0; i < e; i ++) {
                int u, v, c, d;
                scanf("%d%d%d%d", &u, &v, &c, &d);
                add_edge(u, v, c, d);
        }
        printf("%d\n", MinCostFlow(0, V - 1, f));
        return 0;
}

Measured memory_bytes: 5688
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn=3e5+5;
const ll p=1000000007;
vector<pair<ll,pair<ll,ll> > >G[maxn];
vector<pair<ll,pair<ll,pair<ll,ll> > > >Q[maxn];

int dep[maxn],f[maxn][25];
void DFS(int x, int fa) {
    dep[x] = dep[fa] + 1;
    f[x][0] = fa;
    for (pair<ll,pair<ll,ll> > p:G[x])
	    if(!dep[p.first]) DFS(p.first, x);
}
 
int n;

void beizeng() {
    DFS(1, 0);
    for(int j = 1; j <= 24; j++)
        for(int i = 1; i <= 2*n; i++)
            f[i][j] = f[f[i][j - 1]][j - 1];
}
 
int LCA(int x, int y) {
    if(dep[x] < dep[y]) swap(x, y);
    for(int i = 24; ~i; i--) if(dep[f[x][i]] >= dep[y]) x = f[x][i];
    if(x == y) return x;
    for(int i = 24; ~i; i--) if(f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
    return f[x][0];
}
 
 

ll ans[maxn];
ll cnt[maxn],sum[maxn];

void dfs(int u,int fa,ll len){
	
	for (pair<ll,pair<ll,pair<ll,ll> > >p:Q[u]){
		ans[p.second.first]+=p.first*(len-sum[p.second.second.first]+cnt[p.second.second.first]*p.second.second.second);
	}
	
	for (pair<ll,pair<ll,ll> > p:G[u]){
		if (p.first==fa) continue;
		cnt[p.second.first]++;
		sum[p.second.first]+=p.second.second;
		dfs(p.first,u,len+p.second.second);
		cnt[p.second.first]--;
		sum[p.second.first]-=p.second.second;
	}
	
	
}

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

	int q;
	cin>>n>>q;
	
	for (int i=0;i<n-1;i++){
		ll u,v,c,d;
		cin>>u>>v>>c>>d;
		G[u].pb({v,{c,d}});
		G[v].pb({u,{c,d}});
	}
	
	beizeng();
	
	for (int i=1;i<=q;i++){
		int x,y,u,v;
		cin>>x>>y>>u>>v;
		int lca=LCA(u,v);
		Q[lca].pb({-2,{i,{x,y}}});
		Q[u].pb({1,{i,{x,y}}});
		Q[v].pb({1,{i,{x,y}}});
	}
	
	dfs(1,0,0);
	
	for (int i=1;i<=q;i++){
		cout<<ans[i]<<endl;
	}
}


Measured memory_bytes: 68080
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;

    if ( (b-a) % 2 == 0) {
        cout << (b-a)/2 << endl;
        return 0;
    }

    cout << min(a-1, n-b) + 1 + (b-a-1)/2 << endl;
    return 0;
}


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

#define ll long long
#define mod 1000000007

using namespace std;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll d,g,ans=INT_MAX;//cout<<ceil((700-0)/(200+0.0))<<endl;
    cin>>d>>g;
    ll p[11],c[11];
    for(int i=0;i<d;i++)cin>>p[i]>>c[i];
    for(int i=0;i<(1<<d);i++){
        ll s=0,num=0,restmax=-1;
        for(int j=0;j<d;j++){
            if(i>>j & 1){
                s+=100*(j+1)*p[j]+c[j];
                num+=p[j];
            }
            else restmax=j;
        }
        if(s<g){
            ll s1=100*(restmax+1);if(s1==0)continue;
            ll need=ceil((g-s)/(s1+0.0));
            if(need>=p[restmax])continue;
            num+=need;
        }
        ans=min(ans,num);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k, s;
    cin >> n >> k >> s;
    rep(i, k) printf("%lld%s", s, (i == (n - 1)) ? "\n" : " ");
    ll v = (s == 1e9) ? (s - 1) : (s + 1);
    rep(i, n - k) printf("%lld%s", v, ((i + k) == (n - 1)) ? "\n" : " ");
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ull unsigned long long

using namespace std;

ull num[200005], ball[200005];

int main ()

{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    vector <ull> distinct;
    ull n, sum = 0;
    cin >> n;
    for ( ull i = 1; i <= n; i++ )
    {
        cin >> ball[i];
        if(!num[ball[i]])
        {
            distinct.push_back(ball[i]);
        }
        num[ball[i]]++;
    }
    for( ull i = 0; i < distinct.size(); i++ )
    {
        sum += ((num[distinct[i]]*(num[distinct[i]]-1))/2);
    }
    for ( ull i = 1; i <= n; i++ )
    {
        cout << sum-(num[ball[i]]-1) << endl;
    }
}


Measured memory_bytes: 5876
from sys import stdin
import math
from operator import itemgetter
from bisect import bisect_left, bisect_right

def main():
    xy = [tuple(map(int, input().split()))+(i, ) for i in range(int(input()))]
    xy.sort()
    root = int(math.sqrt(len(xy)))
    low = [x for x,y,i in xy[::root]]
    high = [x for x, y, i in xy[root-1::root]] + [float('inf')]
    
    xy = [sorted(xy[i:i+root],key = itemgetter(1)) for i in range(0,len(xy),root)]
    xy = [([y for x,y,i in xyi], xyi) for xyi in xy]
    q = int(input())
    for _ in range(q):
        sx, tx, sy, ty =  map(int, input().split())
        ans = []
        for i in range(bisect_left(high,sx),bisect_right(low,tx)):
            k, v = xy[i]
            for i in range(bisect_left(k, sy),bisect_right(k,ty)):
                if sx <= v[i][0] <=tx:
                    ans.append(v[i][2])
        if ans:
            ans.sort()
            print('\n'.join(map(str,ans)))
        print()
main()
    


Measured memory_bytes: 93232
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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

const ll mod=998244353;

const ll INF=1e9;

int main(){
    string s;
    cin >> s;
    ll n=s.length();
    bool N=false;
    bool W=false;
    bool S=false;
    bool E=false;
    rep(i,n){
        if(s[i]=='N') N=true;
        if(s[i]=='W') W=true;
        if(s[i]=='S') S=true;
        if(s[i]=='E') E=true;
    }
    bool x=(N==S);
    bool y=(W==E);
    if(x&y) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
package main

import "fmt"

func main() {
	var A, B, C int
	fmt.Scan(&A, &B, &C)
	found := false
	for i := 0; i < B; i++ {
		if (i*A)%B == C {
			found = true
			break
		}
	}
	if found {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
S = input()
N = int(len(S))
A = "Yes"
n = N//2
m = n//2
 
for i in range(n):
  if S[i] != S[N-1-i]:
    A = "No"
    break
for i in range(m):
  if S[i] != S[n-1-i] or S[n+1+i] != S[N-1-i]:
    A = "No"
    break
print(A)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) > (b) ? (b) : (a))

int
main(int argc, char *argv[])
{
  int p[100]; int n;
  scanf("%d", &n);
  for(int i = 0; i < n; i++) scanf("%d", &p[i]);

  int ans = 0;

  for(int i = 0; i < n - 2; i++){
    if(p[i] <= p[i + 1] && p[i + 1] <= p[i + 2])ans++;
    if(p[i] >= p[i + 1] && p[i + 1] >= p[i + 2]) ans++;
  }
  printf("%d\n", ans);

  return 0;
}
						 


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int N, W;
int w[1010], v[1010];
int dp[101][101010];

int rec(int i, int j) {
    if (dp[i][j] >= 0) return dp[i][j];
    int res;
    if (i >= N) {
        res = 0;
    }
    else if (j < w[i]) {
        res = rec(i + 1, j);
    }
    else {
        res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]);
    }
    return (dp[i][j] = res);
}

int main() {
    cin >> N >> W;
    rep(i, N) {
        cin >> v[i] >> w[i];
    }
    fill(dp[0], dp[N], -1);
    cout << rec(0, W) << endl;
    return 0;
}



Measured memory_bytes: 42556
#include <stdio.h>
#include <string.h>
#define max(a,b) ((a)>(b)?(a):(b))

int W,n;
int s[1000],g[1000],dp[1001];
int i,j,k,c;
int p,q;
main(){
    for(;scanf("%d%d",&W,&n),W;){
        for(i=0;i<n;i++) scanf("%d,%d",s+i,g+i);
        memset(dp,-1,sizeof(dp));
        dp[0]=0;

        for(j=0;j<n;j++){
            for(i=W-g[j];i>=0;i--){
                if(dp[i]>=0) dp[i+g[j]] = max(dp[i+g[j]],dp[i]+s[j]);
            }
        }

        p=q=0;
        for(i=0;i<=W;i++){
            if(dp[i]>p){
                p=dp[i];
                q=i;
            }
        }

        printf("Case %d:\n%d\n%d\n",++c,p,q);
    }
    return 0;
}

Measured memory_bytes: 1040
def main():
    H = map(int, open(0).read().split()[:1:-1])
    pre = None
    for h in H:
        if pre:
            if pre + 1 < h:
                print("No")
                return
            elif pre + 1 == h:
                pre = h - 1
            else:
                pre = h
        else:
            pre = h

    print("Yes")
    return


main()


Measured memory_bytes: 11200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

int main() {
  string s, t;
  cin >> s >> t;
  int r = 0;
  rep(i, s.size()) {
    if(s[i] != t[i])
      r++;
  }
  cout << r << endl;
}


Measured memory_bytes: 3920
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,w,h,x,y,s,t;
    while(cin>>n,n){
        cin>>w>>h;
        int ma[100][100]={};
        for(int i=0;i<n;i++){
            cin>>x>>y;
            ma[y-1][x-1]=1;
        }
        cin>>s>>t;
        int cnt,mx=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cnt=0;
                for(int k=i;k<i+t;k++){
                    for(int l=j;l<j+s;l++){
                        if(ma[k][l]==1) cnt++;
                    }
                }
                mx=max(mx,cnt);
            }
        }
        cout<<mx<<endl;
    }
    return 0;
}



Measured memory_bytes: 3036
#include <stdio.h>
int main()
{
    int ar[50],n,i,count=0; 
    scanf("%d",&n);
    for (i=1; i<=n; i++)
    {
        scanf("%d",&ar[i]);
        if(ar[i]!=i)
            count++;
    }
    if(count>2)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;
    
}

Measured memory_bytes: 2068
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define INF 2e9
#define fi first
#define se second
typedef long long ll;
ll n,ans,calc;
char s[211111];
int main()
{
	//freopen("c.cpp","r",stdin);

	scanf("\n%s",s);
	n=strlen(s);
	for(ll i=n;i>=1;i--)
		s[i]=s[i-1]-48;
	ans=calc=n;
	for(ll i=1;i<=n;i++)
	{
		if(s[i]==1)
			ans=min(ans,max(min(i,n-i+1),max(i-1,n-i)));
		else
			calc=min(calc,max(min(i,n-i+1),max(i-1,n-i)));
	}
	cout<<max(ans,calc);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll i,j;
    ll h,w;
    cin>>h>>w;
    if(h==1||w==1) {
        cout<<1<<endl;
        return 0;
    }
    ll all=h*w;
    if(h%2==1&&w%2==1) all++;
    cout<<all/2<<endl;

}

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

def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

tmp = num_divisors_table(n-1)
print(sum(tmp))


Measured memory_bytes: 75676
package main

import (
	"fmt"
	"strconv"
)

func main() {
	a, b := ScanInt(), ScanInt()

	c := 0
	for i := a; i <= b; i++ {
		s := strconv.Itoa(i)
		h := string(s[0 : len(s)/2])
		t := ReverseStr(s[(len(s)+1)/2:])
		if h == t {
			c++
		}
	}

	fmt.Println(c)
}

func ScanInt() (i int) {
	fmt.Scan(&i)
	return
}

func ReverseStr(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int A,B,C,D;cin>>A>>B>>C>>D;
    for(int i=0;;i++){
        if(i%2==0) C-=B;
        else A-=D;
        if(A<=0){
            cout<<"No"<<endl;
            break;
        }
        if(C<=0){
            cout<<"Yes"<<endl;
            break;
        }
    }
}

Measured memory_bytes: 3624
def max_heapify(x = 1)
  l = 2*x
  r = 2*x+1
  if l <= $n && $heap[l][0] > $heap[x][0]
    maximum = l
  else
    maximum = x
  end
  if r <= $n && $heap[r][0] > $heap[maximum][0]
    maximum = r
  end
  if maximum != x
    $heap[x], $heap[maximum] = $heap[maximum], $heap[x]
    max_heapify(maximum)
  end
end

def extract
  key = $heap[1]
  $heap[1] = $heap[$n]
  $n -= 1
  max_heapify
  key
end

def insert(key)
  $n += 1
  $heap[$n] = key
  i = $n
  while i > 1 && $heap[i/2][0] < $heap[i][0]
    $heap[i], $heap[i/2] = $heap[i/2], $heap[i]
    i /= 2
  end
end

def dist(p0, p1)
  Math.sqrt( (p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2 )
end

def find(x)
  x == $sibling[x] ? x : $sibling[x] = find($sibling[x])
end

n, m = gets.split.map(&:to_i)
$sibling = Array.new(n + 1) { |i| i }
p = [ 0, *n.times.map { gets.split.map(&:to_f) } ]
q = m.times.map { gets.split.map(&:to_i) }
sum = 0
$n = 0
$heap = []
q.each do |a, b|
  insert( [dist(p[a], p[b]), a, b] )
end
until $n < 1
  d, p0, p1 = extract
  if ( p0 = find(p0) ) != ( p1 = find(p1) )
    $sibling[p1] = p0
  else
    sum += d
  end
end
p sum

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

#include <stdio.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iostream>
#include <algorithm>
#include <deque>
#include <assert.h>
#include <time.h>

using namespace std;

using ll = long long;

#define clr(a) (a.clear())
#define sz(x) (int)x.size()
#define mem(a,b) memset(a, b, sizeof(a))
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define pb push_back
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);

#define X first
#define Y second

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

const ll inf = 1;
const ll mod = 1E9;


#define SZ 100010



int main() {
#if defined JESI
//        freopen("1.txt", "r", stdin);
//        freopen("2.txt", "w", stdout);
#endif

    ios::sync_with_stdio(false);

    int n, a, b;
    cin >> n >> a >> b;
    cout << (((b - a - 1) % 2) ? "Alice" : "Borys") << endl;

    return 0;
}







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

# F(A, B)を定義する
def F(A, B):
    A = str(A)
    B = str(B)
    if len(A) >= len(B):
        return len(A)
    else:
        return len(B)

minimumList = []
for a in range(1, int(N**0.5) + 1):
    if N % a == 0:
        b = N // a
        minimumList.append(F(a, b))
print(min(minimumList))

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>

using namespace std;
using ll = unsigned long long;

int main() {

	int a, b, c;

	cin >> a >> b >> c;

	int v = a;
	for (int i = 0; i < 110; i++) {
		if (v % b == c) {
			cout << "YES" << endl;
			return 0;
		}
		v += a;
	}

	cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7
n=int(input())
xl=[list(map(int,input().split())) for i in range(n)]
from collections import deque
# for i in range(n):
#     right.append(xl[i][0]+xl[i][1])
#     left.append(xl[i][0]-xl[i][1])
ans=0
xl.sort()
# right.sort()
# left.sort()
d=deque(xl)
while d:
    tmp=d.popleft()
    while d:
        if tmp[0]+tmp[1]>d[0][0]-d[0][1]:
            ans+=1
            if tmp[0]+tmp[1]>d[0][0]+d[0][1]:
                # d.popleft()
                break
            elif tmp[0]-tmp[1]>d[0][0]-d[0][1]:
                d.popleft()
            else:
                d.popleft()
        else:
            break
if n==1:
    print(1)
    quit()

print(n-ans)

Measured memory_bytes: 58972
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cstring>
#include <functional>
//#include<unordered_map>
//#include<unordered_set>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P; 
const int N = 1000006;
//////////////////////////////

int h, w;
char g[2222][2222];
int tate[2222][2222];
int yoko[2222][2222];

void solve()
{
	cin >> h >> w;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			cin >> g[i][j];
			if (g[i][j] == '.') {
				tate[i][j] = 1;
				yoko[i][j] = 1;
			}
		}

	for (int i = 0; i < h; i++) {
		for (int j = 1; j < w; j++) {
			if (yoko[i][j] != 0) yoko[i][j] += yoko[i][j - 1];
		}
		for (int j = w-2; j >=0 ; j--) {
			if (yoko[i][j] != 0 && yoko[i][j] < yoko[i][j + 1]) yoko[i][j] = yoko[i][j + 1];
		}
	}

	for (int j = 0; j < w; j++) {
		for (int i = 1; i < h; i++) {
			if (tate[i][j] != 0) tate[i][j] += tate[i - 1][j];
		}
		for (int i = h-2; i >= 0; i--) {
			if (tate[i][j] != 0 && tate[i][j] < tate[i+1][j]) tate[i][j] = tate[i + 1][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			if (g[i][j] == '.') {
				ans = max(ans, tate[i][j] + yoko[i][j]);
			}
		}
	cout << ans-1 << endl;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
	solve();
	return 0;
}


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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

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

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

ll fastPow(ll x, ll n)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

ll modDiv(ll a, ll b)
{
    return a * fastPow(b, MOD - 2) % MOD;
}

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

    int q;
    cin >> q;

    ll fac[1123456];
    fac[0] = 1;
    fac[1] = 1;
    for (int i = 2; i <= MOD; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
    }

    V res;
    REP(i, q)
    {
        ll x, d, n;
        cin >> x >> d >> n;

        if (d == 0)
        {
            res.push_back(fastPow(x, n));
            continue;
        }

        ll s = modDiv(x, d);
        ll t = (s + n - 1);

        if (s % MOD == 0 || t % MOD == 0 || (s / MOD != t / MOD))
        {
            res.push_back(0);
            continue;
        }

        ll r = modDiv(fac[t % MOD], fac[s - 1]) * fastPow(d, n) % MOD;

        res.push_back(r);
    }

    for (int i : res)
        cout << i << endl;

    return 0;
}

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

using namespace std;

char str[20] = "CODEFESTIVAL2016";
char ttr[20];

int main() {
    int i;

    scanf("%s",ttr);
    int cnt = 0;
    for (i=0;i<16;i++) cnt += (ttr[i]!=str[i]);
    printf("%d\n",cnt);

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
     char a[4],b[4];
     int len ,i,m,count=0;
     gets(a);
     gets(b);
     len=strlen(a);m=len-1;
     for(i=0;i<len;i++)
     {
     	if(a[i]==b[m])
     	{
     		count++;
		 }
		 m--;
	 }
	 if(count==len)printf("YES\n");
	 else printf("NO\n");
     
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n;cin>>n;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  ll sum=0;
  rep(i,n){
    a[i]-=i+1;
    sum+=a[i];
  }
  sort(all(a));

  vector<ll> sums(n+1);
  rep(i,n){
    sums[i+1]=sums[i]+a[i];
  }

  ll ans=ll(10e17),temp;
  ll b;
  rep(i,n){
    if(n-2*(i+1)!=0){
      b=(sums[n]-2*sums[i+1])/(n-2*(i+1));
      if(b<=a[i]){
        b=a[i];
      }else if(b>=a[i+1]){
        b=a[i+1];
      }
      temp=sums[n]-2*sums[i+1]-b*(n-2*(i+1));
      ans=min(ans,temp);
    }
  }

  cout<<ans<<endl;

}













Measured memory_bytes: 3328
N = int(input())
D = list(map(int, input().split()))
D.append(0)
D.sort()
min_v = D[1]
for n in range(1,N+1,2):
  D[n] = 24 - D[n]
D.sort()
for i in range(1, N+1):
  min_v = min(min_v, D[i] - D[i - 1])
print(min_v)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
int main(){
    int n,b,i,j;
    while(scanf("%d %d",&n,&b)!=EOF){
        char a[105][105];
        for(i=0;i<n;i++)
            scanf("%s",&a[i]);
        for(i=0;i<n;i++){
            printf("%s\n",a[i]);
            printf("%s\n",a[i]);
    }
}
    return 0;
}


Measured memory_bytes: 256
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.container.rbtree;
import std.conv;
import std.math;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	int a, b;
}

void parseInput(T)(out Input input, T file)
{
	with (file) with (input)
	{
		auto ar = readln().strip().split().map!(to!int).array();
		a = ar[0];
		b = ar[1];
	}
}

auto main2(Input* input)
{
	with (input)
	{
        real p1 = a * 12.5;
        real p2 = b * 10;
        auto c = cast(int)round(max(p1, p2));
        int a2 = cast(int)(c * 0.08);
        int b2 = cast(int)(c * 0.1);
        if (a2 == a && b2 == b)
            return c;
        else
            return -1;
	}
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`2 2`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 25);
	}

	unittest // example2
	{
		string example =
`8 10`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 100);
	}

	unittest // example3
	{
		string example =
`19 99`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == -1);
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		struct Adapter
		{
			string[] _lines;
			this(string input) { _lines = input.splitLines(); }
			string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
		}
		parseInput(input, Adapter(example));
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, stdin);
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


Measured memory_bytes: 508
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[90]={2,1};
int main() {
	for (int i=2;i<=86;++i) a[i]=a[i-1]+a[i-2];
	int n;
	cin>>n;
	cout<<a[n]<<endl;
	return 0;
}

Measured memory_bytes: 256
from heapq import *
N, M, S = tuple(map(int, input().split()))
graph = [[] for _ in range(N)]
Max = 0
for i in range(M):
	U, V, A, B = tuple(map(int, input().split()))
	Max = max(Max, A)
	U -= 1
	V -= 1
	graph[U] += [(V, A, B)]
	graph[V] += [(U, A, B)]
Max *= (N - 1)
for i in range(N):
	C, D = tuple(map(int, input().split()))
	graph[i] += [(i, -C, D)]
costs = [[2**64 for _ in range(Max + 1)] for _ in range(N)]
que = [(0, 0, S)]
while que:
	(cost_sum, node, coins) = heappop(que)
	for to, pay, cost in graph[node]:
		if coins >= pay and cost_sum + cost < costs[to][min(Max, coins - pay)]:
			costs[to][min(Max, coins - pay)] = cost_sum + cost
			heappush(que, (cost_sum + cost, to, min(Max, coins - pay)))
for i in range(1, N):
	print(min(costs[i]))

Measured memory_bytes: 25968
#include <stdio.h>
#include <iostream>
#include <algorithm>
#define MAXN 2005
using namespace std;
int a[MAXN];
int main()
{
    int n, z, w;
    while(cin >> n >> z >> w)
    {
        for(int i = 1; i <= n; i++) cin >> a[i];
        if(n == 1)
        {
            cout << max(a[n], w) - min(a[n], w) << endl;
        }
        else
        {
            int ans1 = max(a[n], w) - min(a[n], w);
            int ans2 = max(a[n - 1], a[n]) - min(a[n], a[n - 1]);
            cout << max(ans1, ans2) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#define eps 1e-8
using namespace std;
double L[100],R[100],B[100],T[100];
double X,Y,v,g=9.8;
int n;
int sgn(double x)
{
	return x<-eps?-1:x>eps;
}
int ck(double a,double b,double c)
{
	if(sgn(a-c)*sgn(b-c)<0) return 1;
	return 0;
}
int ck(double h)
{
	//printf("%f\n",h);
	for(int i=0;i<n;i++){
		if(sgn(L[i]-X)<=0) {
			double x=L[i];
			double y1=h*x-g/2/v/v*x*x*(1+h*h);
			if(sgn(y1-T[i])<0&&sgn(y1-B[i])>0) return 0;
			if(sgn(R[i]-X)>=0) x=X;
			else x=R[i];
			double y2=h*x-g/2/v/v*x*x*(1+h*h);
			if(ck(y1,y2,B[i])||ck(y1,y2,T[i])||ck(y1,y2,(B[i]+T[i])/2)) return 0;
		}
		if(sgn(R[i]-X)<=0){
			double x=R[i];
			double y=h*x-g/2/v/v*x*x*(1+h*h);
			if(sgn(y-T[i])<0&&sgn(y-B[i])>0) return 0;
		}
	}
	double y=h*X-g/2/v/v*X*X*(1+h*h);
	//printf("%f\n",y);
	if(sgn(y-Y)>=0) return 1;
	return 0;
}
int ck(double x,double y)
{
	if(sgn(x)==0) return 0;
	double a=-g/2/v/v*x*x;
	double b=x;
	double c=-g/2/v/v*x*x-y;
	double w=b*b-4*a*c;
	if(sgn(w)<0) return 0;
	w=sqrt(w);
	double h1=(-b+w)/(2*a);
	if(ck(h1)) return 1;
	h1=(-b-w)/(2*a);
	return ck(h1);
}
int main()
{
	scanf("%d%lf%lf%lf",&n,&v,&X,&Y);
	for(int i=0;i<n;i++)
		scanf("%lf%lf%lf%lf",L+i,B+i,R+i,T+i);
	int flag=0;
	if(sgn(v)){
		for(int i=0;i<n;i++){
			if(ck(L[i],B[i])||ck(R[i],B[i])||ck(L[i],T[i])||ck(R[i],T[i])) {
				flag=1;
				break;
			}
		}
	}
	if(ck(X,Y)) flag=1;
	if(flag) puts("Yes");
	else puts("No");
}
/***
0 7 3 1
0.466667
2.866667
No
***/

Measured memory_bytes: 0
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end);

#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"

using namespace std;

const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};

typedef long long ll;

int n,h,w;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	cin>>n>>h>>w;
	cout<<((n-h+1)*(n-w+1));
	
	//printf("Time used = %.4f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

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

int n, m, x;
int c[13];
int a[13][13];

void solve() {
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) cin >> a[i][j];
    }
    // --
    long long ans = LLONG_MAX;
    for (int subset = 1; subset < (1 << n); subset++) {
        //
        vector<int> understanding (m, 0);
        int troubled = m;
        long long subans = 0;
        //
        for (int b = 0; b < n; b++) {
            if (subset & (1 << b)) {
                for (int j = 0; j < m; j++) {
                    if (understanding[j] < x) {
                        understanding[j] += a[b][j];
                        troubled -= (understanding[j] >= x);
                    }
                }
                subans += c[b];
            }
        }
        //
        if (troubled == 0) {
            ans = min(ans, subans);
        }
    }
    //
    cout << (ans == LLONG_MAX ? -1 : ans) << endl;
}

int main() {
    solve();
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
#define repi(i,a,b) for(lint i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) tsort(v); reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif

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

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

    lint n, p=1;cin>>n;
    while(p*2<=n)p*=2;
    co(p);
}

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


signed main(){
    string S;
    cin >> S;
    string thn[4]={"resare","remaerd","esare","maerd"};
    int tyn[4]={6,7,5,5};
    bool c=0;
    reverse(S.begin(),S.end());
    while(c==0){
        c=1;
        REP(i,4){
            while(1){
                if(S.find(thn[i])==0){
                     S.erase(0, tyn[i]);
                    // cout << S << endl;
                     c=0;
                }else{
                    break;
                }
            }
        }
    }
    if(S.size()!=0){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 512
import sys
import collections

# input処理を高速化する
input = sys.stdin.readline

def chmax(a, b):
    """ 最大値を返す関数 """
    if a >= b:
        return a
    return b

def main():
    # 入力
    N, M = map(int, input().split())
    # 隣接関係は隣接リストで管理する
    lst_edge = [[] for _ in range(N)]
    # 各頂点の入力辺の本数
    deg = [0] * N
    for _ in range(M):
        x, y = map(int, input().split())
        # 最初のindexをゼロにする
        lst_edge[x-1].append(y-1)
        deg[y-1] += 1

    # 入力辺を持たない頂点をqueueに入れる
    que = collections.deque()
    for v in range(N):
        if deg[v] == 0:
            que.append(v)

    # 各頂点の最初に入力辺を持たなかった点からの距離
    dp = [0] * N

    # For sequences, (strings, lists, tuples), use the fact that empty sequences are false.
    # https://www.python.org/dev/peps/pep-0008/#programming-recommendations
    while que:
        v = que.popleft()
        lst_nv = lst_edge[v]
        for nv in lst_nv:
            # エッジ(v, nv)をグラフから削除する
            deg[nv] -= 1
            if deg[nv] == 0:
                # エッジがなくなったことで、入力辺がなくなったらqueueに入れる
                que.append(nv)
                # 最初に入力辺を持たなかった点からの距離
                dp[nv] = chmax(dp[nv], dp[v] + 1)

    print(max(dp))

main()

Measured memory_bytes: 23056
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
li = list(map(int,input().split()))
S=Counter(li)
Sum = 0
for k in range(n):
            if S[k+1] > 1:
                Sum += (S[k+1] * (S[k+1] -1)) / 2
            else:
                continue

#k個目が何なのかを考える
for i in range(n):
    if S[li[i]] > 1:
        Sum_2 = Sum
        Sum_2 = Sum_2 - (S[li[i]] * (S[li[i]] -1)) / 2 + ((S[li[i]]-1) * (S[li[i]] -2)) / 2
        print(int(Sum_2))
    else:
        print(int(Sum))

Measured memory_bytes: 25920
N = int(input())
xs, ys = [], []
for n in range(N):
  x, y = map(int, input().split(' '))
  xs.append(x)
  ys.append(y)
  
sum_dist = 0
for n1 in range(N-1):
  for n2 in range(n1+1, N):
    sum_dist += ((xs[n1]-xs[n2])**2 + (ys[n1]-ys[n2])**2)**(1/2)

# 辺abを通る組み合わせ数は，頂点a,bをセットと見た順列なので，2!(n-1)!．
# グラフは対称で全ての辺を同じ回数通るので，組み合わせの平均を考えると，
# ave_dist = 2!(n-1)!*sum_dist / n! = 2*sum_dist / n
print((2 * sum_dist) / N)

Measured memory_bytes: 9464
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>

using namespace std;

const int MaxN = 1e6;
int a[MaxN];

int main()
{
	int n, m, ans, vis, t;
	float j, i;
	while(cin >> n)
	{
		vis = 1, a[0] = 0;
		for(i = 1; i <= n; i++)
		{
			ans = 0, j = i;
			while(1)
			{
				j = j * 1.0 / 2;
				if(j - (int)(j) == 0)	ans++;
				else
				{
					ans++;
					break;
				}
			}
			a[vis++] = ans;
		}
		sort(a, a + vis);
		if(a[vis - 1] == n) cout << a[vis - 1] << endl;
		else
		{
			m = 1;
			for(i = 1; i < a[vis - 1]; i++)  m *= 2;
			cout << m << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
n, m =map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda x:x[0])

cnt = m
cost = 0
for a, b in ab:
    buy = min(cnt, b)
    cnt -= buy
    cost += a*buy
    
print(cost)

Measured memory_bytes: 29796
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

inline double add(double a, double b){
    return abs(a+b)<(1e-10)*(abs(a)+abs(b)) ? 0.0 : a+b;
}

struct vec{
    double x,y;
    vec operator-(vec b){
        return (vec){add(x,-b.x),add(y,-b.y)};
    }
    vec operator+(vec b){
        return (vec){add(x,b.x),add(y,b.y)};
    }
    vec operator*(double d){
        return (vec){x*d,y*d};
    }
    double dot(vec v){
        return add(x*v.x,y*v.y);
    }
    double cross(vec v){
        return add(x*v.y,-y*v.x);
    }
    double norm(){
        return sqrt(x*x+y*y);
    }
};

pair<vec,vec> cross_point(vec& C, double r, vec& p1, vec& p2){
    vec P1,P2,P;
    P=(p2-p1)*((p2-p1).dot(C-p1)/(p2-p1).dot(p2-p1))+p1;
    P1=P+(p2-p1)*(sqrt(r*r-(P-C).dot(P-C))/(p2-p1).norm());
    P2=P-(p2-p1)*(sqrt(r*r-(P-C).dot(P-C))/(p2-p1).norm());
    if(P1.x==P2.x){
        if(P1.y<P2.y) return make_pair(P1,P2);
        else return make_pair(P2,P1);
    }else{
        if(P1.x<P2.x) return make_pair(P1,P2);
        else return make_pair(P2,P1);
    }
}

int main(){
    vec C,p1,p2;
    double r;
    int q;
    cin >> C.x >> C.y >> r >> q;
    cout.precision(8);
    cout << fixed;
    while(q--){
        cin >> p1.x >> p1.y >> p2.x >> p2.y;
        pair<vec,vec> P = cross_point(C,r,p1,p2);
        cout << P.first.x << " " << P.first.y << " " << P.second.x << " " << P.second.y << endl;
    }
}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, k, m, n, i, j, r, ans=0; cin >> N; bool f, g, h;
int d=to_string(N).size(), M=pow(3, d); vector<int> L;
for(i=0; i<M; i++){
f=g=h=false; m=1; n=0; k=i;
for(j=0; j<d; j++){
  r=k%3; 
  if(r==0){ f=true; n+=3*m; }else if(r==1){ g=true; n+=5*m; }else{ h=true; n+=7*m; }
  k=k/3; m=10*m;
}
if(f&&g&&h){ L.push_back(n); }
}
for(i=0; i<L.size(); i++){ if(L[i]<=N){ ans++; } }
for(i=1; i<d; i++){ ans+=pow(3, i)-3*pow(2, i)+3; }
cout << ans << "\n";
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std; 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
# define M_PI           3.14159265358979323846
#define vec vector 
int main()
{
    ll n;
    cin>>n;
    ll arr[3][n];
    ll dp[3][n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr[0][i]>>arr[1][i]>>arr[2][i];
    }
    dp[0][0]=arr[0][0];
    dp[1][0]=arr[1][0];
    dp[2][0]=arr[2][0];
    for(ll i=1;i<n;i++)
    {
        dp[0][i]=max(dp[1][i-1],dp[2][i-1])+arr[0][i];
        dp[1][i]=max(dp[0][i-1],dp[2][i-1])+arr[1][i];
        dp[2][i]=max(dp[1][i-1],dp[0][i-1])+arr[2][i];
    }
    cout<<max({dp[0][n-1],dp[1][n-1],dp[2][n-1]});
    return 0;     
}

Measured memory_bytes: 8260
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(N * A, B) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s=="Sunny")
    cout<<"Cloudy";
  else if(s=="Cloudy")
    cout<<"Rainy";
  else if(s=="Rainy")
    cout<<"Sunny";
  return 0;
}

Measured memory_bytes: 256
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
  //~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

void solve() {
  int n; cin >> n;
  int mod = n % 10;
  for(auto x : {2, 4, 5, 7, 9}) {
    if(x == mod) {
      print("hon");
      return;
    }
  }
  for(auto x : {0, 1, 6, 8}) {
    if(x == mod) {
      print("pon");
      return;
    }
  }
  print("bon");
}

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

Measured memory_bytes: 3620
H, N = gets.split.map(&:to_i)
ABs = readlines.map{|l| l.split.map(&:to_i)}
INF = 1<<30

dp = Array.new(H + ABs.map(&:first).max + 1, INF)
dp[0] = 0
mi = ->(x, y){x < y ? x : y}
ABs.sort_by{|a, b| b.to_f/a}.each do |a, b|
  H.times{|i| dp[i + a] = mi[dp[i + a], dp[i] + b] unless dp[i] == INF}
  break if dp[H] != INF
end
puts dp[H .. -1].min

Measured memory_bytes: 1916
N, x = list(map(int, input().split()))
arr = list(map(int, input().split()))

cnt, prv = 0, 0

for i in range(N):
    diff = max(arr[i] + prv - x, 0)
    cnt += diff
    arr[i] -= diff
    prv = arr[i]

print(cnt)

Measured memory_bytes: 14540
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextLong()
    val upper = Math.sqrt(N)
    val candidates = for {
      i <- (1L to upper.toLong)
      if N % i == 0
      j = N / i
    } yield i + j - 2

    val min = candidates.min
    println(min)
  }

}


Measured memory_bytes: 39336
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	ss := map[string]int{}

	n := nextInt()
	for i := 0; i < n; i++ {
		ss[next()]++
	}
	m := nextInt()
	for i := 0; i < m; i++ {
		ss[next()]--
	}

	max := 0
	for _, x := range ss {
		if max < x {
			max = x
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 640
#include<stdio.h>
int main ()
{
    int A,P,M;
    scanf("%d %d",&A,&P);
    if(0<=A && P<=100)
    {
        M=((A*3)+P)/2;
      printf("%d\n",M);
    }
    else

    {
        printf("0");
        }
return 0;
}


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

int main(){
    int a, b, x;
    cin >> a >> b >> x;
    if(a > x){
        cout << "NO" << endl;
        return 0;
    }
    x -= a;
    if(b >= x) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

c = [[0 for i in range(10)] for i in range(10)]

for n in range(1, N+1):
  i = int(str(n)[0])
  j = n % 10
  c[i][j] += 1

ans = 0
for i in range(10):
  for j in range(10):
    ans = ans + c[i][j]*c[j][i]
print(ans)

Measured memory_bytes: 3060