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

int main() {
  string s;
  int f = 1;
  cin >> s;
  reverse(s.begin(), s.end());
  for(int i = 0; i < s.length(); i++) {
    string s5, s6, s7;
    for(int j = 0; j < 7; j++) {
      if(i + j < s.length()) {
        if(j < 5)
          s5.push_back(s[i + j]);
        if(j < 6)
          s6.push_back(s[i + j]);
        s7.push_back(s[i + j]);
      }
    }
    if(s5 == "maerd" || s5 == "esare")
      i += 4;
    else if(s6 == "resare")
      i += 5;
    else if(s7 == "remaerd")
      i += 6;
    else {
      f = 0;
      break;
    }
  }
  cout << (f ? "YES" : "NO") << '\n';
}

Measured memory_bytes: 512
//=================================
// Created on: 2018/07/04 12:38:03
//=================================
#include <bits/stdc++.h>
using namespace std;
int main()
{
    for (int N;;) {
        cin >> N;
        if (N == 0) { break; }
        using P = pair<int, int>;
        map<int, vector<P>> reg;
        set<P> empty;
        constexpr int INF = 1000000000;
        empty.insert({0, INF});
        auto sz = [](const P& p) { return p.second - p.first+1; };
        for (int i = 0; i < N; i++) {
            char c;
            cin >> c;
            if (c == 'W') {
                int l, s;
                cin >> l >> s;
                vector<P> rem;
                for (const auto& p : empty) {
                    if (sz(p) <= s) {
                        s -= sz(p), rem.push_back(p), reg[l].push_back(p);
                    } else {
                        rem.push_back(p), empty.insert({p.first + s, p.second}), reg[l].push_back({p.first, p.first + s - 1}), s = 0;
                    }
                    if (s == 0) { break; }
                }
                for (const auto& r : rem) { empty.erase(r); }
            } else if (c == 'D') {
                int l;
                cin >> l;
                for (const auto& r : reg[l]) { empty.insert(r); }
                reg.erase(l);
            } else {
                int P;
                cin >> P;
                bool found = false;
                for (const auto& vs : reg) {
                    if (found) { break; }
                    const int r = vs.first;
                    const auto& v = vs.second;
                    for (const auto& p : v) {
                        if (p.first <= P and P <= p.second) {
                            found = true, cout << r << endl;
                            break;
                        }
                    }
                }
                if (not found) { cout << -1 << endl; }
            }
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3580
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std ;
typedef unsigned long long ll ;
# define rep (i , n ) for ( int i =0; i < n ; i++)
# define _sort(arg) sort(begin(arg), end(arg))

/*
string level_burgur(int n)
{
	if (n == 0)
	{
		return "P";
	}
	string burgur = "B" + level_burgur(n-1) + "P" + level_burgur(n-1)+"B";
	return burgur;
}
*/

ll ret_size(ll remain, ll n)
{
	/*
	if (remain == 0)
	{
		return 0;
	}
	*/
	//ll tmo = 1 << 52;
	//ll tmp_ = tmo - 3;
	//cout << tmp_ << endl;
	//printf("%llu\n", (1 << 52) - 3);
	if (n == 0)
	{
		if (remain != 0)
		{
			return 1;
		}
		else
		{
			return 0;
		}
		
	}
	ll tmo = 1ull << (n+2);
	ll tmp = tmo - 3;
	//cout << "test n+2=" << n+2 << "; tmp=" << tmp << "; remain="<<remain << endl;
	ll half = ((tmp + 1) >> 1);

	if (remain < half)
	{
		if (remain > 0)
		{
			//cout << "left" << endl;
			return ret_size(remain - 1, n-1);
		}
		else
		{
			return 0;
		}
		
	}
	else if (remain == half)
	{
		//cout << "e" << endl;
		return (1ull << n);
	}
	else
	{
		//cout << "r" << endl;
		return (1ull << n) + ret_size(remain - half, n-1);
	}
}

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

	ll N, X;

	cin >> N >> X;

	//cout << sizeof(ll) << endl;
	/*
	string pan = level_burgur(N);

	ll total = 0;
	for (ll i = 0; i < X; i++)
	{
		if (pan[i] == 'P')
		{
			total++;
		}
	}

	*/

	ll total = ret_size(X, N);

	//printf("%llu\n", total);
	cout << total << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100000+10;
ll n,x;
bool cmp(int a1,int a2){
    return a1<a2;
}
ll mabs(ll xx){
    if(xx<0) return xx*-1;
    return xx;
}
map<ll,ll>mmp;
int main()
{
    while(~scanf("%lld",&n)){
        for(ll i=0;i<n;i++){
            scanf("%lld",&x);
            mmp[x]++;
        }
        ll sum=0;
        for(map<ll,ll>::iterator it=mmp.begin();it!=mmp.end();it++){
            ll a=(*it).first,b=(*it).second;
            if(a>b) sum+=b;
            else sum+=(b-a);

        }
        mmp.clear();
        printf("%lld\n",sum);
    }


    return 0;
}




Measured memory_bytes: 6272
int_a, int_b, int_c, int_d = map(int, input().split())

#print(int_a, int_b, int_c, int_d)

max = int_a*int_c
for i in [int_a, int_b]:
  for j in [int_c, int_d]:
    if max < i*j:
      max = i*j
      
print(max)

Measured memory_bytes: 9164
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll mod = 1e9+7;

int main(void){
	ll N,A[200010],ans=0,zero;
	bool can=true;
	scanf("%lld",&N);
	reg(i,1,N){
		scanf("%lld",&A[i]);
	}
	zero=N;//一番右の0の位置
	ireg(i,1,N){
		if(i<N && A[i+1]-A[i]==1){
			//何もしない
		}else{
			if(i>=A[i]+1 && zero>=i-A[i]){
				zero=i-A[i];
				ans+=A[i];
			}else{
				can=false;
				break;
			}
		}
	}
	if(can){
		printf("%lld\n",ans);
	}else{
		printf("-1\n");
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/
/****** define variable start ******/
ll n;
vl a;
/******* define variable end *******/
int solve() {
	cin >> n;
	a.resize(n);
	ll ma = 0;
	map<ll, ll> youso;
	REP(i, n){
		cin >> a[i];
		if(youso.find(a[i]) == youso.end()){
			youso.insert(make_pair(a[i], 1));
		}else{
			youso.at(a[i])++;
		}
	}
	ll ans = 0;
	map<ll, bool> check;
	REP(i, n){
		check.insert(make_pair(a[i], false));
	}
	REP(i, n){
		if(check.at(a[i]) == true){
			continue;
		}
		check.at(a[i]) = true;
		if(youso.at(a[i]) > a[i]){
			ans += youso.at(a[i]) - a[i];
		}else if(youso.at(a[i]) < a[i]){
			ans += youso.at(a[i]);
		}
	}
	cout << ans << endl;

	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n)-1; i >= 0; --i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}

using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

constexpr char sp = ' ';
constexpr char cmm = ',';
constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}

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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s<<'[';for(size_t i=0;i<v.size();++i){s << v[i];if(i < v.size()-1) s << ", ";}s<<']';return s;
}
struct __f{
    __f(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    }
};

vector<string> cake;
vector<vector<int>> cut;
int main(){

    int H, W, K;
    scanf("%d%d%d", &H, &W, &K);    
    cake.resize(H);
    cut.resize(H, vector<int>(W, 0));
    rep(i, H) cin >> cake[i];
   
    int num = 1;
    rep(i, H){
        rep(j, W){
            if(cake[i][j] == '#') cut[i][j] = num++;
        }
    }

    rep(i, H){
        rep(j, W-1){
            if(!cut[i][j] or cut[i][j+1]) continue;
            cut[i][j+1] = cut[i][j];
        }
    } 

    rep(i, H){
        for(int j = W-1; j > 0; --j){
            if(!cut[i][j] or cut[i][j-1]) continue;
            cut[i][j-1] = cut[i][j];
        }
    }

    rep(i, H-1){
        rep(j, W){
            if(!cut[i][j] or cut[i+1][j]) continue;
            cut[i+1][j] = cut[i][j];
        }
    } 

    for(int i = H-1; i > 0; --i){
        rep(j, W){
            if(!cut[i][j] or cut[i-1][j]) continue;
            cut[i-1][j] = cut[i][j];
        }
    }


    rep(i, H){
        rep(j, W){
            printf("%d ", cut[i][j]);
        }
        putchar('\n');
    }

    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	int n;
	cin>>n;
	int a[n][n];
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			cin>>a[i][j];
		}
	}
	int lim = 1<<n;
	int cost[lim];
	memset(cost,0,sizeof(cost));
	for(int i=0; i<lim; i++){
		for(int j=0; j<n; j++){
			for(int k=j+1; k<n; k++){
				if(i&(1<<j) && i&(1<<k) ) cost[i]+=a[j][k]; 
			}
		}
	}
	//for(int i=0; i<lim; i++) cout<<cost[i]<<' ';
	
	int dp[lim];
	fill(dp,dp+lim,-1e17);
	dp[0] = 0;
	for(int m=1; m<lim; m++){
		for(int s=m; s; s=(s-1)&m){
			dp[m] = max(dp[m], dp[s] + cost[m^s]);
		}
		dp[m] = max(dp[m],dp[0]+cost[m]);
	}
	cout<<dp[lim-1];
}

