akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> dp(100010,vector<long long>(2,-1)),graph(100010);
long long n,a,b;

long long ans(long long curr , long long last , long long par){
    if(dp[curr][last] != -1){
        return dp[curr][last];
    }
    if(graph[curr].size() == 1 && graph[curr][0] == par){
        if(last == 0){
            return 2;
        }else{
            return 1;
        }
    }
    long long ret1=1,ret2=1;
    for(int i : graph[curr]){
        if(i != par){
            if(last == 0){
                ret1 *= ans(i,0,curr);
                ret1 %= 1000000007;
                ret2 *= ans(i,1,curr);
                ret2 %= 1000000007;
            }else{
                ret1 *= ans(i,0,curr);
                ret1 %= 1000000007;
            }
        }
    }
    long long ret;
    if(last == 0){
        ret = ret1+ret2;
    }else{
        ret = ret1;
    }
    ret %= 1000000007;
    dp[curr][last] = ret;
    return ret;
}

int main()
{
    cin >> n;
    for(int i = 0 ; i < n-1 ; i += 1){
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    cout << ans(1,0,-1)%1000000007;
}

Measured memory_bytes: 19584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const int mod = 1000000007;
struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
/*
ll gcd(ll a, ll b)
{
    if (a % b == 0)
        return (b);
    else
        return (gcd(b, a % b));
}
*/
int main()
{
    int n;
    cin >> n;
    ll x, y, zero = 0;
    map<pair<ll, ll>, pi> iwashi; //回転して一致したら同じパラメータを持つのでmap
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y;
        if (x == 0 && y == 0) //例外処理、(0,0)はどのイワシとも仲が悪い
        {
            zero++;
            continue;
        }
        ll g = gcd(x, y);
        x /= g;
        y /= g; //互いに素にする
        if (y < 0)
            x = -x, y = -y; //第3,4象限は180°回転
        else if (y == 0 && x < 0)
            x = -x, y = -y;
        bool rot90 = (x <= 0); //第2象限なら-90°回転
        if (rot90)
        {
            ll tmp = x;
            x = y, y = -tmp;
        }
        if (rot90)
            iwashi[{x, y}].first++;
        else
            iwashi[{x, y}].second++;
    }

    mint ans = 1;
    for (auto p : iwashi)
    {
        int s = p.second.first;
        int t = p.second.second;
        mint now = 1; //誰も選ばない
        now += mint(2).pow(s) - 1;
        now += mint(2).pow(t) - 1;
        ans *= now;
    }
    ans -= 1;
    ans += zero;
    cout << ans << endl;
}


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

int main(){
   int n;
   cin >> n;
   int a[n];
   for(int i=0;i<n;i++) cin >> a[i];
   int minv = a[0],maxv = a[1]-a[0];
   for(int i=1;i<n;i++){
       maxv = max(maxv,a[i]-minv);
       minv = min(minv,a[i]);
   }
   cout << maxv << endl;
}



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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    ll n;cin >> n;
    out(n/3);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,ch,cw,dh,dw;
  cin>>h>>w>>ch>>cw>>dh>>dw;
  ch--;
  cw--;
  dh--;
  dw--;
  vector<string> s(h);
  for(int i=0;i<h;i++)
    cin>>s.at(i);
  vector<vector<int>> l(h,vector<int>(w,h*w));
  priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>> q;
  q.push({0,ch,cw});
  while(!q.empty()){
    int gl=q.top().at(0);
    int gy=q.top().at(1);
    int gx=q.top().at(2);
    q.pop();
    if(gl>=l[gy][gx])
      continue;
    l[gy][gx]=gl;
    for(int my=-2;my<=2;my++)
      for(int mx=-2;mx<=2;mx++)
        if(my!=0||mx!=0)
          if(gy+my>=0&&gy+my<h&&gx+mx>=0&&gx+mx<w&&s[gy+my][gx+mx]=='.')
            if(gl+(abs(my)+abs(mx)==1?0:1)<l[gy+my][gx+mx])
              q.push({gl+(abs(my)+abs(mx)==1?0:1),gy+my,gx+mx});
  }
  cout<<(l[dh][dw]==h*w?-1:l[dh][dw])<<endl;
}


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

