akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
#define int long long

template< typename Monoid, typename OperatorMonoid = Monoid >
struct LazySegmentTree
{
  using F = function< Monoid(Monoid, Monoid) >;
  using G = function< Monoid(Monoid, OperatorMonoid) >;
  using H = function< OperatorMonoid(OperatorMonoid, OperatorMonoid) >;
  using P = function< OperatorMonoid(OperatorMonoid, int) >;

  int sz;
  vector< Monoid > data;
  vector< OperatorMonoid > lazy;
  const F f;
  const G g;
  const H h;
  const P p;
  const Monoid M1;
  const OperatorMonoid OM0;


  LazySegmentTree(int n, const F f, const G g, const H h, const P p,
                  const Monoid &M1, const OperatorMonoid OM0)
      : f(f), g(g), h(h), p(p), M1(M1), OM0(OM0)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    data.assign(2 * sz, M1);
    lazy.assign(2 * sz, OM0);
  }

  void set(int k, const Monoid &x)
  {
    data[k + sz] = x;
  }

  void build()
  {
    for(int k = sz - 1; k > 0; k--) {
      data[k] = f(data[2 * k + 0], data[2 * k + 1]);
    }
  }

  void propagate(int k, int len)
  {
    if(lazy[k] != OM0) {
      if(k < sz) {
        lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
        lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
      }
      data[k] = g(data[k], p(lazy[k], len));
      lazy[k] = OM0;
    }
  }

  Monoid update(int a, int b, const OperatorMonoid &x, int k, int l, int r)
  {
    propagate(k, r - l);
    if(r <= a || b <= l) {
      return data[k];
    } else if(a <= l && r <= b) {
      lazy[k] = h(lazy[k], x);
      propagate(k, r - l);
      return data[k];
    } else {
      return data[k] = f(update(a, b, x, 2 * k + 0, l, (l + r) >> 1),
                         update(a, b, x, 2 * k + 1, (l + r) >> 1, r));
    }
  }

  Monoid update(int a, int b, const OperatorMonoid &x)
  {
    return update(a, b, x, 1, 0, sz);
  }


  Monoid query(int a, int b, int k, int l, int r)
  {
    propagate(k, r - l);
    if(r <= a || b <= l) {
      return M1;
    } else if(a <= l && r <= b) {
      return data[k];
    } else {
      return f(query(a, b, 2 * k + 0, l, (l + r) >> 1),
               query(a, b, 2 * k + 1, (l + r) >> 1, r));
    }
  }

  Monoid query(int a, int b)
  {
    return query(a, b, 1, 0, sz);
  }

  Monoid operator[](const int &k)
  {
    return query(k, k + 1);
  }
};