Measured memory_bytes: 1280
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    private static FastScanner sc = new FastScanner();
    private static long mod = 1000000007;

    public static void main(String[] args) {
    	long N = sc.nextLong();
    	long M = sc.nextLong();
    	long K = sc.nextLong();
    	long[] frac = new long[(int)N * (int)M];
    	frac[0] = 1;
    	for(int i=1; i<N*M; i++) {
    		frac[i] = frac[i-1] * i % mod;
    	}
    	long C = frac[(int)N*(int)M-2] * power(frac[(int)K-2], mod-2) % mod * power(frac[(int)N*(int)M-(int)K], mod-2) % mod;
    	//System.out.println(C);
    	long sum = 0;
    	for(int i=0; i<N; i++) {
    		for(int j=0; j<M; j++) {
    			sum = (sum + (M-1-j) * (M-1-j + 1) / 2) % mod;
    			sum = (sum + ((M-1-j) * (M-1-j + 1) / 2 + (j) * (j + 1) / 2) * (N-1-i)) % mod;
    			sum = (sum + ((N-1-i) * (N-1-i + 1) / 2) * M )% mod;
    		}
    	}
    	System.out.println(sum * C % mod);
    }

    static long power(long m , long n){
    	if(n == 0) {
    		return 1;
    	}else if(n == 1){
            return m;
        }else if(n % 2 == 0){
            long s = power(m, n/2);
            return ( (s % mod) * (s % mod) ) % mod;
        }else{
            return ( (m % mod) * (power(m, n-1) % mod) ) % mod;
        }
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 24660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+10;
typedef pair <int ,int >pll;
map<pll,ll>mp;
int main()
{
    //std::ios::sync_with_stdio(0);
    int n;
    cin>>n;
    if(n==0)
        cout<<1<<endl;

    else
         cout<<0<<endl;




}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int n;
    cin >> n;
    if (n == 0){
      break;
    }
    vector<tuple<int, int, int>> r(n);
    for (int i = 0; i < n; i++){
      int L, R, w;
      cin >> L >> R >> w;
      L--;
      r[i] = make_tuple(R, L, w);
    }
    sort(r.begin(), r.end());
    vector<vector<int>> dp(366, vector<int>(366, 0));
    for (int i = 0; i < n; i++){
      int R = get<0>(r[i]);
      int L = get<1>(r[i]);
      int w = get<2>(r[i]);
      vector<vector<int>> dp2 = dp;
      for (int j = 0; j < 366; j++){
        dp2[R][j] = max(dp2[R][j], dp[L][j] + w);
        dp2[j][R] = max(dp2[j][R], dp[j][L] + w);
      }
      for (int j = 0; j < 366; j++){
        for (int k = 0; k < 366; k++){
          if (j > 0){
            dp2[j][k] = max(dp2[j][k], dp2[j - 1][k]);
          }
          if (k > 0){
            dp2[j][k] = max(dp2[j][k], dp2[j][k - 1]);
          }
        }
      }
      swap(dp, dp2);
    }
    cout << dp[365][365] << endl;
  }
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MAX 1000010
#define MOD 1000000007
  