int main() {
  int N, K;
  int64_t sum = 0;
  cin >> N >> K;
  vector<int64_t> H(N);
  for (int i = 0; i < N; i++) cin >> H[i];
  sort(H.begin(), H.end(), greater<int64_t>());
  
  for (int i = K; i < N; i++) sum += H[i];
  cout << sum << endl;
}
    

Measured memory_bytes: 1792
#include<bits/stdc++.h>
const int  mod = 1e9 + 7;
#define debug(x) cout << '>' << #x << ':' << x << endl;

using namespace std ;
int main()
{
    long int n;
    cin >> n;
    long int arr[n];
    long int suf[n]={0};

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

    for(int i = 1; i < n; i++)
        {
            suf[i] = arr[i]+suf[i-1];
        }
    long long int res = 0;

    for(int i = 0; i < n ; i++)
            {
                res += ((suf[n-1]-suf[i])%mod*arr[i]%mod)%mod;
            }
    cout<<res%mod;
}



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

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x)
        cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}

#ifndef ONLINE_JUDGE
#define dbg(x...)                 \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define dbg(x...)
#endif
#define endl "\n"
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define ROF(i, a, n) for (ll i = a; i >= n; i--)
#define all(x) (x).begin(), (x).end()
#define dline cout << "///REACHED///\n";

typedef long long ll;

const ll MOD = 1e+9 + 7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
const ll MAXN = 4e+5 + 7;

