akhauriyash/Code-Regression huggingface dataset:
#include <atcoder/segtree>
#include <cstdio>
#include <vector>

using namespace std;
using namespace atcoder;

int op(int a, int b) { return max(a, b); }

int e() { return -1; }

int target;

bool f(int v) { return v < target; }

int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &(a[i]));
    }

    segtree<int, op, e> seg(a);

    for (int i = 0; i < q; i++) {
        int t;
        scanf("%d", &t);
        if (t == 1) {
            int x, v;
            scanf("%d %d", &x, &v);
            x--;
            seg.set(x, v);
        } else if (t == 2) {
            int l, r;
            scanf("%d %d", &l, &r);
            l--;
            printf("%d\n", seg.prod(l, r));
        } else if (t == 3) {
            int p;
            scanf("%d %d", &p, &target);
            p--;
            printf("%d\n", seg.max_right<f>(p) + 1);
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}

#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back

void solve(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a * b, c * d);
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

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

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

    string s;
    cin>>s;
    map<char,ll>m;
    ll i;
    for(i=0;i<s.length();i++)
    {
        m[s[i]]++;
    }
    if(m.size()!=2)
    {
        cout<<"No";
    }
    else
    {
        map<char,ll>:: iterator it;
        for(it=m.begin();it!=m.end();it++)
        {
            if(it->second!=2)
            {
                cout<<"No";
                return 0;
            }
        }
        cout<<"Yes";
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
   char a[101],b[101];
   scanf("%s%s",a,b);
   if(strlen(a)>strlen(b)){
     printf("GREATER\n");
            return 0;
   }
    else if(strlen(a)<strlen(b)){
         printf("LESS\n");
            return 0;
    }
   else {
    for(int i=0;i<strlen(a);i++)
    {
        if(a[i]>b[i]){
            printf("GREATER\n");
            return 0;
                          }

        else if(a[i]<b[i]){
            printf("LESS\n");
            return 0;
                                  }
        else{
            printf("EQUAL\n");
            return 0;
                }

    }
   }
}



Measured memory_bytes: 1664
#coding: utf-8
#a, b = map(int, input().split())
#a, b, c, x = map(int, [input() for i in range(4)])

a, b = map(int, input().split())

if a >= 13:
    print(b)
elif a >= 6 and a <= 12:
    print(int(b / 2))
elif a <= 5:
    print(0)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+999;
struct edge{
	int to,nxt,dis,from;
}e[maxn<<1];
int head[maxn],tot;
void add(int x,int y,int z){
	e[++tot].to=y;
	e[tot].from=x;
	e[tot].dis=z;
	e[tot].nxt=head[x];
	head[x]=tot;
}
int b[2],a[2]={INT_MAX,INT_MAX},siz[maxn],fa[maxn],n,cnt;
long long ans;
void get_barycentric(int x){
	int maxx=0;siz[x]=1;
	for(int i=head[x];i;i=e[i].nxt){
		int y=e[i].to;
		if(y==fa[x])continue;
		fa[y]=x;
		get_barycentric(y);
		maxx=max(maxx,siz[y]);
		siz[x]+=siz[y];
	}
	maxx=max(maxx,n-siz[x]);
	if(maxx<a[0]){
		a[0]=maxx;b[0]=x;b[1]=0;cnt=1;
	}
	else if(maxx==a[0])b[1]=x,cnt=2;
}
void calc(int x,int y,int z){
	if(fa[x]==y)swap(x,y);
	int tmp=min(siz[y],n-siz[y]);
	ans+=2ll*z*tmp;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;++i){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		add(x,y,z);add(y,x,z);
	}
	get_barycentric(1);
	for(int i=1;i<=tot;i+=2)
		calc(e[i].from,e[i].to,e[i].dis);
	if(cnt==1){
		int minn=INT_MAX,x=b[0];
		for(int i=head[x];i;i=e[i].nxt){
			int y=e[i].to;
			minn=min(minn,e[i].dis); 
		}
		ans-=minn;
	}
	else{
		int x=b[0];
		for(int i=head[x];i;i=e[i].nxt){
			int y=e[i].to;
			if(y==b[1]){
				ans-=e[i].dis;break;
			}
		}
	}
	cout<<ans;
}

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

int n,m,a[100010],b[100010],id[100010],fa[100010],bel[100010],x,y,d[100010],p[100010],q[100010],l,r;
long long sum[100010],f[100010],ans;
vector<int> v[100010];

bool cmp(const int &x,const int &y) {return a[x]<a[y];}
int ask(int x) {return bel[x]==x?x:bel[x]=ask(bel[x]);}
void Addedge(int x,int y) {v[x].push_back(y),v[y].push_back(x);}