signed main() {
    int n, m;
    cin >> n >> m;
    vector <int> p(m), a(n - 1), b(n - 1), c(n - 1);
    auto F = [](int a, int b) { return a + b; };
    auto P = [](int a, int b) { return a * b; };
    LazySegmentTree <int> seg(n - 1, F, F, F, P, 0, 0);
    rep (i, m) cin >> p[i];

    rep (i, m - 1) {
        int from = p[i], to = p[i + 1];
        if (from > to) swap(from, to);
        from--, to--;
        seg.update(from, to, 1);
    }
    rep (i, n - 1) cin >> a[i] >> b[i] >> c[i];

    int ans = 0;
    rep (i, n - 1) {
        int num = seg.query(i, i + 1);
        if (num == 0) continue;
        if (b[i] * num + c[i] > a[i] * num) ans += a[i] * num;
        else ans += b[i] * num + c[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9972
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	
	vector<int> problems(n + 1, 0);
	vector<bool> isAccepted(n + 1, false);

	for (int i = 0; i < m; i++) {
		int problem;
		string status;
		cin >> problem >> status;

		if (isAccepted[problem]) continue;
		else {
			if (status == "AC") isAccepted[problem] = true;
			else problems[problem]++;
		}
	}

	int acc = 0;
	int penalties = 0;

	for (int i = 1; i <= n; i++) {
		if (isAccepted[i]) {
			acc++;
			penalties += problems[i];
		}
	}

	cout << acc << " " << penalties;
}


Measured memory_bytes: 640
Var     n,min,max: Longint;
        a: Array[0..1005] Of Longint;

Procedure       Nhap;
Var     i: Longint;
Begin
Readln(n);
For i:=1 to n do
        Read(A[i]);
End;

Procedure       Xuly;
Var     i: Longint;
Begin
min:=1000;
max:=0;
For i:=1 to n do
        Begin
        If a[i]>max Then max:=a[i];
        If a[i]<min Then min:=a[i];
        End;
End;

Procedure       Xuat;
Begin
Writeln(max-min);
End;

Begin
Nhap;
XuLy;
Xuat;
End.


Measured memory_bytes: 128
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    H = LI()

    pre = -999
    flag = True
    for h in H:
        if pre <= h - 1:
            pre = h - 1
        elif pre <= h:
            pre = h
        else:
            flag = False
            break

    print('Yes' if flag else 'No')

if __name__ == '__main__':
    solve()


Measured memory_bytes: 14836
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    int a,b,k,i,small;
    vector<int> ar;
    cin>>a>>b>>k;
    if(a>b)
    small=b;
    else
    small=a;
    for(i=small;i>0;i--)
        if(a%i==0 && b%i==0){
            ar.push_back(i);
            
        }
    cout<<ar[k-1];
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli n,k;
vll w;
priority_queue<lli,vector<lli>,greater<lli> > q;
lli ans;

int judge(lli m){
    lli t = 0;
    lli ret = 1;
    for(lli i = 0;i < n;i++){
        if(t + w[i] > m){
            ret++;
            t = w[i];
        }else{
            t += w[i];
        }
    }
    return ret;
}

int main(){
    cin >> n >> k;
    w = vll(n);
    for(lli i = 0;i < n;i++) cin >> w[i];
    lli h = 1000000000,l = *max_element(w.begin(),w.end()),m;
    while(h > l){
        m = (h+l) / 2;
        if(judge(m) > k) l = m+1;
        else h = m;
    }
    cout << h << endl;
    return 0;
}

Measured memory_bytes: 3588
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
int INF = INT_MAX / 2;
double EPS = 1e-10;

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

int main() {
	int N, M; cin >> N >> M;
	vector<int> K(N);
	vector<vector<int> > S(N), H(N);
	for (int i = 0; i < N; i++) {
		cin >> K[i];
		for (int k = 0; k < K[i]; k++) {
			int s, h; cin >> s >> h;
			S[i].push_back(s);
			H[i].push_back(h);
		}
	}
	double maxi = 0;
	for (int t = 0; t < N; t++) {
		vector<int> dp(M + 1, -INF);
		dp[M] = 0;
		for (int i = 0; i < N - 1; i++) {
			vector<int> _dp = dp;
			for (int j = 0; j <= M; j++) {
				int h = 0, v = 0;
				for (int k = 0; k < K[i]; k++) {
					h += H[i][k];
					v += S[i][k] * H[i][k];
					if (v > j) break;
					_dp[j - v] = max(_dp[j - v], dp[j] + h);
				}
			}
			dp = _dp;
		}
		for (int j = 0; j <= M; j++) {
			double h = dp[j], v = j;
			for (int k = 0; k < K[N - 1]; k++) {
				double dh = min((double)H[N - 1][k], v / S[N - 1][k]);
				h += dh; v -= S[N - 1][k] * dh;
			}
			maxi = max(maxi, h);
		}
		rotate(K.begin(), K.begin() + 1, K.end());
		rotate(S.begin(), S.begin() + 1, S.end());
		rotate(H.begin(), H.begin() + 1, H.end());
	}
	printf("%.20f\n", maxi);
}

Measured memory_bytes: 1272
#include<stdio.h>
#include<math.h>
int main()
{
	int X,t,s;
	scanf("%d %d",&X,&t);
	if(X>t)
	{
		s=X-t;
		printf("%d",s);
	}
	else
	{
		s=0;
		printf("%d",s);
	}
	return 0;
}
 

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String value = String.valueOf(sc.next());
		String[] val = new String[value.length()];
		int sum=0;

		for (int i = 0; i < value.length(); i++) {
			val[i] = String.valueOf(value.charAt(i));
			sum += Integer.parseInt(val[i]);
		}

		if(Integer.parseInt(value)%sum==0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
#define lowbit(x) ((x)&-(x))
#define rep(i,l,r) for(res i=l,_r=r;i<=_r;++i)
#define per(i,r,l) for(res i=r,_l=l;i>=_l;--i)
#define mkp make_pair
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem0n(a,n) memset(a,0,n*sizeof(a[0]))
#define iter(x,v) for(res v,_p=head[x];v=ver[_p],_p;_p=nxt[_p])
#ifdef cccgift //by lqh
#define SHOW(x) cerr<<#x"="<<(x)<<endl
#else
#define SHOW(x) 0
#endif
//#define getchar()(ip1==ip2&&(ip2=(ip1=ibuf)+fread(ibuf,1,1<<21,stdin),ip1==ip2)?EOF:*ip1++)
//char ibuf[1<<21],*ip1=ibuf,*ip2=ibuf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
struct node{
	ll d[64];
	void clear() {mem0(d);}
	void ins(ll x) {
		per(i,62,0)
		  if((x>>i)&1) {
		  	if(d[i]) x^=d[i];
		  	else {d[i]=x;break;}
		  }
	}
	bool check(ll x) {
		per(i,62,0)
		  if((x>>i)&1) {
		  	if(d[i]) x^=d[i];
		  	else return false;
		  }
		return true;
	}
} t0;
int t,n;
ll a[201];
char s[201];
int main()
{
	read(t);
	while(t--) {
		t0.clear(),read(n);
		rep(i,1,n) read(a[i]);scanf("%s",s+1);
		if(s[n]=='1') {puts("1");continue;}
		bool flag=false;
		per(i,n,1) if(s[i]=='0') t0.ins(a[i]);
		else if(!t0.check(a[i])) {flag=true;break;}
		puts(flag?"1":"0");
	}
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e9
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int,int> P;
struct edge{int to,cost;};

int d[3600],w,h,c[4],dx[]={1,0,-1,0},dy[]={0,-1,0,1},dd[]={0,3,2,1};
int m[30][30];
vector<edge> g[3600];

void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > q;
	fill(d,d+4*h*w,INF);
	d[s]=0;
	q.push(P(0,s));
	while(!q.empty()){
		P p=q.top();q.pop();
		int v=p.second;
		if(d[v]<p.first)continue;
		rep(i,g[v].size()){
			edge e=g[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				q.push(P(d[e.to],e.to));
			}
		}
	}
}

int main(){
	while(cin>>w>>h&&w){
		rep(i,4*h*w)g[i].clear();
		rep(i,h)rep(j,w)cin>>m[i][j];
		rep(i,4)cin>>c[i];
		rep(i,h)rep(j,w)rep(k,4)rep(l,5){
			edge e;
			int nk;
			if(l<4||m[i][j]<4){
				if(l<4)nk=(k+dd[l])%4;
				else nk=(k+dd[m[i][j]])%4;
				int nx=j+dx[nk],ny=i+dy[nk];
				if(nx>=0&&nx<w&&ny>=0&&ny<h){
					e.to=nk*h*w+ny*w+nx;
					if(l<4)e.cost=c[l];
					else e.cost=0;
					g[k*h*w+i*w+j].push_back(e);
				}
			}
		}
		dijkstra(0);
		int ans=INF;
		rep(i,4)ans=min(ans,d[(i+1)*h*w-1]);
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1288
/****************************************

	LostMartian

****************************************/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <numeric>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;
typedef long long ll;
#define rep(i,m,n) for(ll i=m; i<n; i++)
#define repr(i,m,n) for(ll i=m; i>=n; i--)
#define vll vector<ll >
#define vvl vector<vector<ll > >
#define pi pair<ll, ll >
#define pb push_back
#define mk make_pair
#define sz size()
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define d(x) cout<<"Value of "#x" = "<<x<<"\n";
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define LOCAL #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
	clock_t z = clock();
	FAST
	//LOCAL
	ll aa, b, c;
	cin>>aa>>b>>c;
	ll a[8];
	a[5]=0; a[7]=0;
	a[aa]++; a[b]++; a[c]++;
	if(a[5]==2 && a[7]==1) {
		cout<<"YES\n";
	}
	else  {
		cout<<"NO\n";
	}
	

	debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define re(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007;
int n;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n,k;
    cin>>n>>k;
    int c=max({n+k,n-k,n*k});
    cout<<c<<endl;
}

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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 dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};


int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    vector<string> s(n); rep(i,n) cin>>s[i];

    using P = pair<ll,ll>;
    vector<P> X(n);
    vector<P> pl,mi;


    rep(i,n){
        ll minval,tot;
        minval = 0;
        tot = 0;
        for(auto c:s[i]){
            if(c == '(') tot++;
            else tot--;
            chmin(minval,tot);
        }
        X[i] = mp(minval, tot);
        if(tot>=0) pl.emplace_back(minval,tot);
        else mi.emplace_back(minval,tot);
    }

    // sort(ALL(X), greater<P>());
    sort(ALL(pl), greater<P>());
    sort(ALL(mi), [](P a, P b){return a.second - a.first > b.second - b.first;});
    // sort(ALL(mi));

    // for(auto p: X)cout<<p.first<<" "<<p.second<<endl;
    ll now = 0;
    // minが大きい順
    for(auto p:pl){
        if(now + p.first < 0){
            cout<<"No"<<endl;
            return 0;
        }
        now += p.second;
    }

    // minが大きい順
    for(auto p:mi){
        if(now + p.first < 0){
            cout<<"No"<<endl;
            return 0;
        }
        now += p.second;
    }

    if(now == 0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;

}


Measured memory_bytes: 65924
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

map<ll,ll> mp;

void prime_factor(ll n){
    for(ll i=2;i<=n;i++){
        ll u=i;
        for(ll j=2;j*j<=u;j++){
            while(u%j==0){
                ++mp[j];
                u/=j;
            }
        }
        if(u!=1) mp[u]++;
    }
    ll ans=1;
    for(auto v:mp) ans=ans*(v.sc+1)%mod;
    cout<<ans<<endl;
}

signed main(){
    ll n;
    cin>>n;
    prime_factor(n);
}

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

const int MAX=50;
long long dp[100][2]; //dp[桁数][上限ギリギリかどうか]

int main(){
    memset(dp,-1,sizeof(dp));
    dp[0][0]=0;
    long long N,K; cin >> N >> K;
    long long a[N];
    for(int i=0;i<N;i++) cin >> a[i];
    for(int d=0;d<MAX;d++){
        long long mask=1LL<<(MAX-d-1);
        int num=0; //ビットが立っているものの本数
        for(int i=0;i<N;i++){
            if(mask&a[i]) num++;
        }
        long long cost0,cost1; //d桁目を0,1にした時のコスト
        cost0=num*mask;
        cost1=(N-num)*mask;
        
        if(dp[d][1]!=-1){
            dp[d+1][1]=max(dp[d+1][1],dp[d][1]+max(cost0,cost1));
        }
        if(dp[d][0]!=-1){
            if(K&mask){
                dp[d+1][1]=max(dp[d+1][1],dp[d][0]+cost0);
            }
        }
        if(dp[d][0]!=-1){
            if(K&mask) dp[d+1][0]=max(dp[d+1][0],dp[d][0]+cost1);
            else dp[d+1][0]=max(dp[d+1][0],dp[d][0]+cost0);
        }
    }
    cout << max(dp[MAX][0],dp[MAX][1]) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int w, q;
        cin >> w >> q;
        if(w == 0)
            return 0;

        vector<int> wall(w, -1);
        for(int i=0; i<q; ++i){
            char c;
            int id;
            cin >> c >> id;
            if(c == 's'){
                int size;
                cin >> size;
                bool ok = false;
                for(int i=0; i<w-size+1; ++i){
                    int j;
                    for(j=0; j<size; ++j){
                        if(wall[i+j] != -1){
                            i += j;
                            break;
                        }
                    }
                    if(j == size){
                        for(j=0; j<size; ++j)
                            wall[i+j] = id;
                        cout << i << endl;
                        ok = true;
                        break;
                    }
                }
                if(!ok)
                    cout << "impossible" << endl;
            }else{
                for(int i=0; i<w; ++i){
                    if(wall[i] == id)
                        wall[i] = -1;
                }
            }
        }

        cout << "END" << endl;
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

vector<vector<ll>> adj;
vector<ll> maxdeg;

ll dfs(ll pos, ll par, ll dpt, P cent) {
	ll sum=0;
	ll ret=dpt;
	REP(i,(ll)adj[pos].size()) {
		if(adj[pos][i]==par) continue;
		if(adj[pos][i]==cent.first||adj[pos][i]==cent.second) continue;
		sum++;
		ret=max(ret,dfs(adj[pos][i],pos,dpt+1,cent));
	}
	maxdeg[dpt]=max(maxdeg[dpt],sum);
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	adj.resize(n);
	maxdeg.resize(n+10,0);
	REP(i,n-1) {
		ll a,b;
		cin>>a>>b;
		a--;
		b--;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	ll wf[n+1][n][n];
	REP(i,n+1) REP(j,n) REP(k,n) wf[i][j][k]=INF;
	REP(i,n) wf[0][i][i]=0;
	REP(i,n) {
		REP(j,(ll)adj[i].size()) {
			wf[0][i][adj[i][j]]=1;
		}
	}
	FOR(i,1,n+1) {
		REP(j,n) {
			REP(k,n) {
				wf[i][j][k]=min(wf[i-1][j][k],wf[i-1][j][i-1]+wf[i-1][i-1][k]);
			}
		}
	}
	P cent=P(-1,-1);
	ll mincost=INF;
	REP(i,n) {
		ll buf=0;
		REP(j,n) buf=max(buf,wf[n][i][j]);
		if(buf<mincost) mincost=buf;
	}
	REP(i,n) {
		ll buf=0;
		REP(j,n) buf=max(buf,wf[n][i][j]);
		if(buf==mincost) {
			if(cent.first==-1) cent.first=i;
			else cent.second=i;
		}
	}
	ll ans1=INF;
	ll ans2=INF;
	REP(piyo,(ll)adj[cent.first].size()) {
		ll i=adj[cent.first][piyo];
		if(cent.second!=-1&&i!=cent.second) continue;
		REP(j,n) maxdeg[j]=0;
		dfs(cent.first,-1,0,P(cent.first,i));
		if(dfs(i,-1,0,P(cent.first,i))>mincost) continue;
		ll buf=0;
		REP(j,n) buf=max(buf,min(wf[n][j][cent.first],wf[n][j][i]));
		if(buf+1<=ans1) {
			ans1=buf+1;
			ll hoge=1;
			REP(j,n+10) {
				if(maxdeg[j]==0) break;
				else hoge*=maxdeg[j];
				//cout<<i<<" "<<ans<<endl;
			}
			if(i!=cent.first) hoge*=2;
			if(hoge==1) cout<<i<<endl;
			ans2=min(ans2,hoge);
		}
	}
	while(1) {
	ll i=cent.first;
	if(cent.second!=-1&&i!=cent.second) break;
	REP(j,n) maxdeg[j]=0;
	dfs(cent.first,-1,0,P(cent.first,i));
	if(dfs(i,-1,0,P(cent.first,i))>mincost) break;
	ll buf=0;
	REP(j,n) buf=max(buf,min(wf[n][j][cent.first],wf[n][j][i]));
	if(buf+1<=ans1) {
		ans1=buf+1;
		ll hoge=1;
		REP(j,n+10) {
			if(maxdeg[j]==0) break;
			else hoge*=maxdeg[j];
			//cout<<i<<" "<<ans<<endl;
		}
		if(i!=cent.first) hoge*=2;
		if(hoge==1) cout<<i<<endl;
		ans2=min(ans2,hoge);
	}
	break;
	}
	cout<<ans1<<" "<<ans2<<endl;
}


Measured memory_bytes: 8192
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,K = map(int,readline().split())
A = np.array(readline().split(),np.int64)
F = np.array(readline().split(),np.int64)

A.sort(); F.sort(); F=F[::-1]

def test(x):
    # 全員がx秒以下に収めるための必要コストがK以下である
    return np.maximum(0,A-x//F).sum() <= K

left = -1 # 不可能目標
right = 10**13 # 可能目標
while left+1 < right:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

answer = right
print(answer)

Measured memory_bytes: 26200
a,b,m = map(int,input().split())
ref = list(map(int,input().split()))
ran = list(map(int,input().split()))

ans = min(ref) + min(ran)

for i in range(m):
  t = list(map(int,input().split()))
  p = t[0] 
  q = t[1]
  c = t[2]
  if (len(ref) >= p and len(ran) >= q):
    if ref[p - 1] + ran[q - 1] - c < ans:
      ans = ref[p - 1] + ran[q - 1] - c
      
print(ans)

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


const int MOD = (int)1e9 + 7;

/**
* Binary_Indexed_Tree(BIT) 2d by mod
* Fenwick Tree
* 0-indexed!!!
* O((log N)(log M))
*/
template<int mod>
class binary_indexed_tree_2d_by_mod {
private:
    int N;
    int M;
    std::vector<std::vector<int>> bit;

    void add(int &a, int b) {
        if (b < 0) b += mod;
        a += b;
        if (a >= mod) a -= mod;
    }

public:
    binary_indexed_tree_2d_by_mod() {}
    binary_indexed_tree_2d_by_mod(int n, int m) : N(n), M(m), bit(n, std::vector<int>(m)) {}

    void add(int x, int y, long long val) {
        // for mod calc
        val %= mod;
        // for 0-indexed
        x++; y++;

        for (int i = x; i <= N; i += i & (-i)) {
            for (int j = y; j <= M; j += j & (-j)) {
                this->add(this->bit[i - 1][j - 1], val);
            }
        }
    }

    int sum(int x, int y) {
        int res = 0;
        // for 0-indexed
        x++; y++;

        for (int i = x; i > 0; i -= i & (-i)) {
            for (int j = y; j > 0; j -= j & (-j)) {
                this->add(res, this->bit[i - 1][j - 1]);
            }
        }
        return res;
    }

    int sum(int x1, int y1, int x2, int y2) {

        int res = this->sum(x2, y2);
        add(res, -sum(x1 - 1, y2));
        add(res, -sum(x2, y1 - 1));
        add(res, sum(x1 - 1, y1 - 1));

        return res;
    }
};

const int MAX = 2e3 + 10;
int N, M;
binary_indexed_tree_2d_by_mod<MOD> bit;

int main(void) {
    std::cin >> N >> M;
    std::vector<int> S(N);
    for (int i = 0; i < N; i++) {
        std::cin >> S[i];
    }
    std::vector<int> T(M);
    for (int i = 0; i < M; i++) {
        std::cin >> T[i];
    }
    bit = binary_indexed_tree_2d_by_mod<MOD>(N + 1, M + 1);

    bit.add(0, 0, 1);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (S[i] == T[j]) {
                bit.add(i + 1, j + 1, bit.sum(i, j));
            }
        }
    }

    std::cout << bit.sum(N, M) << std::endl;
}


Measured memory_bytes: 17152
import collections
import sys

readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    A = collections.Counter(A)

    cnt = 0
    for a in A:
        if A[a] < a:
            cnt += A[a]
        elif A[a] > a:
            cnt += A[a] - a

    print(cnt)


main()


Measured memory_bytes: 18332
a0 = int(input())
an = [a0]
def f(n):
        if n%2 == 0:
                return n/2
        else:
                return 3*n + 1
frag = 0
while frag == 0:
        an.append(f(an[-1]))
        for i in range(len(an)-1):
                if an[-1] == an[i]:
                        frag = 1
print(len(an))

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

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

    int ans = 0;

    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if(500 * i + 100 * j + 50 * k == x){
                    ans++;
                }
            }

        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace std;
#define ll long long int
#define ld long double
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> in_set;
#define rep(n) for(ll i=0;i<(n);i++)
#define jrep(n) for(ll j=0;j<(n);j++)
#define krep(n) for(ll k=0;k<(n);k++)
#define all(a) (a).begin(), (a).end()
#define dpp(a) cout<<(a).first<<" "<<(a).second<<endl;
#define append push_back
#define mod 1000000007
#define ff first
#define ss second
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fast ios::sync_with_stdio(0);
ll pw(ll x,ll y,ll p=mod){ll r=1; x=x%p;while(y>0){ if(y&1)r=(r*x)%p;
y=y>>1;x=(x*x)%p;} return r; } vector<ll> uniq(vector<ll> arr)
{vector<ll>brr;sort(all(arr));brr.append(arr[0]);
for(auto i:arr)if(brr.back()!=i)brr.append(i);return brr;}

ll n; vector<ll> arr; 
set<ll> vis;
ll noddm[200005]; ll nevenm[200005];
vector<ll> graph[200005];
void solve(ll ts){
    ll n,x,t; cin>>n>>x>>t;
    cout<<t*((n+x-1)/x)<<endl;
}
 
int main(){
    ffast
    ll t=1;
//    cin>>t;
    rep(t) solve(i+1);
}
 
 
// *p.find_by_order(n) : nth value (0 indexed)
// p.order_of_key(7): index of 7 (0 indexed)


Measured memory_bytes: 8332
#include <iostream>

using namespace std;

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

    int count = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (500*i + 100*j + 50*k == x) count++;
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>

//エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};


int main(){
    Stream io;

    int H, W, K;
    io.read(H, W, K);
    auto c = io.read_vec<string>(H);

    int bitH = (1 << H);
    int bitW = (1 << W);

    int ans = 0;
    for(int y = 0; y < bitH; y++){
        for(int x = 0; x < bitW; x++){
            int sum = 0;
            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    if(((y >> i) & 1) || ((x >> j) & 1) || c[i][j] == '.'){
                        continue;
                    }
                    sum++;
                }
            }
            if(sum == K) ans++;
        }
    }
    cout << ans;
    return 0;
}


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

int main() {
  int h, w;
  cin >> h >> w;

  vector<vector<char>> A(h, vector<char>(w));
  int total = 0;
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      cin >> A[i][j];
      if(A[i][j] == '#') total++;
    }
  }
  int expected = h + w - 1;

  if(total == expected) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 10;
char S[N], T[N];
int main()
{
 // freopen("input.txt", "r", stdin);
  cin >> S >> T;
  int len_s = strlen(S), len_t = strlen(T);
  int Max = 0;
  for (int i = 0; i <= len_s - len_t; i++)
  {

    int temp = i;
    int sum = 0;
    for (int j = 0; j < len_t; j++)
    {
      if (S[temp + j] == T[j])
        sum++;
    }
    Max = max(Max, sum);
  }
  printf("%d\n", len_t - Max);
  return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

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

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

const ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  int A, B, C; cin >> A >> B >> C;
  if (A == B && C != A) cout << "Yes" << endl;
  else if (A == C && B != A) cout << "Yes" << endl;
  else if(B == C && A != B) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

using namespace std;

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0;i < n - 1;i++) cin >> a[i];

    for (int i = 0;i < n - 1;i++)
    {
        b[a[i] - 1]++;
    }


    for (int i = 0;i < n;i++) cout << b[i] << endl;
    
    return 0;
}