void solve()
{
    ll n;
    cin>>n;
    vector<int> a(n);
    FOR(i, 0, n)
    {
        cin >> a[i];
    }
    sort(all(a), greater<int>());
    ll ans = a[0];
    FOR(i, 1, n / 2)
    {
        ans += 2 * a[i];
    }
    if (n & 1)
    {

        ans += a[n / 2];
    }
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll T = 1;
    //cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    cout<<k-n+1;
    for (int i = k-n+2;i < k+n;i ++)
        cout<<' '<<i;
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
int a,b,c;

int main()
{
	scanf("%d%d%d",&a,&b,&c);
    if(c >= a && c <= b) printf("Yes\n");
    else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main()
{
	IOS;
	int a,b,h;
	cin>>a>>b>>h;
	cout<<(a+b)*h/2;
	return 0;
}


Measured memory_bytes: 256
S = str(input())

if S == "SAT":
	print(1)
elif  S == "FRI":
	print(2)
elif  S == "THU":
	print(3)
elif  S == "WED":
	print(4)
elif  S == "TUE":
	print(5)
elif  S == "MON":
	print(6)
else:
	print(7)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maX 1000005
ll ans[1000008];
vector<ll>p;
bool marked[maX];

void sieve()
{
    for(ll i=4; i<=maX; i+=2)
    {
        marked[i]=1;
    }

    p.push_back(2);

    for(ll i=3; i<=maX; i+=2)
    {
        if(marked[i]==0)
        {
            p.push_back(i);
            for(ll j=i*i; j<=maX; j+=i+i)
            {
                marked[j]=1;
            }
        }
    }
}

void div()
{
    ll i,j,a,d,e;

    ans[0]=0;
    ans[1]=1;
    for(i=2; i<1000001; i++)
    {
        a=i;
        d=1;
        for(j=0; (p[j]*p[j])<=a; j++)
        {
            if(a%p[j]==0)
            {
                e=1;
                while(a%p[j]==0)
                {
                    e++;
                    a/=p[j];
                }
                d*=e;
            }
        }
        if(a>1) d=d*2;
        ans[i]=d+ans[i-1];
    }
}

int main()
{

    sieve();
    div();

    ll x;
    cin>>x;

    cout<<ans[x-1]<<endl;

    return 0;
}




Measured memory_bytes: 12840
def factorial(n):
  ans = 1
  for i in range(n):
    ans *= i+1
    ans %= mod
  return ans

n,m = map(int, input().split())
mod = 10**9 + 7
diff = abs(n-m)
if diff == 0:
  print((((factorial(n)**2)%mod)*2)%mod)
elif diff == 1:
  print((factorial(n)*factorial(m))%mod)
else:
  print(0)

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

using namespace std;

const char en = '\n';
using  ll =          long long;
using ull = unsigned long long;

#define REP(i  ,n) for(int i=0;i<n;i++)
#define FOR(i,s,g) for(int i=s;i<g;i++)

const ll INFL = 810000001919114514;
const int INF =         1919114514;


int N,MA,MB;
int A[40],B[40],C[40];

int nowA=0,nowB=0,nowC=0,result=INF;

int search(int i){
	if(nowA&&nowB&&(nowA*MB==nowB*MA)){
		result=min(result,nowC);
	}
	if(nowC>=result) return 0;
	if(i==N) return 0;
	//cout<<i<<en;

	search(i+1);
	nowA+=A[i];
	nowB+=B[i];
	nowC+=C[i];
	search(i+1);
	nowA-=A[i];
	nowB-=B[i];
	nowC-=C[i];
}

int main(){
	ios::sync_with_stdio(false);cin.tie();
	
	cin>>N>>MA>>MB;

	REP(i,N)
		cin>>A[i]>>B[i]>>C[i];

	search(0);
	
	cout<<((result==INF)?-1:result)<<en;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>;
#include<string>;
#include<vector>;
#include<algorithm>;
using namespace std;
int main() {
	int n, a, b, c,pla,val,t; string ans;
	cin >> n>>t>>a;
	t = t * 1000;
	a = a * 1000;
	vector<int> h(n+1);
	h[0] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> h[i];
	}
	pla = 1;
	val = abs(t - 6 * h[1] - a);
	for (int i = 1; i <= n; i++) {
		int dif = abs(t - 6 * h[i] - a);
		if (dif <= val) {
			pla = i;
			val = dif;
		}
	}
	cout << pla;
	return 0;//1000倍したことを忘れずに、１個ずれてる
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ll;
typedef pair<ll, ll> P;

vector<P > vec_sort(vector<P > v){
  int a = v[0].first;
  int b = v[0].second;
  vector<P > lf,ri;
  REP(i,v.size()){
    if(i==0) continue;
    if(v[i].second<b){
      lf.pb(v[i]);
    }else if(v[i].second>b){
      ri.pb(v[i]);
    }else{
      if(v[i].first<a){
        lf.pb(v[i]);
      }else{
        ri.pb(v[i]);
      }
    }
  }
  if(lf.size()>1){
    lf = vec_sort(lf);
  }
  if(ri.size()>1){
    ri = vec_sort(ri);
  }
  lf.pb(v[0]);
  lf.insert(lf.end(),all(ri));
  return lf;
}

int main(){
  int n;
  cin >> n;
  vector<P > works(n);
  ll a,b;
  REP(i,n){
    cin >> a >> b;
    works[i] = make_pair(a,b);
  }
  works = vec_sort(works);
  int now = 0;
  REP(i,n){
    //cout << works[i].first << " " << works[i].second << endl;
    now += works[i].first;
    if(now>works[i].second){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> m(h);
    for (int i = 0; i < h; i++)
    {
        cin >> m[i];
    }
    vector<vector<int>> l(h, vector<int>(w, 0));
    vector<vector<int>> r, u, d;
    r = l;
    u = l;
    d = l;
    int x, y;
    for (int i = 0; i < h; i++)
    {
        y = h - (i + 1);
        for (int j = 0; j < w; j++)
        {
            x = w - (j + 1);
            if (m[i][j] == '#')
            {
                l[i][j] = 0;
                u[i][j] = 0;
                continue;
            }
            if (j > 0)
            {
                 l[i][j] = l[i][j - 1] + 1;
            }
            else
            {
                l[i][j] = 1;
            }
            if (i > 0)
            {
                u[i][j] = u[i - 1][j] + 1;
            }
            else
            {
                u[i][j] = 1;
            }        
        }
    }
    for (int i = 0; i < h; i++)
    {
        y = h - (i + 1);
        for (int j = 0; j < w; j++)
        {
            x = w - (j + 1);
            if (m[y][x] == '#')
            {
                d[y][x] = 0;
                r[y][x] = 0;
                continue;
            }
            if(x<w-1)
            {
                r[y][x] = r[y][x + 1] + 1;
            }
            else
            {
                r[y][x] = 1;
            }
            if(y<h-1)
            {
                d[y][x] = d[y + 1][x] + 1;
            }
            else
            {
                d[y][x] = 1;
            }
        }
        
    }
    
    int maxv = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            maxv = max(maxv, l[i][j] + r[i][j] + d[i][j] + u[i][j] - 3);
        }
    }
    cout << maxv << endl;
    return 0;
}

Measured memory_bytes: 67200
#include<iostream>
using namespace std;
typedef pair<int,int> p;
p P(int a,int b){
	p PP;
	PP.first=a; PP.second=b;
	return PP;
}

int main(){
while(1){
	p A[100000+2];
	int n,k=0,in,ans=0;
	scanf("%d",&n);
	if(n==0)break;
	for(int i=0;i<n;i++){
		scanf("%d",&in);
		if(i%2==0){
			if(k==0){A[0]=P(in,1); k++;}
			else {
				if(in==A[k-1].first)A[k-1].second++;
				else {A[k]=P(in,1); k++;}
			}
		}
		else {
			if(in==A[k-1].first)A[k-1].second++;
			else{
				if(k==1){A[0]=P((A[0].first+1)%2,A[0].second+1);}
				else {
					A[k-2].second+=A[k-1].second+1;
					k--;
				}
			}
		}
	}
	for(int i=0;i<k;i++){
		if(A[i].first==0)ans+=A[i].second;
	}
	printf("%d\n",ans);
}
}

Measured memory_bytes: 1952
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n, h, w;
  cin >> n >> h >> w;
  int x = 1 + n - h;
  int y = 1 + n - w;

  cout << x * y << endl;
  return 0;
}


Measured memory_bytes: 3568
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val T = sc.nextInt()
    val ans = (1..N).map {
        val c = sc.nextInt()
        val t = sc.nextInt()
        if (t <= T) {
            c
        } else {
            Int.MAX_VALUE
        }
    }.min()
    println(if (ans == Int.MAX_VALUE) "TLE" else ans)
}


Measured memory_bytes: 29852
/*
    ThunderClap and Flash
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod) + (b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod) * (b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod) - (b%mod) + mod)%mod;}

void Flash(){
    ll n;
    cin>>n;
    string ss;
    cin>>ss;
    ll cntW = 0, cntR = 0;
    for (ll i = 0; i < n; i++) {
        cntW += (ss[i] == 'W');
        cntR += (ss[i] == 'R');
    }
    string chk;
    while (cntR--) {
        chk.pb('R');
    }
    while (cntW--) {
        chk.pb('W');
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        ans += (ss[i] != chk[i]);
    }
    ans /= 2;
    cout<<ans<<"\n";
}

int main(int argc, char const *argv[]){ 
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif
    ThunderClap;
    ll t = 1;
    //cin>>t;
    for(ll i = 1; i <= t; i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}


Measured memory_bytes: 3872
N,M = list(map(int,input().split()))
A = [input() for i in range(N)]
B = [input() for i in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j:j+M] == B[0]:
            for k in range(1,M):
                if B[k] != A[i+k][j:j+M]:
                    break
            else:
                print("Yes")
                break
    else:
        continue
    break
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0,b=0,x,y;
	cin>>n;
	cin>>x;
	for(int i=1;i<n;i++){
		cin>>y;
		if(y<=x) b++;
		else{
			ans=max(ans,b);
			b=0;
		}
		x=y;
	}
	ans=max(ans,b);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [list(map(int, input().split())) for i in range(2)]

res = 0
for i in range(n):
  ans = 0
  for j in range(i+1):
    ans += a[0][j]
  for k in range(i, n):
    ans += a[1][k]
    
  res = max(ans, res)
  
print(res)

Measured memory_bytes: 9152
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

    long long ans=1;
    for(int i=0; i<max(n, m); i++){
        ans = ans * (n-i ? n-i : 1) % 1000000007 * (m-i ? m-i : 1) % 1000000007;
    }
    if(n==m) ans = ans * 2 % 1000000007;
    if(fabs(n-m)>1) ans = 0;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N,K=gets.split.map(&:to_i)
v=[]
N.times{
    x,y=gets.split.map(&:to_i)
    v<<[x,y]
}
v.sort_by!{|o|o[0]}
s=10**20
(0 .. N-K).each{|l|
    (l+K-1 .. N-1).each{|r|
        w=v[r][0]-v[l][0]
        sy=v[l .. r].map{|o|o[1]}.sort
        (sy.size-K+1).times{|i|
            h=sy[i+K-1]-sy[i]
            warn [h,w*h].inspect
            if w*h<s
                s=w*h
            end
        }
    }
}
puts s


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

int main(){

    int a,b;
    cin>>a>>b;

    if(a==1){
        a=14;
    }
    if(b==1){
        b=14;
    }
    if(a==b){
        cout<<"Draw"<<endl;
    }
    else if(a<b){
        cout<<"Bob"<<endl;
    }
    else{
        cout<<"Alice"<<endl;
    }

    return 0;
}

Measured memory_bytes: 3560
"use strict";
const main = arg => {
  let row1 = arg.split("\n")[1].split(" ").map(n => n*1);
  let sortrow = arg.split("\n")[1].split(" ").map(n => n*1).sort(
    (a, b)=>{return a - b})
  let count = 0;
  
  for(let i = 0; i < row1.length; i++){
  	if(sortrow[i] != row1[i]){
    	count++;
    }
  }
  let ans = (count == 2 || count == 0) ? "YES": "NO";
  console.log(ans);
}

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


Measured memory_bytes: 7372
using System;
using System.Collections.Generic;
using System.Linq;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }
        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    class Program
    {
        private int N, X;
        private long[] x;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            X = sc.NextInt();
            x = sc.LongArray();
        }

        public void Solve()
        {
            Scan();
            x = x.Select(i => Math.Abs(i - X)).ToArray();
            var ans = x[0];
            for (int i = 1; i < N; i++)
            {
                ans = GCD(ans, x[i]);
            }
            Console.WriteLine(ans);
        }

        long GCD(long a, long b)
        {
            while (b > 0)
            {
                var r = b;
                b = a % b;
                a = r;
            }
            return a;
        }

        static void Main() => new Program().Solve();
    }
}

Measured memory_bytes: 21600
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000];

// DP テーブル
long long dp[110000];

int main(){
  int N,K;
  cin>>N>>K;
  int h[100010];
  long long dp[101000];
  for (int i=0; i<N; i++) cin>>h[i];
  
  for (int i=0; i<N; i++) dp[i]=INF;
  
 dp[0]=0;
  
  for (int i=0; i<N-1; i++){
    for (int j=1;j<=K; j++){
  
  chmin(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
    }
  }
  cout<<dp[N-1]<<endl;
}
  

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

struct edge {
    int to;
    ll cost;
};

vector<ll> dijkstra ( int a, vector<vector<edge>> &g, int n ) {
    vector<ll> cost(n, 1e18);
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que;
    cost[a] = 0;
    que.push({0, a});
    while(!que.empty()) {
        pair<ll, int> now = que.top(); que.pop();
        ll now_cost = now.first;
        int now_p = now.second;
        if ( now_cost > cost[now_p] ) continue;
        for ( auto tmp_num : g[now_p] ) {
            if ( cost[now_p] + tmp_num.cost < cost[tmp_num.to] ) {
                cost[tmp_num.to] = cost[now_p] + tmp_num.cost;
                que.push({cost[tmp_num.to], tmp_num.to});
            }
        }
    }
    return cost;
}   

int main(){
    int n;
    cin >> n;
    vector<vector<edge>> g(n);
    rep(i, n-1) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        --a, --b;
        g[a].push_back((edge){b, c});
        g[b].push_back((edge){a, c});
    }

    int q, k;
    cin >> q >> k;
    --k;
    vector<ll> cost(n, 1e18);
    cost = dijkstra(k, g, n);

    vector<int> xv(q);
    vector<int> yv(q);
    rep(i, q) {
        int x, y;
        cin >> x >> y;
        xv[i] = --x;
        yv[i] = --y;
    }
//    rep(i, n) cout << cost[i] << " ";
//    cout << endl;
    rep(i, q) {
        cout << cost[xv[i]] + cost[yv[i]] << endl;
    }
    return 0;
}


Measured memory_bytes: 13424
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var h=new int[n-1][];
		for(int i = 0;i<n-1;i++) {
			h[i]=new int[n-1-i];
			for(int j = i+1;j<n;j++) {h[i][j-1-i]=(int)Log((i^j)&-(i^j),2)+1;}
		}
		StringBuilder sb=new StringBuilder();
		for(int i = 0;i<n-1;i++) {sb.Append(String.Join(" ",h[i])+"\n");}
		Console.Write(sb);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 16604
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){

    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n){
        cin >> p.at(i);
    }
    sort(p.begin(), p.end());
    int ans = 0;
    rep(i,k){
        ans += p.at(i);
    }
    cout << ans << endl;
    return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

vector<ll> div(ll N) {
    vector<ll> ans;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ans.pb(i);
            if (i != N / i) ans.pb(N / i);
        }
    }
    return ans;
}

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

    ll N; cin >> N;
    ll cnt = div(N - 1).size() - 1;
    for (ll x : div(N)) {
        if (x == 1) continue;
        ll tmp = N;
        while (tmp % x == 0) tmp /= x;
        if (tmp % x == 1) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;
typedef long long LL;
const long long INF = (1LL<<62);

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, K; cin >> N >> K;
	vector<int> X;
	for(int i=0; i<N; i++){
		int x; cin >> x;
		X.push_back(x);
	}

	LL ans = 0;
	for(int i=0; i<N; i++){
		LL d = (LL)min(abs(X[i]), abs(X[i]-K));
		ans += (2*d);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef pair<l_l,ll> lll;
typedef vector<string> vs;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll dp[440][440],sum[440][440];
int main(){
    ll n;cin>>n;
    vl a(n);rep(i,n)cin>>a[i];
    rep(i,n){
        for(int j=i+1;j<=n;j++){
            sum[i][j]=a[j-1];
            if(j-1>=0)sum[i][j]+=sum[i][j-1];
        }
    }
    rep(i,n){
        rep(j,n+1){
            dp[i][j]=LINF;
        }
        dp[i][i+1]=0;
    }
    for(int len=2;len<=n;len++){
        for(int i=0;i<n;i++){
            if(i+len>n)continue;
            int j=i+len;
            for(int k=i+1;k<j;k++){
                //if(i==2&&j==4)cout<<dp[2][4]<<endl;
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]+sum[i][j]);
            }
        }
    }
    /*cout<<sum[2][4]<<endl;
    cout<<dp[2][3]<<endl;
    cout<<dp[2][4]<<endl;*/
    cout<<dp[0][n]<<endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m, c;
    cin >> n >> m >> c;
    vi b(m);
    vvi a(n, vi(m));
    rep(i, m) cin >> b[i];
    rep(i, n) rep(j, m) cin >> a[i][j];
    int ans = 0;
    rep(i, n) {
        int sum = c;
        rep(j, m) {
            sum += a[i][j] * b[j];
        }
        if (sum > 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	int n;
	int flag = 0;
	int count = 1;

	cin >> n;

	vector<int>a(n + 1);
	FOR(i, 1, n) {
		cin >> a[i];
	}
	FOR(i, 1, n-1) {
		switch (flag) {
		case 0:
			if (a[i + 1] > a[i]) {
				flag = 1;
			}
			else if (a[i + 1] < a[i]) {
				flag = 2;
			}
			else {
				flag = 3;
			}
			break;
		case 1:
			if (a[i + 1] < a[i]) {
				flag = 0;
				count++;
			}
			break;
		case 2:
			if (a[i + 1] > a[i]) {
				flag = 0;
				count++;
			}
			break;
		case 3:
			if (a[i + 1] > a[i]) {
				flag = 1;
			}
			else if (a[i + 1] < a[i]) {
				flag = 2;
			}
			break;
		}
		
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    string str;
    while(1)
    {
        cin >> str;
        int sum = 0;
        if(str.at(0) == '0')break;
        for(int i = 0 ; i < str.size() ; i++)
        {
            sum += str.at(i) - '0';
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3184
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Set<String> set = new HashSet<String>();
		int count =0;
		for (int i=0;i<N;i++) {
			String temp = sc.next();
			if (set.contains(temp)==false) {
				count++;
				set.add(temp);
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 78724
//daddy's back in town, back to rolling the damn hash yoooo babeeeeees//
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
const ll mod = (int)1e9 + 7;
int n, k;

int32_t main(){
	ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin>>n>>k;
	if(n==1){
		if(k==0) return cout<<"0 0 1 1", 0;
		else return cout<<-1, 0;
	}
	if(k>=(1<<n)) return cout<<-1, 0; 
	for(int i=0; i<(1<<n); i++){
		if(i!=k) cout<<i<<" ";
	}
	cout<<k<<" ";
	for(int i=0; i<(1<<n); i++){
		if((1<<n)-1-i!=k) cout<<(1<<n)-1-i<<" ";
	}
	cout<<k;
}

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

int main() {
    string S;
    int K;
    cin >> S >> K;
    int N = S.size();

    //全探索。S[i]に対して部分文字列の配列を作っていく
    vector<string> vec;
    for (int i = 0; i < N; i++) {
        for (int j = 1; j <= K; j++) {
            vec.push_back(S.substr(i, j));
        }
    }

    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());

    string ans;
    ans = vec[K-1];
    cout << ans << endl;
    return 0;
}


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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(a>b)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream&os, const pair<t,u>&p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream&operator <<(ostream&os,const vc<t>&v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class t>
void mkuni(vc<t>&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

const int inf=LLONG_MAX/3;

using p=tuple<int,int,int>;
using ld=long double;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	int n;cin>>n;
	n++;
	vc<p> ps;
	rep(i,n){
		int x,z;cin>>x>>z;
		ps.eb(x,z,i);
	}
	
	vi can(n,0);
	vc<ld> ans(n,inf);
	
	rep(_,2){
		sort(all(ps));
		vc<pi> conv;
		int i=0;
		while(i<n){
			int a,b,c;tie(a,b,c)=ps[i++];
			while(conv.size()>=2){
				int s=conv.size();
				if((conv[s-1].a-a)*(conv[s-2].b-conv[s-1].b)-(conv[s-1].b-b)*(conv[s-2].a-conv[s-1].a)>0)
					break;
				conv.pop_back();
			}
			conv.eb(a,b);
			if(c==0)break;
		}
		while(i<n){
			int a,b,c;tie(a,b,c)=ps[i++];
			auto calc=[&](int j){
				return ld(conv[j].b-b)/(a-conv[j].a);
			};
			int l=0,r=(int)conv.size()-1;
			while(r-l>=3){
				int m1=(l+l+r)/3,m2=(l+r+r)/3;
				if(calc(m1)>calc(m2))
					r=m2;
				else
					l=m1;
			}
			rng(j,l,r+1){
				if(conv[j].b>b){
					can[c]=1;
					chmin(ans[c],ld(a-conv[j].a)/(conv[j].b-b));
				}
			}
		}
		
		for(auto&w:ps){
			int a,b,c;tie(a,b,c)=w;
			w=p(-a,-b,c);
		}
	}
	
	rng(i,1,n){
		if(can[i])cout<<ans[i];
		else cout<<-1;
		cout<<"\n";
	}
}



Measured memory_bytes: 15952
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();

        int[][] point = new int[n][3];
        for (int i=0; i<n; i++) {
            point[i][0] = sc.nextInt();
            point[i][1] = sc.nextInt();
            point[i][2] = sc.nextInt();
        }

        int[][] dp = new int[n+1][3];

        for (int i=0; i<n; i++) {
            dp[i+1][0] = Math.max(dp[i][1]+point[i][1], dp[i][2]+point[i][2]);
            dp[i+1][1] = Math.max(dp[i][0]+point[i][0], dp[i][2]+point[i][2]);
            dp[i+1][2] = Math.max(dp[i][1]+point[i][1], dp[i][0]+point[i][0]);
        }

        int ans = 0;

        ans = Math.max(dp[n][0], Math.max(dp[n][1], dp[n][2]));

//        System.out.println(dp[1][0]);
//        System.out.println(dp[1][1]);
//        System.out.println(dp[1][2]);

        System.out.println(ans);
    }
}




Measured memory_bytes: 95260
n = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))

ans = 1
mod = 10**9 + 7
inf = float('inf')

for i in range(n-1):
    if A[i] == A[i+1]:
        A[i] = -A[i]
    if T[n-i-1] == T[n-i-2]:
        T[n-i-1] = -T[n-i-1]

for t,a in zip(T,A):
    if t < 0 and a < 0:
        ans *= min(-t,-a)
        ans %= mod
    elif t < 0:
        if -t < a:
            ans *= 0
    elif a < 0:
        if -a < t:
            ans *= 0
    elif t != a:
        ans *= 0
print(ans)


Measured memory_bytes: 82148
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int h = scanner.nextInt();
			System.out.println((a + b) * h / 2);
		}
	}
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) ;
#define cerr if(0)cout
#endif

int main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    ll n, a, b, c, d; cin >> n >> a >> b >> c >> d; n --;
    ll diff = b - a;
    rep(i, 0, n + 1){
        if(diff >= i * c - (n - i) * d and diff <= i * d  - (n - i) * c){
            DBG(diff, i, (n - i), i * c - (n - i) * d, i * d - (n - i) * c);
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
W, H, x, y = map(int, input().split())

if W / 2 == x and H / 2 == y:
    flag = '1'
    s = (W / 2) * H

elif W / 2 == x and H / 2 != y:
    flag = '0'
    s = (W / 2) * H

elif W / 2 != x and H / 2 == y:
    flag = '0'
    s = W * (H / 2)

elif W / 2 != x and H / 2 != y:
    flag = '0'
    s = W * H / 2

print('{} {}'.format(s, flag))


Measured memory_bytes: 3060
import java.io.*;
import java.util.*;

class Main{
	public void run(){
		String str = next();
		int idx = str.length();
		for(int i=0;i<str.length();i++){
			if(str.charAt(i) == 'C'){
				idx = i;
				break;
			}
		}
		String result = "No";
		for(int i=idx+1;i<str.length();i++){
			if(str.charAt(i) == 'F'){
				result = "Yes";
				break;
			}
		}

		out.println(result);
	}

	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().run();
		out.flush();
	}

	public Main(){
	}

	int ni(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;	}

	long nl(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}

	double nd(){
		return Double.parseDouble(next());
	}

	String next(){
		int c;
		while(!isAlNum(c = read()));
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	String nextLine(){
		int c;
		while(!isAlNumOrSpace(c = read()));
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNumOrSpace(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
	private static boolean isAlNumOrSpace(int c){
		return isAlNum(c) || c == ' ' || c == '\t';
	}
	void debug(Object... os){
		out.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 8276
//be naame khodaa
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
#define F first
#define S second
#define pb push_back
#define sz(x) ((int)(x).size())

inline int in(){ int x, y; y = scanf("%d", &x); return x; }

vector<pii> ans;

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

    bool flag = false; 
    if( n % 2 ) {
        flag = true; 
        n--; 
    }

    for(int i = 1; i <= n; i++) 
        for(int j = i+1; j <= n; j++) 
            if( i + j != n + 1 ) 
                ans.pb({i,j}); 

    if( flag ) { 
        for(int i = 1; i <= n; i++)
            ans.pb( {n+1, i} ); 
    }

    cout << sz(ans) << endl;
    for(auto x: ans) 
        cout << x.F << " " << x.S << '\n';

    return 0;
}


Measured memory_bytes: 384