int main()
{
	srand(12019687);
	scanf("%d%d",&n,&m),ans=1000000000000000000ll;
	for (int i=1; i<=n; i++) scanf("%d%d",&a[i],&b[i]),id[i]=i;
	if (n==1) return printf("%d\n",max(a[1],b[1])),0;
	for (int i=1; i<=m; i++) scanf("%d%d",&x,&y),Addedge(x,y);
	sort(id+1,id+1+n,cmp);
	for (int qaq=1; qaq<=130; qaq++)
	{
		for (int l=1,r; l<=n; l++)
		{
			r=l;
			while (r<n&&a[id[r+1]]==a[id[l]]) r++;
			random_shuffle(id+l,id+r+1),l=r;
		}
		for (int i=1; i<=n; i++) p[id[i]]=i,d[i]=0;
		for (int i=1; i<=n; i++) bel[i]=i,fa[i]=0;
		for (int i=1; i<=n; i++)
		{
			x=id[i];
			for (int j:v[x])
				if (p[j]<i&&(y=ask(j))!=x) fa[y]=x,bel[y]=x;
		}
		l=1,r=0;
		for (int i=1; i<=n; i++) if (fa[i]) d[i]++,d[fa[i]]++;
		for (int i=1; i<=n; i++) if (d[i]==1&&fa[i]) q[++r]=i;
		while (l<=r)
		{
			x=q[l++];
			if (fa[x]&&(--d[fa[x]])==(fa[x]!=id[n])) q[++r]=fa[x];
		}
		sum[0]=0;
		for (int i=1; i<=n; i++) f[i]=1000000000000000000ll,sum[i]=b[i];
		for (int i=1; i<=r; i++) 
		{
			x=q[i];
			f[x]=min(sum[x]-b[x]+f[x],sum[x]-b[x]+max(a[x],b[x]));
			f[fa[x]]=min(f[fa[x]],max(1ll*a[fa[x]],b[fa[x]]+f[x])-sum[x]);
			sum[fa[x]]+=sum[x];
		}
		ans=min(ans,f[id[n]]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 10620
#include <bits/stdc++.h>
// until dimension reduction.

using namespace std;
typedef long long LL;

#define LOG(...) fprintf (stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()

const int INF = 0x3f3f3f3f, N = 100010;
const LL INFL = 0x3f3f3f3f3f3f3f3fll;
vector <int> g[N], num[N];
int n, deg[N], ans[N];
set <int> used[N];

void dfs (int u, int pre, int lstc) {
//	cout << "dfs " << u << " " << pre << " " << lstc << endl;
	int cnt = 0; 
	for (int i = 0; i < g[u].size(); i++) {
		int v = g[u][i], id = num[u][i];
		if (v == pre) continue;
		cnt++;
		if (cnt == lstc) cnt++; 
		ans[id] = cnt; 
		dfs (v, u, cnt);
	}
}
int main() {
#ifdef LiM_817
	freopen ("input.txt", "r", stdin);
	double cl = clock();
#endif
	
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v); num[u].pb(i);
		g[v].pb(u); num[v].pb(i);
		++deg[u], ++deg[v];
	}
	int k = *max_element (deg + 1, deg + n + 1);
//	cout << k << endl;
	
	dfs (1, 0, 0);
	cout << *max_element (ans + 1, ans + n) << endl;
	for (int i = 1; i < n; i++) cout << ans[i] << endl;
#ifdef LiM_817
	cerr << fixed << setprecision(2) << "Time ellapsed: " << ((double)(clock() - cl) / CLOCKS_PER_SEC) << "s\n";
#endif
	return 0;
}


Measured memory_bytes: 18688
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
typedef long long ll;
using namespace std;
const int maxn=200100;
int n;
ll ai[maxn],bi[maxn];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&ai[i]);
    for(int i=1;i<=n;i++) bi[i]=ai[i]-i;
    sort(bi+1,bi+n+1);
    ll tmp;
    if(n%2==1) tmp=bi[(n+1)/2];
    else tmp=(bi[n/2]+bi[(n+1)/2])/2;
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=(abs(ai[i]-i-tmp));
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3328
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int ans=700;
		String b;
		String a;
		a=sc.next();

		for(int i=0;i<3;i++){
			if(a.charAt(i)=='o') ans=ans+100;
		}

		System.out.println(ans);
	}
}

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

int main()
{
	int a,b,c;	
	int i=0;
	cin>>a>>b>>c;
	for(int x=a;x<=b;x++){
		if (c%x==0)
			i++;
	}
	cout<<i<<endl;
	return 0;
}


Measured memory_bytes: 3124
#include<stdio.h>

int main(void){


int a,b,c,x,y,z;


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


if(a>b){


x=a;


a=b;


b=x;


}


if(b>c){


y=b;


b=c;


c=y;


}


if(a>b){


z=a;


a=b;


b=z;


}


printf("%d %d %d\n",a,b,c);


return 0;


}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
        ll i,j,k,l,m,n;
        ll dp[100005];
        cin>>n>>k;
        vi v(n);
        cin>>v;
        clr(dp,0);
        for(i=0;i<=k;i++)
        {
            if(dp[i]==0)
            {
                for(j=0;j<n;j++)
                {
                    if(v[j]+i<=k)
                        dp[v[j]+i]=1;
                }
            }
        }
        if(dp[k])
            cout<<"First";
        else
            cout<<"Second";
    }
    return 0;
}

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
using ld = long double;  using vld = vector<ld>; 

int main(void) {
	ll r; cin >>r;
	
	if(r<1200) cout <<"ABC" <<endl;
	if(1200<=r&&r<2800) cout <<"ARC" <<endl;
	if(2800<=r) cout <<"AGC" <<endl;
	
	
    return 0;
}

Measured memory_bytes: 256
def find(x):
    if(par[x]==x):
        return x
    else:
        par[x]=find(par[x])
        return par[x]