using ll = long long;
using Graph = vector<vector<pair<ll,ll>>>;

int main(){
  int H,W; cin>>H>>W;
  vector<vector<int>> A(H,vector<int> (W));
  rep(i,H)rep(j,W)cin>>A.at(i).at(j);
  queue<pair<pair<int,int>,pair<int,int>>> res;
  rep(i,H-1)rep(j,W){
    if(A.at(i).at(j)%2){
      A.at(i+1).at(j)++;
      res.push(make_pair(make_pair(i+1,j+1),make_pair(i+2,j+1)));
    }
  }
  rep(j,W-1){
    if(A.at(H-1).at(j)%2){
      A.at(H-1).at(j+1)++;
      res.push(make_pair(make_pair(H,j+1),make_pair(H,j+2)));
    }
  }
  cout<<res.size()<<endl;
  while(!res.empty()){
    int a = res.front().first.first;
    int b = res.front().first.second;
    int c = res.front().second.first;
    int d = res.front().second.second;
    cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
    res.pop();    
  }
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

using namespace std;
using ll = unsigned long long;
using pii = pair<int, int>;

const int oo = 1e9 + 7;
const ll mod = 1e9 + 7,maxn = 100000000;
const double PI = acos(-1);


int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0); 
    string s, t;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;

    string u;
    cin >> u;

    if (u == s) a--;
    else b--;
    cout << a << " " << b << endl;

    return 0;
}

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

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

int main() {
	int n; cin >> n;
	map<int, int> a;
	rep(i, n) {
		int b; cin >> b;
		a[b] = i + 1;
		//printf("%d %d\n", b, i + 1);
	}
	for (int i = 1; i <= n; i++)
	{
		cout << a[i] << " ";
	}

	return 0;
}

Measured memory_bytes: 5504
import math
a,b,h,m = map(int,input().split())
ans = 0
ang = 0
tan = 30*h+0.5*m
cho = 6*m
ang = abs(cho-tan)
#print(tan,cho,ang)

ans = math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(ang)))
print(ans)

Measured memory_bytes: 9504
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef pair <int,int> pr;
#define fr(i, n) for(int i = 0; i < n; i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c)(c).begin(), (c).end()
#define tr(c, i) for (typeof ((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x)((c).find(x) != (c).end())
#define cpresent(c, x)(find(all(c), x) != (c).end())
// for mod power a^b%m use power<lli> (a,b,m)
template < class mytype >
mytype power(mytype a, mytype b, mytype m){if (b == 1) return a % m;if (b == 0) return 1;
mytype root = power < lli > (a, b / 2, m);mytype ans = (root * root) % m;if (b % 2) ans = (ans * a) % m;
return ans;
}
// for gcd use gcd<int> (a,b)
template < class type >type gcd(type a, type b){if (a == 0) return b;else return gcd(b % a, a);}
template < class type >type mod_inv(type a, type p) {return power(a, p - 2, p);}