Measured memory_bytes: 4844
#include <stdio.h>
//#include <stdlib.h>
#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  char s[15], t[15], u[15];
  int a, b;
  scanf("%s %s", s, t);
  scanf("%d%d", &a, &b);
  scanf("%s", u);
  if (strcmp(t, u)) a--;
  else b--;
  printf("%d %d\n", a, b);
  return 0;
}


Measured memory_bytes: 128
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

if N > 1:
	ans = gcd(abs(x[0] - X), abs(x[1] - X))
	for i in range(2, len(x)):
		ans = gcd(ans, abs(x[i] - X))
else:
	ans = abs(x[0] - X)

print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


int main(){
    string s;
    int k;
    cin >> k >> s;
    if(s.size() <= k){
        cout << s << endl;
        return 0;
    }else{
        string ans;
        ans = s.substr(0, k);
        ans += "...";
        cout << ans << endl;
        return 0;
    }
	return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int const mod=998244353;
int const maxn=1e5+5;
int dis[maxn];
typedef long long ll;
ll quick(ll x,ll y)
{
    ll ans=1;
    while(y)
    {

        if(y&1)
        {

            ans*=x;ans%=mod;
        }
        x*=x;x%=mod;y>>=1;
    }
    return ans;
}
int main(){
    int n;
    bool rc=0;int maxr=0;
    scanf("%d",&n);int x;
    for(int i=1;i<=n;i++) {
        scanf("%d",&x);
        if((i==1&&x!=0)||(i!=1&&x==0)) rc=1;
        dis[x]++;
        maxr=max(maxr,x);
    }
    long long res=1;long long tmp=1;
    if(dis[0]!=1) rc=1;
    //cout<<rc<<endl;
    for(int i=1;i<=maxr;i++)
    {
        if(dis[i]==0)
        {
            rc=1;break;
        }
        else{
            res=res*quick(tmp,dis[i])%mod;
            tmp=dis[i];
        }
    }
    if(rc) printf("0\n");
    else{
        printf("%lld\n",res);
    }

}


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

int main() {
    
    while(1) {
        int a, b;
        char op;
        cin>>a>>op>>b;
        if(op == '?') break;
        else if(op == '+') cout<<a + b<<endl;
        else if(op == '-') cout<<a - b<<endl;
        else if(op == '*') cout<<a * b<<endl;
        else if(op == '/') cout<<a / b<<endl;
    }
    
    return 0;
}


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

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

    uint32_t min = UINT32_MAX;
    for (auto a = 1; a < n; a++) {
        int sum = 0, tmp_a = a, tmp_b = n - a;
        while(tmp_a > 0 || tmp_b > 0) {
            sum += tmp_a % 10 + tmp_b % 10;
            tmp_a /= 10;
            tmp_b /= 10;
        }
        if(min > sum) min = sum;
    }

    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace Array
{
    class Matrix_Vector_Multiplication
    {
        static void Main(string[] args)
        {
            var size = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            var matrix = new int[size[0]][];
            for (int i = 0; i < matrix.Length; i++)
                matrix[i] = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var vector = new int[size[1]];
            for (int i = 0; i < vector.Length; i++)
                vector[i] = int.Parse(Console.ReadLine());

            var res = new int[size[0]];
            for (int i = 0; i < res.Length; i++)
            {
                for (int j = 0; j < matrix[i].Length; j++)
                {
                    res[i] += matrix[i][j] * vector[j];
                }
            }

            for (int i = 0; i < res.Length; i++)
            {
                Console.WriteLine(res[i]);
            }
        }
    }
}

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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

ll rec(int l,int r,vector<vector<ll>>& dp,vector<ll>& sums) {
    if (dp[l][r]) return dp[l][r];
    ll ret = INT64_MAX;
    if (r-l) {
        for (int i = l;i < r;++i) ret = min(ret,rec(l,i,dp,sums)+rec(i+1,r,dp,sums)+sums[r+1]-sums[l]);
    } else ret = 0;
    return dp[l][r] = ret;
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n),sums(n+1,0);
    vector<vector<ll>> dp(n,vector<ll>(n,0));
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n;++i) sums[i+1] = sums[i]+a[i];
    cout << rec(0,n-1,dp,sums) << endl;
    return 0;
    
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<int,int> P;
typedef struct pair<int,P> P2;