def union(a,b):
    a=find(a)
    b=find(b)
    if(a==b):
        return 0
    else:
        if rank[a]>rank[b]:
            par[b]=a
            siz[a]+=siz[b]
        else:
            par[a]=b
            siz[b]+=siz[a]
            if rank[a]==rank[b]:
                rank[b]+=1
def size(a):
    return siz[find(a)]
def same(a,b):
    return find(a)==find(b)
    
N,M=map(int,input().split())
par=[i for i in range(N)]
siz=[1 for _ in range(N)]
rank=[0 for _ in range(N)]

p=list(map(lambda x:int(x)-1,input().split()))
dic={p[i]:i for i in range(N)}

for i in range(M):
    x,y=map(lambda x:int(x)-1,input().split())
    union(dic[x],dic[y])
cnt=0
for i in range(N):
    if same(i,p[i]):
        cnt+=1
print(cnt)

Measured memory_bytes: 103340
// 0238
#include <iostream>
using namespace std;

int main(){
	while(1){
		int t, n, time = 0;

		cin>>t;
		if(t == 0)
			break;

		cin>>n;
		for(int i=0;i<n;i++){
			int s, f;
			cin>>s>>f;

			time += f-s;
		}

		if(time >= t)
			cout<<"OK"<<endl;
		else
			cout<<t-time<<endl;
	}
	return 0;
}

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

#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