int main()
{
   int n,m;
   cin >> n >> m;
   vector< vector<int> > v( n , vector<int>() );
   vector<int> out(n , 0);
   for(int i = 0 ; i < m ; i++){
    int x , y;
    cin >> x >> y;x--;y--;
    v[x].pb(y);
    out[y]++;
   }
   queue<int> q;vector<int> sor;
   for(int i = 0 ; i < n ; i++) if(out[i] == 0) q.push(i);
   while(!q.empty()){
    int t = q.front();q.pop();sor.pb(t);
    for(int i : v[t]){
        out[i]--;if(out[i] == 0) q.push(i);
    }
   }
   vector<int> lon(n, 0);
   for(int ele : sor){
    for(int child : v[ele]){
        lon[child] = max(lon[child] , lon[ele] + 1);
    }
   }
   int ans = 0;
   for(int i = 0 ; i < n ; i++) ans  = max(ans , lon[i]);
   cout << ans <<endl;


   return 0;
}


Measured memory_bytes: 7032
#include <bits/stdc++.h>
using namespace std;
int N;
string S;

void print(vector<bool> &vb)
{
  for (int i = 1; i <= N; i++)
  {
    if (vb.at(i))
      cout << 'W';
    else
      cout << 'S';
  }
  cout << endl;
}

void build(vector<bool> &vb)
{
  if (vb[1]) // W
  {
    if (S.at(0) == 'o')
      vb.at(0) = !vb.at(2);
    else
      vb.at(0) = vb.at(2);
  }
  else
  {
    if (S.at(0) == 'o')
      vb.at(0) = vb.at(2);
    else
      vb.at(0) = !vb.at(2);
  }

  for (int i = 2; i <= N; i++)
  {
    if (vb.at(i)) // W
    {
      if (S.at(i - 1) == 'o')
        vb.at(i + 1) = !vb.at(i - 1);
      else
        vb.at(i + 1) = vb.at(i - 1);
    }
    else
    {
      if (S.at(i - 1) == 'o')
        vb.at(i + 1) = vb.at(i - 1);
      else
        vb.at(i + 1) = !vb.at(i - 1);
    }
  }
}