ll d[1001]={};

int main() {
	int n;
	ll a,b;
	string s;
	cin>>a;
	b=(a/11)*2;
	a=a%11;
	if(a==0){
		b+=0;
	}else if(a<7){
		b+=1;
	}else{
		b+=2;
	}

		cout<<b<<endl;
	return 0;
}


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

#define ldb long double
#define ll long long

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> cnt(n + 1);
    
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        cnt[a[i]]++;
    }
    
    ll sum = 0;
    
    for(int i = 1; i <= n; i++)
    {
        sum += cnt[i] * (cnt[i] - 1) / 2;
    }
    
    for(int i = 0; i < n; i++)
    {
        ll temp = sum - cnt[a[i]] * (cnt[a[i]] - 1) / 2;
        temp += (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2;
        
        if(temp > 0)
        {
            cout << temp << "\n";
        }
        else
        {
            cout << 0 << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int ccw(Point a,Point b,Point c)
{
  b=b-a;
  c=c-a;
  if(b%c>0) return +1;
  else if(b%c<0)return -1;
  else if(b*c<0) return +2;
  else if(b.size()<c.size()) return -2;
  else return 0;
}

int w,h;
vector<string> board;
vector<vector<string> > memo;
int dx[]={1,0};
int dy[]={0,1};

inline bool outrange(int x,int y)
{
  return (x<0 || x>=w || y<0 || y>=h);
}

string cmp(string a,string b)
{
  if(a.size()>b.size()) return a;
  if(b.size()>a.size()) return b;
  return max(a,b);
}

string dfs(int x,int y)
{
  if(outrange(x,y)) return "";
  if(!isdigit(board[y][x])) return "";
  if(memo[y][x]!="") return memo[y][x];
  
  string res="";
  for(int d=0;d<2;d++)
    {
      res=cmp(res,board[y][x]+dfs(x+dx[d],y+dy[d]));
    }
  memo[y][x]=res;
  return res;
}

int main(int argc,char const* argv[])
{
  string board[1005];
  int dp[1005][1005];
  int n,ans;
  while(cin >> n && n)
    {
      ans=0;
      memset(dp,0,sizeof(dp));
      for(int i=0;i<n;i++)
	{
	  cin >> board[i];
	}
      for(int i=0;i<n;i++)
	{
	  for(int j=0;j<n;j++)
	    {
	      if(board[i][j]=='*') dp[i][j]=0;
	      else
		{
		  if(i>0 && j>0)
		    {
		      dp[i][j]=min({dp[i-1][j],dp[i][j-1],dp[i-1][j-1]})+1;
		    }
		  else dp[i][j]=1;
		  ans=max(ans,dp[i][j]);
		}
	    }
	}
      cout << ans << endl;
    }
  return 0;
}



Measured memory_bytes: 7924
// Ruby to C++ port. https://atcoder.jp/contests/agc038/submissions/7686919
#include<bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}

int P[200000], Q[200000];

int main()
{
	int N, K;
	read(N); read(K);
	for (int* p = P; p != P+N; ++p) {
		read(*p);
	}

	int pm = 0, n = 2-K;
	int i = 0;
	struct {
		int head, tail;
	} min = {0, 0}, max = {N-1, N-1};
	Q[min.head] = Q[max.head] = i;

	while (++i != N) {
		int p = P[i];

		// assert(0 <= min.head <= min.tail <= max.tail <= max.head < N)
		bool min_gone = Q[min.head] == i-K;
		if (p < P[Q[min.head]]) {
			min.head = min.tail--;
		} else {
			while (p < P[Q[min.tail]]) {
				--min.tail;
			}
			if (Q[min.head] == i-K) {
				++min.head;
			}
		}
		if (P[Q[max.head]] < p) {
			max.head = max.tail++;
		} else {
			while (P[Q[max.tail]] < p) {
				++max.tail;
			}
			if (Q[max.head] == i-K) {
				--max.head;
			}
		}
		Q[++min.tail] = Q[--max.tail] = i;
		bool max_entered = Q[max.head] == i;
		// assert(0 <= min.head <= min.tail <= max.tail <= max.head < N)

		if (min.tail-min.head+1 == K) {
			pm = 1;
		} else if (! min_gone or ! max_entered) {
			n += 1;
		}
	}

	cout << n+pm << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	cout<<fixed<<setprecision(15);
	ld a,b,h,m;
	cin>>a>>b>>h>>m;
	ld pi = acos(-1);
	ld a1 = ((h+ m/60.0)*pi )/6.0;
	ld a2 = m*pi/30.0;
	cout << sqrt(a*a + b*b - 2*a*b*cos(a1-a2)) <<endl; 
}

Measured memory_bytes: 4184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9;
const int inf=0x3f3f3f3f;
ll a[200005];
ll upper=1e18;
int main()
{
   ll n;cin>>n;
   ll out=1;
   for (int i = 0; i < n; i++)
   {
	   cin>>a[i];
	   if(a[i]==0)
		   out=0;
   }
   if (out!=0)
   {
	   for (int i = 0; i < n; i++)
	   {
		   if(a[i]<=upper/out)
			   out*=a[i];
		   else
		   {
			   out=-1;
			   break;
		   }
	   }
   }
   cout<<out<<endl;
   //cout<<ans<<endl;
}

Measured memory_bytes: 4420
<?php
/*
    http://agc006.contest.atcoder.jp/tasks/agc006_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d", $N);
fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $t);

for ($i = $N; $i >= 0; $i--) {
	$ss = substr($s, strlen($s) - $i);
	$tt = substr($t, 0, $i);
	// echo "{$ss} {$tt}\n";
	if ($ss == $tt) {
		echo ($N * 2 - $i) . PHP_EOL;
		exit;
	}
}


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static int[][] map;
	public static int[][] passed;
	public static int[] dx = {0, 1, 1, 1, 0, -1, -1, -1};
	public static int[] dy = {-1, -1, 0, 1, 1, 1, 0, -1};
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			int w = sc.nextInt();
			int h = sc.nextInt();
			if(w == 0) break;
			
			map = new int[h][w];/* 地図の初期化 */
			for(int i = 0 ; i < h; i++)
				for(int j = 0; j < w; j++)
					map[i][j] = sc.nextInt();
			passed = new int[h][w];/* 通った場所の初期化 */
			
			int cnt = 0;
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++) {
					/* 探索したことのない陸地 */
					if(map[i][j] == 1 && passed[i][j] == 0) {
						search(i, j);/* 周囲の島を探索 */
						cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
	}
	
	public static void search(int y, int x) {
		passed[y][x] = 1;/* 無限ループ回避のためここでチェック */

		/* 周囲の陸地探索 */
		for(int i = 0; i < 8; i++) {
			int new_y = y + dy[i];
			int new_x = x + dx[i];
			/* 配列外に出ないように */
			if((0 <= new_y) && (new_y < map.length)
				&& (0 <= new_x) && (new_x < map[0].length)) {
				/* 通ったことのない陸地 */
				if(passed[new_y][new_x] == 0 && map[new_y][new_x] == 1) {
					search(new_y, new_x);
				}
			}
		}
	}
}



Measured memory_bytes: 45596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll a,b,h;
  cin >> a >> b >> h;
  cout << (a+b)*h/2 << endl;
}

Measured memory_bytes: 3572
# -*- coding: utf-8 -*-
S = input()
bcount=S.count('B')
wcount=S.count('W')
Slen=len(S)
ans=0
bb=0
for i in range(Slen):
    if i!=Slen:
        if S[Slen-i-1]=="B":
            ans=ans+bb
        else:
            bb=bb+1
print(ans)


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

const int MAX = 30000;
int main()
{
        vector<int> pr;
        bool p[MAX+1] = {false};
        for (int i=2; i<=MAX; i++)
                p[i]=1;

        for (int i=2; i*i<=MAX; i++)
                if (p[i])
                        for (int k=i+i; k<=MAX; k+=i)
                                p[k] = 0;

        for (int i=2; i<=MAX; i++)
                if(p[i]) pr.push_back(i);

        int N;
        while (cin >> N, N)
        {
                int cnt = 0;
                for (int i=0; i<pr.size(); i++)
                for (int j=i; j<pr.size()&&pr[i]+pr[j]<=N; j++)
                {
                        int k = N-pr[i]-pr[j];
                        if (!p[k]) continue;
                        if (pr[j] > k) continue;
                        if (pr[i]+pr[j] > k)
                                cnt++;
                }
                cout << cnt << endl;
        }
}

Measured memory_bytes: 968
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n;
  cin >> n;
  vll S(n);
  for(int i = 0; i < n; i++){
    cin >> S.at(i);
  }
  ll q;
  cin >> q;
  vll T(q);
  for(int i = 0; i < q; i++){
    cin >> T.at(i);
  }
  int counter = 0;
  for(int i = 0; i < q; i++){
    auto ite = lower_bound(ALL(S), T.at(i));
    if(ite != S.end() && *ite == T.at(i)) counter++;
  }
  cout << counter << endl;
}


Measured memory_bytes: 3892
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


int main() {
    int A, B;
    cin >> A >> B;
    if(A % 2 and B % 2) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3568
from bisect import*
from itertools import*

N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
ans = bisect(b, K)
for i in range(N):
    rest = K - a[i]
    if rest < 0:
        continue
    else:
        pre = bisect(b, rest)
        ans = max(ans, i+1+pre)
print(ans)



Measured memory_bytes: 41880