signed main(){
	int X,Y;

	cin>>X>>Y;

	if((Y-2*X)%2){
		cout<<"No"<<endl;
		return 0;
	}

	int b=(Y-2*X)/2;
	int a=X-b;

	if(0<=a&&0<=b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
    return 0;
}


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

string s;
int main() {
  cin >>s;
  sort(s.begin(),s.end());
  if((s[0]==s[1] && s[2]==s[3]) && s[0]!=s[2]) cout << "Yes" << endl;
  else cout <<"No"<< endl;
}

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

#define fst first
#define snd second
#define pb push_back

template<typename T> bool chkmin(T&a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool chkmax(T&a, T b) { return a < b ? a = b, 1 : 0; }

const int maxn = 100 + 10;

int n;
bool g[maxn][10];
int f[maxn][10], a[maxn];

int main() {

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

    g[0][0] = 1;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < 10; j++) if(g[i-1][j]) {
            chkmax(f[i][j], f[i-1][j]);
            g[i][j] = 1;
            chkmax(f[i][(j+a[i])%10], f[i-1][j] + a[i]);
            g[i][(j+a[i])%10] = 1;
        }
    }
    int ans = 0;
    for(int i = 1; i < 10; i++) chkmax(ans, f[n][i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n,i,m[600000],k,j;
vector <int> v(300000,1e9 + 5);
int main(){
	cin>>n>>k;
  	for (i=0; i<n; i++) cin>>m[i];
  	v[0] = 0;
  	for (i=0; i<n; i++){
      for (j = i+1; j<i+k+1; j++){
        if (j<n)
      	v[j]=min(v[j], v[i] + abs(m[i]- m[j]));
      }
    }
    cout<<v[n-1];
}

Measured memory_bytes: 4772
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int N;
P robots[100000];

int main(void){
	cin >> N;
	for(int i = 0; i < N; i++){
		int x, l;
		cin >> x >> l;
		robots[i].first = x + l;
		robots[i].second = x - l;
	}
	sort(robots, robots + N);

	int pos = -1 * INF;
	int res = 0;
	for(int i = 0; i < N; i++){
		if(pos <= robots[i].second){
			res++;
			pos = robots[i].first;
		}
	}

	cout << res << '\n';

	return 0;
}

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

int main() {
    long long N,k,v,p;
    long long a=1,ans=0,b=0;
    cin >> N >> k;
    vector<long long> A(N);
    priority_queue<long long> que;
  
    for (long long i = 0; i < N; i++) {
        cin >> A.at(i);
        que.push(A.at(i));
    }

    for (long long i = 0; i < k; i++) {
        que.pop();
    }
    for (long long i = 0; i < N-k; i++) {
        ans+=que.top();
        que.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 3956
#include<iostream>

int main(){
    
    int i,j;
    std::cin >> i >> j;
    while(!(i==0 && j==0)){
        if(i>=j) std::cout << j << " " << i << std::endl;
        else     std::cout << i << " " << j << std::endl;
        std::cin >> i >> j;
    }
    
    return 0;
}


Measured memory_bytes: 3088
h,w=map(int,input().split())
dx=[0,1,0,-1] ; dy=[1,0,-1,0]
A=[list(input()) for i in range(h)]

for i in range(h):
    for  j in range(w):
        if A[i][j]=="#":
            for q,e in zip(dx,dy):
                if 0<=i+q<h and 0<=j+e<w:
                    if A[i+q][e+j]=="#":break
            else:
                print("No");exit()
print("Yes")


Measured memory_bytes: 9116
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <cassert>
#include <functional>
#include <iterator>
using namespace std;
using VI = vector<int>;

int main() {
    VI v(3);
    cin >> v[0] >> v[1] >> v[2];
    sort(v.begin(), v.end());
    cout << v[0] + v[1] << endl;
}


Measured memory_bytes: 256
'use strict';

function Main(input) {
  const N = input.split("\n")[0].split(" ")[0]
  const M = input.split("\n")[0].split(" ")[1]
  const C = input.split("\n")[0].split(" ")[2]
  const B = input.split("\n")[1].split(" ").map(x => Number(x))
  const qList = input.split("\n").slice(2).map(x => x.split(" "))
  let ans = 0
  
  for (let q of qList) {
    let count = 0
    for (let i = 0; i < M; i++) {
        count += q[i] * B[i]
    }
    if (count > -1 * C) {
        ans++
    }
  }

  console.log(ans)
  
};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


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

int main()
{
    int n;
    cin>>n;
    vector<int> vb;
    for(int i=0; i<n-1; i++)
    {
        int p;
        cin>>p;
        vb.push_back(p);
    }
    int ans = vb[0];
    for(int i=0; i<n-1; i++)
    {
        if(vb[i] <= vb[i+1])
        {
            ans += vb[i];
        }
        else
        {
            ans += vb[i+1];
        }
    }
    ans += vb[n-2];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int A, B;
    
    scanf("%d %d", &A, &B);
    
    if(A <= 5) {
        B = 0;
    } else if(A <= 12) {
        B = B / 2;
    } else {
        B = B;
    }
    
    printf("%d", B);

    return 0;
}


Measured memory_bytes: 128
from collections import Counter


def solve(n, cnt):
    if len(cnt) == 1:
        a = next(iter(cnt))
        return (a == n - 1) or (1 <= a <= n // 2)
    a1, a2 = min(cnt), max(cnt)
    if a2 - a1 > 1:
        return False
    c1, c2 = cnt[a1], cnt[a2]
    return c1 < a2 and a2 - c1 <= c2 // 2


n = int(input())
cnt = Counter(map(int, input().split()))

print('Yes' if solve(n, cnt) else 'No')


Measured memory_bytes: 22636
#include<iostream>
using namespace std;
int main () {
  int N;
  cin >> N;
  int st[200002];
  st[0] = 0;
  for (int i = 1; i <= N; i ++) {
     st[i] = st[i - 1];
    char c;
    cin >> c;
    if (c == '.') st[i] ++;
  }
  int ans = 10000000;
  for (int i = 0; i <= N; i ++) {
    int k = i - st[i] + st[N] - st[i];
    //cout << k << endl;
    if (ans > k) ans = k;
  }
  cout << ans << endl;
}
  



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n;
double dp[301][301][301];
double solve(int x , int  y ,int  z)
{ 
   if(x == 0 && y == 0 && z == 0)
    return 0;

   if(x<0 || y<0 || z<0)
    return 0;

   if(dp[x][y][z]> -1.0)
     return dp[x][y][z];

   double cal =  (n + x*solve(x-1,y,z)+y*solve(x+1,y-1,z)+z*solve(x,y+1,z-1))/(x+y+z);

   return dp[x][y][z] = cal;
}

int main(void)
{
  cin>>n;int k;
  int x,y,z;x = y = z = 0;
  for(int  i = 0;i<n;i++)
  {
    cin>>k;
    if(k==1)
      x++;
    if(k == 2)
      y++;
    if(k == 3)
      z++;
  }
   memset(dp , -1 ,sizeof dp);
    cout<<fixed<<setprecision(10)<<solve(x,y,z)<<endl;

}

Measured memory_bytes: 213504
#author : dokueki

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, k = map(int, sys.stdin.readline().split())
    if k > n:
        print(1)
    else:
        ans = 0
        for i in range(k, n+2):
            i = i - 1
            l = ((i * (i + 1)) // 2)%mod
            r = ((n*(n+1))//2 - ((n-i)*(n-i-1))//2) % mod
            ans += ((r-l)+1) % mod
        print(ans % mod)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()


Measured memory_bytes: 63560
const main = input => {
  const number = parseInt(input.replace(' ', ''), 10)
  const square = Math.sqrt(number)
  if (square === parseInt(square, 10)) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            String s = sc.next();
            String t = sc.next();

            boolean isOk = false;
            for (int i = 0; i < s.length(); i++) {
                boolean tmpFlag = true;
                for (int j = 0; j < s.length(); j++) {
                    if (s.charAt(j) != t.charAt((j + i) % s.length())) {
                        tmpFlag = false;
                        break;
                    }
                }
                if (tmpFlag) {
                    isOk = true;
                    break;
                }
            }

            if (isOk) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }

}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a*b/gcd(a,b);
}

long long com(long long n,long long k){
	
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	string t;
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(b,c)<<endl;
	cout<<max((b+c-a),0)<<endl;
}

	


Measured memory_bytes: 256
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	ll w, h, x, y;
	cin >> w >> h >> x >> y;
	double ans = (double)w * h * 0.5;
	printf("%.12f ", ans);
	if (w == x * 2 && h == y * 2) {
		cout << "1" << endl;
	}
	else {
		cout << "0" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a<c&&c<b)cout << "Yes"<<endl;
  else if(b<c&&c<a)cout << "Yes"<<endl;
  else cout << "No"<<endl;
}

Measured memory_bytes: 256
a,b,c,d,e = 0,0,0,0,0
for _ in [0]*int(input()):
  s = input()[0]
  if s == "M":
    a += 1
  elif s == "A":
    b += 1
  elif s == "R":
    c += 1
  elif s == "C":
    d += 1
  elif s == "H":
    e += 1
print(a*b*(c+d+e)+(a+b)*(c*d+d*e+e*c)+c*d*e)

Measured memory_bytes: 3828
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

int main() {
	int n, K; cin >> n >> K;
	vector<int> A(n); for (int i = 0; i < n; ++ i) cin >> A[i];

	vector<int> count(n);
	for (int i = 0; i < n; i++) {
		count[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		count[A[i]]++;
	}
	sort(count.begin(), count.end());
	reverse(count.begin(), count.end());
	long long sum = 0;
	long long ret = 0;
	for (int i = 0; i < K; i++) {
		sum += count[i];
	}
	ret = n - sum;
	cout << ret << endl;
}



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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  int a;
  REP (i, n) scanf("%d", &a);

  int ans = 1;
  n -= k;

  if (n % (k - 1) == 0) ans += n / (k - 1);
  else ans += n / (k - 1) + 1;

  cout << ans << endl;
}


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

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

int main(){
  int n;
  cin>>n;
  ll ans=1,x;
  for(int i=0;i<n;i++){
    cin>>x;
    ans=lcm(ans,x);
  }
  cout<<ans<<endl;
}


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

int main()
{
    int n, c, k,ans=0;
    cin >> n >> c >> k;
    vector<int> t(n);
    rep(i, n) cin >> t[i];
    sort(t.begin(), t.end());

    int i = 0;
    while(i<n){
        int s = t[i] + k;
        int psg = 1;
        for (int j = 1; j < c && j + i < n; j++){
            if(s>=t[i+j])
                psg++;
        }
        i += psg;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

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 dp[100005];

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v(N);
  for ( int i = 0; i < N; i++) {
    int h;
    cin >> h;
    v.at(i) = h;
  }
  if (K+1 >= N) {
    cout << abs(v.at(N-1)-v.at(0)) << endl;
  }
  else {
  for (int i = 1; i <= K; i++) {
    dp[i] = abs(v.at(i)-v.at(0));
  }
  for (int i = K+1; i <N; i++) {
    priority_queue<int, vector<int>, greater<int>> q;
    for (int j = 1; j <= K; j++) {
      q.push(dp[i-j]+abs(v.at(i)-v.at(i-j)));
    }
    dp[i] = q.top();
  }
  cout << dp[N-1] << endl;
  }
}


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

int getmd(int a,int b,int c,int d){
    return abs(a-c)+abs(b-d);
}

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

    if(a==b){
        cout << a*2 << endl;
        return 0;
    }

    cout << max(a,b)*2-1 << endl;

    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	map<int, int> A;
	for (int i = 0; i < n - 1; ++i)
	{
		int in;
		cin >> in;
		++A[in];
	}
	for (int i = 1; i <= n; i++)
	{
		cout << A[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 12972
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private int totalEdge;
	private int[][] adjList;
	private int[] degree1;
	private int[] degree2;
	private int[] visited;
	private LinkedList<Integer> previsit = new LinkedList<Integer>();
	private LinkedList<Integer> postvisit = new LinkedList<Integer>();
	public Graph() {
		degree1 = null;
		degree2 = null;
		totalVertex = 0;
		totalEdge = 0;
		totalVertex = 0;
		adjList = null;
	}

	public void loadList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		totalEdge = in.nextInt();
		degree1 = new int[totalVertex];
		degree2 = new int[totalVertex];
		adjList = new int[totalVertex][totalVertex];
		for (int i = 0; i < totalVertex; i++) {
			degree1[i] = 0;
			degree2[i] = 0;
		}
		for (int i = 0; i < totalEdge; i++) {
			int x = in.nextInt();
			int y = in.nextInt();
			adjList[x][degree2[x]] = y;
			degree1[y]++;
			degree2[x]++;
		}
		in.close();
		visited = new int[totalVertex];
		for (int i = 0; i < totalVertex; i++)
			visited[i] = 0;
	}
	
	public void DFS(int vertex) {
		previsit.add(vertex);
		visited[vertex] = 1;
		for (int i = 0; i < degree2[vertex]; i++)
			if (visited[adjList[vertex][i]] == 0)
				DFS(adjList[vertex][i]);
		postvisit.add(vertex);
	}
	public void DFStopological() {
		for (int i = 0; i < totalVertex; i++)
			if (degree1[i] == 0)
				DFS(i);
		LinkedList<Integer> list = new LinkedList<Integer>();
		Iterator<Integer> iterator = postvisit.iterator();
		while (iterator.hasNext())
			list.add(0, iterator.next());
		display(list);
	}
	public void display (LinkedList<Integer> list) {
		Iterator<Integer> iterator = list.iterator();
		while(iterator.hasNext())
			System.out.println(iterator.next());
	}
}

public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadList();
		g.DFStopological();
	}
}



Measured memory_bytes: 559336
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
struct as
{
    int x,y;
}pos[10]; //用来存储每次的起点和终点
struct node
{
    int x,y;
    int step;
};
bool vis[1010][1010];
char maze[1050][1050];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int H,W,N;

bool check(int x,int y)
{
    if (x<=0 || x>H) return 1;
    if (y<=0 || y>W) return 1;
    if (vis[x][y]) return 1;
    if (maze[x][y] =='X')return 1;
    return 0;
}
int bfs(int m,int n)
{
    memset(vis,0,sizeof vis);
    int sx = pos[m].x, sy = pos[m].y;
    int gx = pos[n].x, gy = pos[n].y;
   // printf("%d %d\n",sx,sy);
   // printf("%d %d\n",gx,gy);
    queue<node> Q;
    node a,next;
    a.step = 0;
    a.x = sx, a.y =sy;
    Q.push(a);
    while(!Q.empty())
    {
        a = Q.front();
        Q.pop();
        if (a.x == gx && a.y == gy)
            return a.step;
        for(int i = 0; i < 4 ;i++)
        {
            int nx = a.x + dx[i];
            int ny = a.y + dy[i];
            if(check(nx,ny))
                continue;
            else
            {
                vis[nx][ny] =1;
                next.x = nx,next.y = ny,next.step = a.step+1;
                Q.push(next);
            }
        }
    }
    return 999999;
}

int main()
{
   // freopen("in.txt","r",stdin);
    while(cin>>H>>W>>N)
    {
        int sx,sy;
        for(int i = 1;i<=H;i++)
        {
            for(int j = 1; j <= W;j++)
            {
                cin>>maze[i][j];
                if (maze[i][j] >='1' && maze[i][j]<='9')
                {
                    pos[maze[i][j]-'0'].x = i;
                    pos[maze[i][j]-'0'].y = j;
                }
                if (maze[i][j]=='S')
                    sx=i,sy = j;
            }
        }

        pos[0].x = sx,pos[0].y = sy;
        int ans = 0;
        for(int i = 0;i<N;i++)
            ans += bfs(i,i+1);
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 5080
#include<stdio.h>
#include<math.h>
#define PI 3.14159265358979323846264338327950
int main(void){
   double a,b,h,w;
 
  scanf("%lf%lf%lf%lf",&a,&b,&h,&w);
   double s; 
  s=fabs(360*h/12+0.5*w-360*w/60);

  //if(s>180)s=360-s;


  double sita=s*PI/180;
 
  long double ans=sqrt(a*a+b*b-2*a*b*cosl(sita));
  printf("%.20Lf",ans);
  return 0;
}

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

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Program
{
    static int N;
    static int[] h;

    public static void Main(string[] args)
    {
        N = Input.NextInt();
        h = Input.LineInt();

        int c = 0;
        for (int max = h.Max(); max > 0; max--)
        {
            int mode = 0; // non-max
            for (int j = 0; j < h.Length; j++)
            {
                if (h[j] == max)
                {
                    if (mode == 0)
                    {
                        mode = 1;
                        c++;
                    }
                    h[j] = max - 1;
                }
                else
                {
                    if (mode != 0)
                    {
                        mode = 0;
                    }
                }
            }
        }
        
        Console.WriteLine(c);
    }
}


Measured memory_bytes: 13524
#include<bits/stdc++.h>
using namespace std;
vector<int>v[100007];
int dp[100007][2][2][2],n;

int solve(int x,int y, int z,int i)
{
    if(i>=n) return 0;
    if(dp[i][x][y][z]!=-1) return dp[i][x][y][z];
    dp[i][x][y][z]=0;
    if(x==0){
        dp[i][x][y][z]=max(dp[i][x][y][z],solve(x+1,0,0,i+1)+v[i][0]);
    }
    if(y==0)
    {
        dp[i][x][y][z]=max(dp[i][x][y][z],solve(0,y+1,0,i+1)+v[i][1]);
    }
    if(z==0)
    {
        dp[i][x][y][z]=max(dp[i][x][y][z],solve(0,0,z+1,i+1)+v[i][2]);
    }
    return dp[i][x][y][z];
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        v[i].push_back(a); v[i].push_back(b); v[i].push_back(c);
    }

    memset(dp,-1,sizeof(dp));

    printf("%d\n",solve(0,0,0,0));


    return 0;
}


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

int solve(int, int);

int main() {
    int n, x;
    
    while(1) {
        cin >> n >> x;
        
        if (n == 0 && x == 0) {
            break;
        } else {
            cout << solve(n, x) << endl;
        }
        
    }
}

int solve(int n, int x) {
    int cnt = 0;
    
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (i + j + k + 3 == x) {
                    cnt++;
                } else if (i + j + k >= x) {
                    break;
                }
            }
        }
    }
    
    return cnt;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>
#define m 1000000007LL
using namespace std;
typedef long long ll;
int n;
string x[1001];
vector <int> G[1001];
ll R[11],SUM;

void saiki2(int ima,ll sum,int kai){
  if(ima==-1)return;
  for(int i=ima-1;i>=0;i--) saiki2(i,sum*R[i],kai+1);
  if(kai)SUM+=sum;
}

ll saiki(int ima){
  ll S=G[ima].size(),res=1,r[11];
  for(int i=0;i<S;i++)r[i]=saiki(G[ima][i]);

  if(x[ima][0]=='E') {
    res=1;
    for(int i=0;i<S;i++) res*=r[i];
  }
  if(x[ima][0]=='A'){
    res=0;
    for(int i=0;i<S;i++) res+=r[i];
  }
  if(x[ima][0]=='R'){
    SUM=0;
    for(int i=0;i<S;i++) R[i]=r[i];
    saiki2(S,1,0);
    res=SUM;
  }
  return (res+x[ima].size()-1)%m;
}

int main(){



  cin >>n;
  string str;
  //E,E?,A,R,A?,B?
  for(int i=1;i<=n;i++)cin>>x[i];
  
  for(int i=1;i<n;i++){
    int a,b;
    cin >>a>>b;
    G[a].push_back(b);
  }
  cout <<saiki(1)<<endl;
  return 0;
}

Measured memory_bytes: 1444
#include<stdio.h>

int main(){
  int a,b,c,t;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  
  t=a; a=b; b=t;
  t=a; a=c; c=t;
  
  printf("%d %d %d",a,b,c);
  
  return 0;
}

Measured memory_bytes: 1704
n, k, q = map(int, input().split(" "))
a = []
points = []
for i in range(0,n):
  points.append(k - q)

for s in range(0,q):
  a = int(input()) - 1
  points[a] = points[a] + 1

for t in range(0, n):
  result = "Yes"
  if points[t] <= 0:
    result = "No"
  print(result)

Measured memory_bytes: 7844
N, Q = map(int, input().split())
AC = [None] * N
flag_A = False
cnt = 0
for i, s in enumerate(input()):
    AC[i] = cnt
    if flag_A:
        if s == 'C':
            cnt += 1
            AC[i] = cnt
        flag_A = False

    if s == 'A':
        flag_A = True

for q in range(Q):
    l, r = map(int, input().split())
    print(AC[r-1] - AC[l-1])


Measured memory_bytes: 6028
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 1 * 1e6 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
int v[1005];
ll POW(ll a,ll b){
    ll ans = 1;
    while(b){
        if(b & 1)
            ans = (ans % mod * a % mod) % mod;
        b >>= 1;
        a = (a % mod * a % mod) % mod;
    }
    return ans;
}
int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    fast;
    string s;
    cin >> s;
    int i = 0,j = sz(s) - 1;
    int idx = -1,id = -1;
    fore(i,0,sz(s))
        if(s[i] == 'A'){
            idx = i + 1;
            break;
        }
    for(int i = sz(s) - 1; i >= 0; i--)
        if(s[i] == 'Z'){
            id = i + 1;
            break;
        }
    cout << id - idx + 1 << '\n';
    return 0;   
}

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T>
vector<vector<T> > make_v(size_t a,size_t b){
  return vector<vector<T> >(a,make_v<T>(b));
}
template<typename T>
vector<vector<vector<T> > > make_v(size_t a,size_t b,size_t c){
  return vector<vector<vector<T> > > (a,make_v<T>(b,c));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<double> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];

  const double INF = 1e18;
  auto dp=make_v<double>(n+1,m+1);
  fill_v(dp,-INF);
  dp[0][0]=0;
  for(Int i=0;i<n;i++){
    for(Int j=0;j<m;j++){
      double sum=0;
      for(Int k=1;i+k<=n;k++){
	sum+=a[i+k-1];
	chmax(dp[i+k][j+1],dp[i][j]+sum/k);
      }
    }
  }
  
  cout<<dp[n][m]<<endl;
  return 0;
}



Measured memory_bytes: 5108
from fractions import gcd
from functools import reduce

N, M = map(int,input().split())
a = list(map(int,input().split()))
a = [x // 2 for x in a]

def solve(p, q):
    g = gcd(p, q)
    p //= g
    q //= g
    if (p - q) % 2 == 1:
        return 0
    return p * q * g

k = reduce(solve, a)
if k == 0:
    print(0)
else:
    print(M // k - M // (k * 2))

Measured memory_bytes: 16344
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a = inp()
print(a+a**2+a**3)

Measured memory_bytes: 10312
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
ll n,a[N],jc1[N],jc2[N],f[N],f1[N],ans;
int main(){
    scanf("%lld",&n);jc2[n+1]=jc1[0]=1;
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
    for(int i=1;i<N;i++)jc1[i]=jc1[i-1]*i*1ll%mod;
    for(int i=n;i>=1;i--)jc2[i]=jc2[i+1]*i*1ll%mod;
    for(int i=1;i<n;i++)f[i+1]=jc1[i]*jc2[i+2]%mod;f[1]=jc2[2];
    for(int i=2;i<N;i++)f1[i]=(f1[i-1]+f[i])%mod;
    for(int i=0;i<n;i++)ans=(ans+(f1[i+1]+f1[n-i]+f[1])*a[i])%mod;
   	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define pb push_back
#define mp make_pair
#define err(x) cout<<#x<<"= "<<x<<endl;
#define rep(i,n) for(int i =0; i< n; i++)
#define ff first
#define ss second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define SIZE 100010

struct Person{
	ll a,b,c;
	
	bool operator <(const Person& q) const
	{
		return a-c > q.a-q.c;
	}
}p[SIZE];

struct Id{
	int a;

	bool operator >(const Id& b)const
	{
		return p[a].a-p[a].b > p[b.a].a- p[b.a].b;
	}
}id[SIZE];

struct Id1{
	int a;

	bool operator >(const Id1& b) const
	{
		return p[a].c-p[a].b > p[b.a].c- p[b.a].b;
	}
}id1[SIZE];


int main()
{
	ios::sync_with_stdio(false);
	
	ll totb = 0,ans=0,x,y,z;
	cin>>x>>y>>z;
	
	rep(i,x+y+z)
	{
		cin >> p[i].a >> p[i].b >> p[i].c;
		id[i].a = i;
		id1[i].a = i;
		totb += p[i].b;
	}
	
	sort(p, p+x+y+z);

	rep(i,x+y+z){
//		cerr<<p[i].a<<' ' <<p[i].b<<' '<<p[i].c<<endl;
	}
	ll pre[SIZE]={0}, suf[SIZE]={0};
	priority_queue<Id,vector<Id> ,greater<Id> > preq;
	priority_queue<Id1,vector<Id1> , greater<Id1> > sufq;
	rep(i,x)
	{
		pre[i+1] = pre[i]+p[i].a - p[i].b;
		preq.push(id[i]);
//		cerr<<pre[i+1]<<' ';
	}

	for(int i = x; i<x+y; i++)
	{
		int now = preq.top().a;
		Person now1= p[now];
		if(now1.a- now1.b< p[i].a-p[i].b)
		{
			preq.pop();
			preq.push(id[i]);
			pre[i+1] = pre[i] + p[i].a-p[i].b + now1.b - now1.a;
		}
		else
		{
			pre[i+1] = pre[i];
		}
//		cerr<<pre[i+1]<<' ';
	}
//	cout<<endl;
	for(int i = x+y+z-1 ; i>x+y-1; i--)
	{
		suf[i-1] = suf[i] + p[i].c - p[i].b;  
		sufq.push(id1[i]);
	//	cerr<<suf[i-1]<<' ';
	}

	for(int i = x+y-1; i>x-1; i--)
	{
		int now = sufq.top().a;
		Person now1= p[now];
		if(now1.c- now1.b< p[i].c-p[i].b)
		{
			sufq.pop();
			sufq.push(id1[i]);
			suf[i-1] = suf[i] + p[i].c-p[i].b + now1.b - now1.c;
		}
		else
		{
			suf[i-1] = suf[i];
		}
//		cerr<<suf[i-1]<<' ';
	}
//	cerr<<endl;
	for(int i = x; i <=x+y ; i++){
		ans = max(totb+pre[i]+suf[i-1],ans);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5628
//解説のコピペ
#include <bits/stdc++.h>

using namespace std;

int main() {
    int N, D; cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < D; ++j) {
        cin >> X[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            int norm = 0;
            for (int k = 0; k < D; ++k) {
                int diff = abs(X[i][k] - X[j][k]);
                norm += diff * diff;
            }
            // check whether norm = k for some k
            bool flag = false;
            for (int k = 0; k <= norm; ++k) {
                if (k * k == norm) {
                flag = true;
                }
            }
            if (flag) ++ans;
        }
    }
    cout << ans << endl;
}

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

signed main(){
   int a;
   cin>>a;
   for(int b=0;b<a;b++){
       int c,d;cin>>c>>d;
       int i=0;
       for(;c!=d;i++){
	   for(int j=1;;j<<=1){
	       if(j>d-c||c%j!=0){c+=j/2;break;}
	       }
	   }
	   cout<<i<<endl;
       }
    }

Measured memory_bytes: 3048
import sys
def input(): return sys.stdin.readline().rstrip()
class Sieve: #区間[2,n]の値の素因数分解 O(nloglogn+logn)
    def __init__(self,n): #nは計算対象としてありうる最大の値
        self.primes=[]
        self.f=[0]*(n+1) #ふるい（素数ならその値）
        self.f[0]=self.f[1]=-1
        self.f_lis = [0]*(n+1)
        for i in range(2,n+1): #素数リスト作成
            if self.f[i]: continue
            self.primes.append(i)
            self.f[i]=i
            for j in range(i*i,n+1,i):
                if not self.f[j]:
                    self.f[j]=i  #最小の素因数を代入
    def prime_fact(self,A): #素因数分解 {2:p,3:q,5:r,...}
        for x in A:
            while x!=1:
                p=self.f[x]
                x//=p
                if x % p > 0:
                    if self.f_lis[p] > 0: return False
                    self.f_lis[p] += 1
        return True

import math
from functools import reduce
def gcd_all(numbers):#gcd(A)
    return reduce(math.gcd, numbers)

def main():
    n = int(input())
    A = list(map(int,input().split())) 
    Sieve_a = Sieve(max(A)+1)
    if Sieve_a.prime_fact(A):
        print("pairwise coprime")
    elif gcd_all(A) == 1:
        
        print("setwise coprime")   
    else:
        print("not coprime")

if __name__=='__main__':
    main()

Measured memory_bytes: 127188
// ACM-ICPCà\I2007 B. OC/OAEgL^ÌðÍ

#include <iostream>
#include <vector>

using namespace std;

int main(){
	int n, m;
	while(cin >> n >> m, n){
		cin >> n;
		vector <int> count(m, 0);
		vector < vector< pair<int,int> > > rec(m);
		int t, p, s;
		for(int i=0;i<n;i++){
			cin >> t >> p >> p >> s;
			p--;
			if(s == 1){
				if(count[p] == 0)
					rec[p].push_back(make_pair(t,t));
				count[p]++;
			} else {
				count[p]--;
				if(count[p] == 0)
					rec[p].back().second = t;
			}
		}
		cin >> n;
		for(int i=0;i<n;i++){
			int ans = 0;
			cin >> s >> t >> p;
			p--;
			for(int j=0;j<rec[p].size();j++){
				ans += max(0, min(t, rec[p][j].second) - max(s, rec[p][j].first));
			}
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 0