int main()
{
  cin >> N >> S;
  vector<bool> vb(N + 2);
  for (int i = 0; i <= 1; i++)
  {
    for (int j = 0; j <= 1; j++)
    {
      vb[1] = i, vb[2] = j; // 0: S, 1: W
      build(vb);
      if (vb[1] == vb[N + 1] && vb[0] == vb[N])
      {
        print(vb);
        return 0;
      }
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3760
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n, d, x; cin >> n >> d >> x;
    int ans = x;
    REP(i, n){
        int a; cin >> a;
        ans += 1 + (d-1)/a;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    double x[N];
    string u[N];
    long double Sum = 0;
    for(int i=0;i<N;i++){
        cin >> x[i] >> u[i];
        if(u[i]  == "JPY") {
            Sum = Sum + x[i];
        }else{
            Sum = Sum + x[i] * 380000.0;
        }
    }
    cout << Sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner scan = new Scanner(System.in);
		
		String s = scan.next();
		String[] s1 = s.split("");
		String[] s2 = new String[s1.length];
		int ans = 0;
		
		for(int i = 0; i < s1.length; i++) {
			
			/*if(s1[i].equals("?")) {
				if(i == s1.length -1) {
					s1[i] = "D";
				}
				
				if(s1[i+1].equals("D") && i < s1.length -2) {
					s1[i] = "P";
				}
				if(s1[i-1].equals("P") && i > 1) {
					s1[i] = "D";
				}
				
				
			}*/
			if(s1[i].equals("?")) {
				s2[i] = "D";
				
			}
			else {
				s2[i] = s1[i];
				
			}
			
		}
		
		for(int i = 0; i < s1.length; i++) {
			
			if(s1[i].equals("D")) {
				ans++;
			}
			if(i < s1.length - 1) {
			if(s1[i].equals("P") && s1[i+1].equals("D")) {
				ans++;
			}
			}
		}
		String answer = String.join("", s2);
		
		System.out.println(answer);
		
	}

}

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

int main(){
    string s;
    getline(cin, s);
    string t=s;
    for(int i=0; i<s.length(); i++){
        if(islower(s[i]))t[i]=toupper(s[i]);
        else if(isupper(s[i]))t[i]=tolower(s[i]);
    }
    cout<<t<<endl;
    return 0;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

int main(){
    string s,t, u;
    int Ns, Nt;
    cin >> s>>t;
    cin>>Ns>>Nt;
    cin>>u;
    if(t==u) Nt--;
    else Ns--;

    cout<<Ns<<" "<<Nt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main () {
  int X, A, B;
  cin >> X >> A >> B;
  int Y=-1*X;
  if (0<=A-B) {
    cout << "delicious";
  }
  else if (Y<=A-B&&0>A-B) {
    cout << "safe";
  }
   else  {
     cout << "dangerous";
   }
}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main{
public static void main(String args[]){
  Scanner scan=new Scanner(System.in);
long row=scan.nextLong();
long col=scan.nextLong();
long pro=row*col;
if(row==1 || col==1){
  System.out.println("1");
}
else if (pro%2==0){
  System.out.println(pro/2);
}
else{
  System.out.println((pro+1)/2);
}
}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
ull B=950527;
int n,m;
char str[1000005];
ull a[1000005];

int main(){
  scanf("%s",str);
  n=strlen(str);
  for(int i=0;i<n;i++){
    a[i]=str[i];
    if(i)a[i]+=a[i-1]*B;
  }
  scanf("%s",str);
  m=strlen(str);
  ull key=0,num=0,C=1;
  for(int i=0;i<m;i++){
    key=key*B+str[i];
    C*=B;
  }
  for(int i=0;i<n;i++){
    num=a[i];
    if(i-m>=0)num-=C*a[i-m];
    if(key==num){
      printf("%d\n",i-m+1);
    }
  }
   
  return 0;
}

Measured memory_bytes: 9924
#include <stdio.h>
int main (void){
int x,y;

for ( ; ; ){

scanf ("%d %d",&x,&y);

if (x==0&&y==0){
	break;
}


if (x>y){
printf ("%d %d\n",y,x);
}

else {
printf ("%d %d\n",x,y);
}

}

return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for(ll i = 0; i < (n); i++)
//pow(x,n)
//cout << fixed << setprecision(桁数);

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

    int sum=0;
    priority_queue<int> A;
    rep(i,n){
        int in;
        cin >> in;
        A.push(in);
        sum += in;
    }

    bool flag=1;

    float border=sum/(4.0*m);
    rep(i,m){
        if(A.top()>=border){
            A.pop();
            continue;
        }
        else{
            flag=0;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;

int main(){
    long long N, M;
    cin >> N >> M;

    vector<long long> H(N);
    vector<long long> A(M), B(M);

    for(int i = 0; i < N; ++i){
        cin >> H.at(i);
    }

    for(int i = 0; i < M; ++i){
        cin >> A.at(i) >> B.at(i);
    }

    vector<bool> check(N, true);
    for(int i = 0; i < M; ++i){
        if(H[A[i] - 1] > H[B[i] - 1]){
            check[B[i] - 1] = false;
        }
        else if(H[A[i] - 1] < H[B[i] - 1]){
            check[A[i] - 1] = false;
        }
        else{
            check[A[i] - 1] = false;
            check[B[i] - 1] = false;
        }
    }

    int count = 0;
    for(int i = 0; i < N; ++i){
        if(check[i]){
            ++count;
        }
    }
    cout << count;
}


Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
#define all(v) v.begin(),v.end()


ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
 
int main(){
  int n;
  ll h;
  cin >> n >> h;
  ll a_mx=-inf;
  ll ans=0;
  vector<ll>dam(n);
  rep(i,n){
    ll a,b;
    cin >> a >> b;
    a_mx=max(a,a_mx);
    dam[i]=b;
  }
  sort(all(dam));
  reverse(all(dam));
  int now=0;
  while(h>0){
    if(dam[now]>=a_mx){
      h-=dam[now];
      now++;
      ans++;
    }
    else{
      h-=a_mx;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n, m;
	while(cin>>n>>m, n!=0){
		ll ans=0;
		vll a(n);
		rep(i, n) cin>>a[i];
		for(int i=0; i<n; i++)
			for(int j=i+1; j<n; j++)
				if (a[i]+a[j] <= m)
					ans = max(ans, a[i]+a[j]);

		if (ans!=0)
			cout << ans << "\n";
		else
			cout << "NONE\n";
	}
	return 0;
}


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

#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=50000;
    rep(y,1,P){
        ll x=mod(y*k);
        
        if(abs(x)<=P||x+P>=i_7){
            if(x+P>=i_7){
                x-=i_7;
            }
            cout<<x<<"/"<<y<<endl;
            //cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
typedef vector<ll> vl;
//////////////////////////



int main(){fastio
    ll a[3];rep(i,0,2)cin>>a[i];
    ll k;cin>>k;
    ll c=0;
    rep(z,0,1){
        while(a[z]>=a[z+1]){
            a[z+1]*=2;
            c++;
        }
    }
    if(k>=c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    
    return 0;
}



Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);


int N, M;

class Edge{
public:
    int from, to, cost;
    Edge(int from = 0, int to = 0, int cost = 0) :
            from(from), to(to), cost(cost){}

    bool operator < (const Edge &e) const{
        return cost < e.cost;
    }
    bool operator >(const Edge &e) const{
        return cost > e.cost;
    }

};

class Node{
public:
    vector<Edge> edges;
    int sign;
    Node(){
        sign = 0;
    }
};

class Graph{
public:
    vector<Node> nodes;
    Graph(int n) {
        rep(i, n) { Node n;  nodes.push_back(n); }
    }
    Node& operator[](int i){
        return nodes[i];
    }
};

class Data{
public:
    int from, to, sign;
    Data(int from, int to, int sign) {
        this->from = from;
        this->to   = to;
        this->sign = sign;
    }
};

Graph G(0);

bool bfs(){

    queue<Data> q;
    q.push(Data(-1, 0, 1));

    rep(i, N) G[i].sign = 0;

    bool flg = false;

    while(!q.empty()){
        Data d = q.front(); q.pop();
        fprintf(stderr, "%d->%d %d\n", d.from, d.to, d.sign);
        Node &n = G[d.to];
        n.sign = d.sign;

        for(auto &ee : n.edges){
            int s = d.sign * -1;
            Node &nn = G[ee.to];
            if(nn.sign != 0 && nn.sign != s){
                flg = true;
                continue;
            }
            if(nn.sign != 0 && nn.sign == s) {
                continue;
            }
            if(nn.sign == 0){
                nn.sign = s;
                q.push(Data(ee.from, ee.to, s));
            }
        }
    }

    return flg;
}

int main() {

    // input
	cin >> N >> M;
    G = Graph(N);

	rep(i, M){
		int a, b;
        cin >> a >> b; a--; b--;
        G[a].edges.push_back(Edge(a, b, 0));
        G[b].edges.push_back(Edge(b, a, 0));
	}

    // run
    bool extra = bfs();

    if(extra){
        ll all = (ll)(N) * (ll)(N-1) / 2LL;
        ll ret = all - M;
        cout << ret << endl;
    }
    else{
        ll countP = 0;
        ll countM = 0;
        rep(i, N){
            if(G[i].sign == 1) countP++;
            if(G[i].sign == -1) countM++;
        }

        ll all = countP * countM;
        ll ret = all - M;
        cout << ret << endl;
    }

}


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

int main() {
  string S, T;
  cin >> S >> T;
  
  for(int i = 0; i < T.size(); i++){
    if(S == T){
      cout << "Yes" << endl;
      return 0;
    }
    S = S.at(S.size()-1) + S;
    S.erase(S.size()-1);
  }

  cout << "No" << endl;
}

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

using namespace std;
int main() {
   map<string,int>mp;
   string s;
   int n;
   cin >>n;
   for(int i=0;i<n;i++){
       cin >>s;
       mp[s]++;
   }
   int mx=-1;
   for(auto x:mp){
       if(x.second>mx)mx= x.second;
   }
   for(auto x:mp){
       if(x.second == mx) cout <<x.first<<"\n";
   }
   return 0;
}


Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a;
int main(){
	cin>>a;
	if(a<1200)
	cout<<"ABC";{
	if(a>=1200 and a<2800)
	cout<<"ARC";{
	if(a>=2800)
	cout<<"AGC";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>

int main() {
  size_t N;
  scanf("%*u %zu", &N);  // skip L

  intmax_t res = 0;
  for (size_t i = 0; i < N; ++i) {
    intmax_t x, w;
    scanf("%jd %jd", &x, &w);
    res -= x*w;
  }

  if (res < 0) {
    printf("1\n-1 %jd\n", -res);
  } else if (res > 0) {
    printf("1\n1 %jd\n", res);
  } else {
    puts("0");
  }
}



Measured memory_bytes: 2748
/**
    Problem: Given two sequences a and b, find two balance sequences of brackets (s, t) of the same length
        such that their cost is maximized.
    The cost is calculated as followed: with position i, cost += a[i] if s[i] == t[i]; cost += b[i] otherwise.
*/

#include <cstdio>
#include <algorithm>
#include <set>

using namespace std;

#define long long long

const int N = 2e5 + 2;

int n, q, a[N], b[N];
set<pair<int, int> > s[2];
long cost = 0, sum[2] = {0, 0};

void Solve()
{
    while (q--)
    {
        int p, x, y; long cur = 0;
        scanf("%d %d %d", &p, &x, &y); --p;
        if (p == 0 || p == n - 1) cost += x - a[p], a[p] = x;
        else
        {
            cost += x - a[p];
            int old_sign = b[p] - a[p] >= 0;
            int new_sign = y - x >= 0;
            sum[old_sign] -= b[p] - a[p];
            sum[new_sign] += y - x;
            s[old_sign].erase({b[p] - a[p], p});
            s[new_sign].insert({y - x, p});
            a[p] = x, b[p] = y;
        }
        if (s[1].size() & 1)
            cur = cost + max(sum[1] + (--s[0].end())->first, sum[1] - s[1].begin()->first);
        else cur = cost + sum[1];
        printf("%lld\n", cur);
    }
}

int main()
{
    scanf("%d %d", &n, &q);
    n *= 2;
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]), cost += a[i];
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &b[i]);
        if (i != 0 && i != n - 1)
        {
            int x = b[i] - a[i];
            int sign = x >= 0;
            sum[sign] += x;
            s[sign].insert({x, i});
        }
    }
    Solve();
    return 0;
}


Measured memory_bytes: 12672
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long g = 0;
    for (int i = 0; i < N; i++) {
      long A = sc.nextLong();
      g = GCD(g, A);
    }
    sc.close();
    System.out.println(g);
  }

  public static long GCD(long a, long b) {
    if (b == 0) {
      return a;
    }
    return GCD(b, a % b);
  }
}


Measured memory_bytes: 48236
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {

    public static void main(String[] args) {
        try (var br = new BufferedReader(new InputStreamReader(System.in))) {
            var s = br.readLine().split(" ");
            var list = Stream.of(s).mapToInt(Integer::parseInt).boxed().collect(Collectors.toList());
            System.out.println(list.indexOf(0) + 1);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 34300
#include <stdio.h>

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    int ans=a+b;
    if (ans<a-b){
        ans=a-b;
    }
    if(ans<a*b){
        ans=a*b;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
N = int(input())
*A, = map(int, input().split())
m = max(A)
cnt = [0] * (m + 1)
for elem in A:
    cnt[elem] += 1
unique = []
for i in range(m + 1):
    if cnt[i] == 1:
        unique.append(i)
cnt = [0] * (m + 1)
A = list(set(A))
for elem in A:
    for mul in range(elem * 2, m + 1, elem):
        cnt[mul] = 1
ans = 0

for elem in unique:
    if cnt[elem] == 0:
        ans += 1
print(ans)

Measured memory_bytes: 48204
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
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(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

template <typename T>
struct li_chao_tree {
    const T INF = numeric_limits<T>::max();
    struct line {
        T a, b;
        line(T a, T b) : a(a), b(b) {}
        T operator()(T x) const { return a*x + b;}
    };
    int n;
    vector<line> fs;
    vector<T> xs;
    
    li_chao_tree(const vector<T>& xs_) : xs(xs_) {
        sort(xs.begin(), xs.end());
        xs.erase(unique(xs.begin(), xs.end()), xs.end());
        n = xs.size();
        fs.assign(n<<1, line(T(0), INF));
    }
    
    int index(T x) const { return lower_bound(xs.begin(), xs.end(), x) - xs.begin();}

    void add_line(T a, T b) { update(a, b, 0, n);}
    
    void add_line(T a, T b, T xl, T xr) {
        int l = index(xl), r = index(xr);
        update(a, b, l, r+1);
    }

    void update(T a, T b, int l, int r) {
        line g(a, b);
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) descend(g, l++);
            if (r & 1) descend(g, --r);
        }
    }
    
    void descend(line g, int i) {
        int l = i, r = i+1;
        while (l < n) l <<= 1, r <<= 1;
        while (l < r) {
            int c = (l+r) >> 1;
            T xl = xs[l-n], xr = xs[r-1-n], xc = xs[c-n];
            line& f = fs[i];
            T fl = f(xl), fr = f(xr), fc = f(xc);
            T gl = g(xl), gr = g(xr), gc = g(xc);
            if (fl <= gl && fr <= gr) return;
            if (fl >= gl && fr >= gr) { f = g; return;}
            if (fc > gc) swap(f, g), swap(fl, gl);
            if (fl >= gl) { i = i<<1|0; r = c;}
            else { i = i<<1|1; l = c;}
        }
    }
    
    T get_min(T x) const {
        int i = index(x);
        T res = INF;
        for (i += n; i; i >>= 1) res = min(res, fs[i](x));
        return res;
    }
};

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

    int n; ll c;
    cin >> n >> c;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];

    vector<ll> xs(n);
    rep(i, n) xs[i] = -2 * h[i];
    li_chao_tree<ll> seg(xs);
    
    vector<ll> dp(n);
    for (int i = 1; i < n; ++i) {
        seg.add_line(h[i-1], dp[i-1] + h[i-1] * h[i-1]);
        dp[i] = seg.get_min(-2 * h[i]) + h[i] * h[i] + c;
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 15880
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();

		int a[] = new int[n];

		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		sc.close();
		for(int j=0;j < n;j++) {
			if(a[j] % 2 == 0) {
				if(a[j] % 3 != 0 && a[j] % 5 != 0) {
					System.out.println("DENIED");
					return;
				}
			}
		}

		System.out.println("APPROVED");

		sc.close();

	}

}


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

int main(){
	string s;cin>>s;
	int cnt=0;
	for(char c:s){
		cnt+=c-'0';
	}
	puts(cnt%9==0?"Yes":"No");
}

Measured memory_bytes: 3748
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int arr[101]={};  
  for(int i=a;i<b;i++)arr[i]++;
  for(int i=c;i<d;i++)arr[i]++;
  int ans=0;
  rep(i,101){
    if(arr[i]>=2)ans++;
  }
  cout<<ans<<endl;
  
 return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner	sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] m = new int[n];
		for(int i = 0 ; i < n ; i++) m[i] = sc.nextInt();
		int sum = 0;
		for(int i = 0 ; i < n ; i++) {
			sum += m[i];
		}
		Arrays.sort(m);
		int temp = x - sum;
		System.out.println(n + temp / m[0]);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main() {
  int w[9][9],h[9][9],g[3][3][9],mp[9][9],n,i,j,f=0;
  cin >> n;
  for (n;n>0;n--) {
	  memset(w,0,sizeof(w)); memset(h,0,sizeof(h)); memset(g,0,sizeof(g));
	  for (i=0;i<9;i++) for (j=0;j<9;j++) {
		  cin >> mp[i][j];
		  mp[i][j]--;
          w[j][mp[i][j]]++; h[i][mp[i][j]]++;
		  g[i/3][j/3][mp[i][j]]++;
	  }
	  if (f==0) f=1; else cout << endl;
	  for (i=0;i<9;i++) { 
		  for (j=0;j<9;j++) {
		  if (w[j][mp[i][j]]>1 || h[i][mp[i][j]]>1 || g[i/3][j/3][mp[i][j]]>1) cout << '*'; else cout << ' ';
		  cout << mp[i][j]+1;
	      }
		  cout << endl;
	  }
  }    
    return 0;
}

Measured memory_bytes: 1160
/*
	0278: Admission Fee
*/
#include	<iostream>

using namespace std;

int main(void) {
	int cA, cB, n, x, y, b, p;
	bool f;
	
	cin >> n;
	for(int i = 0; i < n; i++) {
		f = false;
		cin >> x >> y >> b >> p;
		if(b >= 5 && p >= 2) {
			f = true;
			cA = (x*0.8) * b + (y*0.8) * p;
		} else {
			cA = x * b + y * p;
		}
		if(f == false) {
			if(b < 5) { b = 5; }
			if(p < 2) { p = 2; }
			cB = (x*0.8) * b + (y*0.8) * p;
		}
		if(f == false) {
			if(cA > cB) {
				cout << cB << endl;
			} else {
				cout << cA << endl;
			}
		} else {
			cout << cA << endl;
		}
	}
	
	return 0;
}

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

using ll = long long;
const ll mod = 1e9 + 7;

const auto ready = []()
{
	std::cin.tie(0);
	std::cout.tie(0);
	std::ios_base::sync_with_stdio(false);
	return true;
}();

ll fast_pow(ll a, ll b, ll m)
{
	if (b == 0)
		return (m == 1) ? 0 : 1;
	if (b % 2 == 0) {
		ll t = fast_pow(a, b / 2, m);
		return t * t % m;
	}
	return fast_pow(a, b - 1, m) * a % m;
}

ll inv(ll a)
{
	return fast_pow(a, mod - 2, mod);
}

const int mx = 2e6 + 10;
int facts[mx];
int revFacts[mx];

const auto precalc = []()
{
	facts[0] = 1;
	revFacts[0] = 1;
	for (int i = 1; i < mx; ++i) facts[i] = 1LL * facts[i - 1] * i % mod;
	revFacts[mx - 1] = inv(facts[mx - 1]) % mod;
	for (int i = mx - 2; i > 0; --i) revFacts[i] = 1LL * revFacts[i + 1] * (i + 1) % mod;
	return true;
}();

ll C(int n, int k)
{
    ll ans = 1;
    for(ll i = n; i >= (n - k + 1); --i) ans = (ans * i) % mod;
    return ans * revFacts[k] % mod;
}

int main()
{
    int x1, y1, x2, y2;
    int x3, y3, x4, y4;
    std::cin >> x1 >> y1 >> x2 >> y2;
    if(!(((x1 <= x2) && (y1 <= y2)) || ((x2 <= x1) && (y2 <= y1)))) std::swap(x1, x2);
    if(x1 >= x2 && y1 >= y2) std::swap(x1, x2), std::swap(y1, y2);
    ++x2, ++y2;
    x3 = x2; y3 = y1; x4 = x1; y4 = y2;
    ll ans = C(x1 + y1, x1) + C(x2 + y2, x2) - C(x3 + y3, x3) - C(x4 + y4, x4);
    ans %= mod;
    if(ans < 0) ans += mod;
    std::cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 19200
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9

using namespace std;

typedef long long ll;

set<ll> divisors;
ll n;

ll ans;
void solve(ll divi)
{
    ll tri = n;
    if(divi == 1)
        return;
    while(tri % divi == 0)
        tri /= divi;
    if(tri % divi == 1)
        ++ans;
}
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(ll i = 1; i * i <= n; ++i)
    {
        if(n % i == 0)
        {
            solve(i);
            divisors.insert(i);
            if(i * i != n)
            {
                solve(n / i);
                divisors.insert(n / i);
            }
        }
    }
    --n;
    for(ll i = 1; i * i <= n; ++i)
    {
        if(n % i == 0)
        {
            if(divisors.find(i) == divisors.end())
                ++ans;
            if(i * i != n)
            {
                if(divisors.find(n/i) == divisors.end())
                    ++ans;
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    ll sum = min(A, K);
    K -= (A + B);
    if (K > 0) {
        sum -= K;
    }
    cout << sum << endl;

    return 0;
}

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

int main(void){
    int N; cin >> N;
    set<int> A;
    for(int i=0; i<N; i++){
        int a; cin >> a;
        auto c=A.erase(a);
        if(!c) A.insert(a);
    }

    cout << A.size() << endl;
}

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

int main() {
  int n, m; cin >> n >> m;
  const ll INF = 100000008*4;
  vector<P> s(n), p(m), ans(n, make_pair(0,INF));
  rep(i,n) {
    int a, b; cin >> a >> b;
    s[i] = make_pair(a,b);
  }
  rep(i,m) {
    int c, d; cin >> c >> d;
    p[i] = make_pair(c,d);
  }
  rep(i,n) {
    ll x1 = s[i].first;
    ll y1 = s[i].second;
    rep(j,m) {
      ll x2 = p[j].first;
      ll y2 = p[j].second;
      ll d = abs(x1 - x2) + abs(y1 - y2);
      if (ans[i].second > d) {
        ans[i].first = j+1;
        ans[i].second = d;
      }
    }
  }
  rep(i,n) {
    cout << ans[i].first << endl;
  }

  return 0;
}

Measured memory_bytes: 3612