akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

const int N=205;

int f[N][N][N],g[N][N][N],n,m;
char s[N][N];

int main() {
	scanf("%d%d",&n,&m);
	fo(i,1,n) scanf("%s",s[i]+1);
	fo(i,1,n) {
		f[i][i][m]=m;
		fd(j,m-1,1) {
			if (s[i][j]==s[i][j+1]) f[i][i][j]=f[i][i][j+1];
			else f[i][i][j]=j;
		}
	}
	fo(i,1,n) 
		fo(k,1,m) 
			fo(j,i+1,n) {
				if (s[j][k]!=s[j-1][k]) break;
				f[i][j][k]=min(f[i][j-1][k],f[j][j][k]);
			}
	int ans=0;
	while (f[1][n][1]<m) {
		fo(i,1,n) fo(j,i,n) fo(k,1,m) g[i][j][k]=0;
		fo(len,1,n)
			fo(i,1,n-len+1) {
				int j=i+len-1;
				fd(k,m,1) {
					g[i][j][k]=f[i][j][k]<m?f[i][j][f[i][j][k]+1]:m;
					if (i<j) {
						int l=i,r=j-1;
						while (l<=r) {
							int mid=l+r>>1;
							g[i][j][k]=max(g[i][j][k],min(f[i][mid][k],f[mid+1][j][k]));
							if (f[i][mid][k]>f[mid+1][j][k]) l=mid+1;
							else r=mid-1;
						}
					}
				}
			}
		fo(i,1,n) fo(j,i,n) fo(k,1,m) f[i][j][k]=g[i][j][k];
		ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 63232
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

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







int main() {
 int n;
 cin >> n;
 string w[n+1];
 map<string,bool> ok;
bool flag = true;
 rep (i,n){
   cin >> w[i];
 }
 
 rep(i,n-1){
   if (ok[w[i]]||w[i+1][0]!=w[i][w[i].size()-1]){
     flag = false;
   }
   ok[w[i]]=true;
 }
 if (ok[w[n-1]]) flag = false;

 if (flag) cout << "Yes" << endl;
 else cout << "No" << endl;

}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    ll N, K;
    cin >> N >> K;
    Vl A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    ll nn = lower_bound(A.begin(), A.end(), 0) - A.begin();
    ll n0 = upper_bound(A.begin(), A.end(), 0) - A.begin() - nn;
    ll np = N - nn - n0;

    ll left = -2e18, right = 2e18;
    while (right - left > 1) {
        ll mid = (left + right) / 2;
        ll cnt = 0;
        if (mid < 0) {
            ll j = 0;
            for (ll i = 0; i < nn; i++) {
                while (j < np && A[i] * A[nn + n0 + j] > mid) ++j;
                cnt += np - j;
            }
        }
        else if (mid == 0) {
            cnt += N * (N - 1) / 2 - nn * (nn - 1) / 2 - np * (np - 1) / 2;
        }
        else {
            ll j = nn - 1;
            for (ll i = 0; i < nn; i++) {
                while (j >= 0 && A[i] * A[j] <= mid) --j;
                cnt += nn - j - 1;
                if (j + 1 <= i) --cnt;
            }
            j = np - 1;
            for (ll i = 0; i < np; i++) {
                while (j >= 0 && A[nn + n0 + i] * A[nn + n0 + j] > mid) --j;
                cnt += j + 1;
                if (i <= j) --cnt;
            }
            cnt /= 2;
            cnt += N * (N - 1) / 2 - nn * (nn - 1) / 2 - np * (np - 1) / 2;
        }
        if (cnt <= K - 1) {
            left = mid;
        }
        else {
            right = mid;
        }
    }

    cout << left + 1 << endl;

    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int Q = Integer.parseInt(in.next());

            int[] l = new int[Q];
            int[] r = new int[Q];

            for (int i = 0; i < Q; i++) {
                l[i] = Integer.parseInt(in.next());
                r[i] = Integer.parseInt(in.next());
            }

            sieve((int) (1e5 + 100));

            boolean[] like2017 = new boolean[(int) (1e5 + 1)];
            for (int i = 0; i < 1e5 + 1; i++) {
                if (i % 2 == 0) {
                    continue;
                }
                if (isPrime[i] && isPrime[(i + 1) / 2]) {
                    like2017[i] = true;
                }
            }

            int[] countLike2017 = new int[(int) (1e5 + 1)];
            for (int i = 1; i < 1e5 + 1; i++) {
                countLike2017[i] = countLike2017[i - 1];
                if (like2017[i]) {
                    countLike2017[i]++;
                }
            }

            for (int i = 0; i < Q; i++) {
                System.out.println(countLike2017[r[i]] - countLike2017[l[i] - 1]);
            }

        }
    }

    private static final int MAX_N = (int) 1e5 + 200;
    private static final int[] prime = new int[MAX_N];
    private static final boolean[] isPrime = new boolean[MAX_N + 1];

    public static final int sieve(int n) {
        int p = 0;
        for (int i = 0; i <= n; i++) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for (int i = 2; i <= n; i++) {
            if (isPrime[i]) {
                prime[p++] = i;
                for (int j = 2 * i; j <= n; j += i) {
                    isPrime[j] = false;
                }
            }
        }
        return p;
    }

}


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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int sx, sy, tx, ty;

int main(void) {

    cin >> sx >> sy >> tx >> ty;

    int dx = abs(tx - sx);
    int dy = abs(ty - sy);

    rep(i, dy) {
        cout << "U";
    }

    rep(i, dx) {
        cout << "R";
    }

    rep(i, dy) {
        cout << "D";
    }

    rep(i, dx) {
        cout << "L";
    }

    cout << "L";

    rep(i, dy + 1) {
        cout << "U";
    } 

    rep(i, dx + 1) {
        cout << "R";
    }

    cout << "D" << "R";

    rep(i, dy + 1) {
        cout << "D";
    }

    rep(i, dx + 1) {
        cout << "L";
    }

    cout << "U" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<set>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define itrep(at)	for(auto it=at.begin();it!=at.end();it++)
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vb vector<bool>
#define vc vector<char>
#define vvll vector<vector<long long int> >
#define sll set<long long int>
#define mll map<long long int,long long int>
#define sllit set<long long int>::iterator
#define pll pair<long long int,long long int>
#define vpll vector<pair<long long int,long long int> >
#define db double
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}
lli mpower(lli a,lli b,lli m){lli res=1;a=a%m;while(b){if(b&1){res=(res*a)%m;}a=((a%m)*(a%m))%m;b>>=1;}return res;}
lli gcd(lli a,lli b){if(b==0) return a;if(a==0) return b;if(a>=b) return gcd(b,a%b);else return gcd(a,b%a);}
lli lcm(lli a,lli b){lli p=a*b;return p/gcd(a,b);}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}


/******************************START********************************/
int main()
{
	char ch1,ch2,ch3;
	string s1,s2,s3,str;
    lli i,j,k,a,b,c,t,d,n,m,sum=0,ans=0,temp;
    cin >> n >> k;
    vll v(n);
    rep(i,0,n)	cin >> v[i];
    for(i=0;i<k;i++)	sum+=v[i];
    ans=sum;
    for(i=1;i<n-k+1;i++){
    	sum=sum-v[i-1]+v[k-1+i];
    	if(ans<sum)	ans=sum;
	}
	ans+=k;
	db d1=ans;
	cout << fixed << setprecision(10) << d1/2 << endl;
    
    
    
    
    
    return 0;
}





















/* UJJWAL KESHRI */

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

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
int main(){
  long n,d,ii,jj,kk;
  long x[10][10];
  ll sum,cnt;
  double ret1,ret2;
  cin >> n >> d;
  cnt = 0;
  
  for(ii=0;ii<n;ii++){
    for(jj=0;jj<d;jj++){
      cin >> x[ii][jj];
      //cout << "iijj" << x[ii][jj] << endl;
    }
  }
  
  for(ii=0;ii<n-1;ii++){
    for(kk=ii+1;kk<n;kk++){
      sum = 0;
      for(jj=0;jj<d;jj++){
	//cout << "ii:" << ii << "kk:" << kk << endl;
	//cout << "iijj:" << x[ii][jj] << "kkjj" << x[kk][jj] << endl;
	sum += pow(x[ii][jj]-x[kk][jj],2);

      }
      //cout << "sum:" << sum << endl;	
      ret1 = sqrt(sum);
      ret2 = (ll)ret1;
      if(ret1 == ret2){
	cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<typeinfo>
using namespace std;

typedef unsigned long long ull;

int main(){
    ull x;
    cin >> x;
    ull a = (x-1) / 11;
    ull b = (x-1) - 11*a;
    cout << 2*a + (ull)(b > 5) + 1;
    return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
 	input!(s: String);

	let v: Vec<char> = s.chars().collect();
	let mut count = 0;
	for i in 1..v.len() {
		if v[i] != v[i-1] {
			count += 1;
		}
	}
	println!("{}", count);
}



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

using namespace std;

int dirs[4][2]={{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

int inf=1e9;

int n, k, q;
vector<int> v;

pair<bool, int> can(int interval_left, int interval_right)
{
    int tot=0;
    vector<bool> available(n, true);
    int ptr1=k-1;
    int ptr2=0;
    priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > pq;
    for(int i=0; i<k; i++) pq.push(make_pair(v[i], i));

    int x=0;
    int y=1e9;
    while(true)
    {
        if(ptr1>=n) break;
        pair<int, int> p = pq.top();
        int val = p.first;
        int idx = p.second;
        if(!(ptr2 <= idx && idx <= ptr1))
        {
            available[idx]=false;
            pq.pop();
            continue;
        }
        if(interval_left <= val && val <= interval_right)
        {
            x=max(x,val);
            y=min(y,val);
            available[idx]=false;
            pq.pop();
            tot++;
            ptr1++;
            if(ptr1>=n) break;
            pq.push(make_pair(v[ptr1], ptr1));
            while(ptr2<n && !available[ptr2]) ptr2++;
        }
        else
        {
            ptr2++;
            while(ptr2<n && !available[ptr2]) ptr2++;
            ptr1++;
            if(ptr1>=n) break;
            pq.push(make_pair(v[ptr1], ptr1));
        }
    }
    bool b = (tot>=q);
    if(x==0 && y==1e9) swap(x, y);
    return make_pair(b, x-y);
}

int main()
{
    //freopen("inp.in", "r", stdin);
    //freopen("outp.out", "w", stdout);
    //ios::sync_with_stdio(false);
    scanf("%d %d %d", &n, &k, &q);
    v.assign(n, -1);
    for(int i=0; i<n; i++) scanf("%d", &v[i]);
    int ans=inf+5;
    vector<int> sorted(n);
    for(int i=0; i<n; i++)
    {
        sorted[i]=v[i];
    }
    sort(sorted.begin(), sorted.end());
    ans=sorted[q-1]-sorted[0];
    int ptr1=q-1;
    int ptr2=0;
    while(ptr1+1<n)
    {
        ptr1++;

        while(ptr1-ptr2+1>=q)
        {
            pair<bool, int> p = can(sorted[ptr2], sorted[ptr1]);
            bool b=p.first;
            if(!b) break;
            ans=min(ans,p.second);
            ptr2++;
        }
        ptr2--;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
s = input()
ans = 0
if s == "SUN":
  ans = 7
elif s == "MON":
  ans = 6
elif s == "TUE":
  ans = 5
elif s == "WED":
  ans = 4
elif s == "THU":
  ans = 3
elif s == "FRI":
  ans = 2
elif s == "SAT":
  ans = 1
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
 
    int sum , i;
    char k[1000];
     
    while(1){
        scanf("%s",k);
        if (k[0]=='0')break;
        for (sum=0,i=0; k[i]!='\0'; i++) {
            sum+=(k[i]-'0');
        }
        printf("%d\n",sum);
        }
 
    return 0;
}

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

#define sz(x) (int)(x.size())
#define FOR(x,y,z) for(int x = y; x <= z; x++)
#define int long long

const int N = 1e5 + 2, inf = 1e18;

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);  

    int n, m;
    cin >> n >> m;
    if(n > m)
        swap(n, m);
    int k;
    cin >> k;
    int ans = 0;
    while(k > 0){
        k -= m;
        ans++;
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,D,X;
cin>>N>>D>>X;
vector<int>a(N);
for(int i=0;i<N;i++){
    cin>>a[i];
}
long long cnt=0;
for(int i=0;i<N;i++){
    int c=0;
   while(true){
    int j=(a[i]*(c++))+1;
    if(j<=D)cnt++;
    else break;
   }
}
cout<<cnt+X;

return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			int n = int.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int k = 0;
			Edge[] ans = new Edge[n - 1];
			List<Edge>[] tree = new List<Edge>[n];
			for (int i = 0; i < n; i++) {
				tree[i] = new List<Edge>();
			}
			for (int i = 0; i < n - 1; i++) {
				int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
				ans[i] = new Edge() { A = vs[0] - 1, B = vs[1] - 1 };
				tree[ans[i].A].Add(ans[i]);
				tree[ans[i].B].Add(ans[i]);
				k = Math.Max(k, tree[ans[i].A].Count);
				k = Math.Max(k, tree[ans[i].B].Count);
			}

			Queue<int> queue = new Queue<int>();
			queue.Enqueue(0);
			bool[] c = new bool[k];
			while (queue.Count > 0) {
				int i = queue.Dequeue();
				for (int x = 0; x < tree[i].Count; x++) {
					c[x] = false;
				}
				foreach (var edge in tree[i]) {
					if (edge.Color != 0) {
						c[edge.Color - 1] = true;
					}
				}
				int j = 0;
				foreach (var edge in tree[i]) {
					if (edge.Color == 0) {
						queue.Enqueue(i == edge.A ? edge.B : edge.A);
						while (c[j]) {
							j++;
						}
						edge.Color = j + 1;
						c[j] = true;
					}
				}
			}
			Console.WriteLine(k);
			foreach (var item in ans) {
				Console.WriteLine(item.Color);
			}


			Console.Out.Flush();
		}
	}

	public class Edge
	{
		public int A;
		public int B;
		public int Color;
	}
}


Measured memory_bytes: 30016
#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--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, t;
  cin >> n >> t;
  vi32 v(n);
  cin >> v;
  int ans = 0;
  int l = 0;
  reps(i, n - 1) {
    if (v[i] <= l + t) {
      ans += v[i] - l;
    } else {
      ans += t;
    }
    l = v[i];
  }
  ans += t;
  cout << ans << endl;
}


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

using namespace std;

int main(void){
	
	string Str,strBefore,strAfter;
	int strMiddle=0,count=0;
	bool miss;
	
	
	while(cin>>Str){
		if(Str.size()%2==0){
			
			strMiddle=Str.size()/2;
			strBefore=Str.substr(0,strMiddle);
			strAfter=Str.substr(strMiddle,Str.size());
			
			miss=false;
			for(int i=0;i<strBefore.size();i++){
				if(strBefore[i]!=strAfter[(strAfter.size()-1)-i]){
					miss=true;
					break;
				}
			}
			
			if(miss==false){
				count++;
			}
		}
		else if(Str.size()%2==1){
			
			strMiddle=Str.size()/2+1;
			strBefore=Str.substr(0,strMiddle-1);
			strAfter=Str.substr(strMiddle,Str.size());
			
			miss=false;
			for(int i=0;i<strBefore.size();i++){
				if(strBefore[i]!=strAfter[(strAfter.size()-1)-i]){
					miss=true;
					break;
				}
			}
			
			if(miss==false){
				count++;
			}
		}
		else if(Str.size()==1){
			count++;
		}
	}
	
	cout<<count<<endl;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim_i = (b); i < lim_i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Tue Mar 17 19:49:14 JST 2020
 **/

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

signed main() {
    Int n, W;
    cin >> n >> W;
    vector<Int> w(n), v(n);
    REP(i, n) cin >> w[i] >> v[i];
    vector<Int> dp(W + 1);
    REP(i, n) {
        for (Int j = W; j >= 0; j--) {
            if (j - w[i] >= 0) chmax(dp[j], dp[j - w[i]] + v[i]);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) << endl;
}


Measured memory_bytes: 1024
import math

N = int(input())
A = list(map(int, input().split()))


def calc(b):
    total = 0
    for i in range(1, N+1):
        ai = A[i-1]
        total += abs(ai - i - b)
    return total


B = list(sorted([A[i-1]-i for i in range(1, N+1)]))
if N % 2 == 0:
    # 偶数の時は中央値=平均値
    median = (B[(N-1)//2] + B[N//2]) / 2
    b1 = math.floor(median)
    b2 = math.ceil(median)
    print(min(calc(b1), calc(b2)))
else:
    b = B[N//2]
    print(calc(b))




Measured memory_bytes: 26612
#include<iostream>
using namespace std;
long long n,a,b,c,d,maxn,minn,flag=0;
int main()
{
	cin>>n>>a>>b>>c>>d;
	if(a>b){
		long long temp=a;
		a=b;
		b=temp;
	}
	for(int i=0;i<=n-1;i++){
		maxn=i*d-(n-1-i)*c;
		minn=i*c-(n-1-i)*d;
		if(a+maxn>=b&&a+minn<=b){
			flag=1;
		}
	}
	if(flag==1){
		cout<<"YES"<<endl; 
	}
	else{
		cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int k, a, b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; ++i) {
		if (i % k == 0) {
			cout << "OK\n";
			return 0;
		}
	}
	cout << "NG\n";
	return 0;
}

Measured memory_bytes: 3676
package main

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

var scanner = bufio.NewScanner(os.Stdin)
const (
	MAX = 1000000
)
func main() {
	a := make([]int, MAX+1)
	a[1] = 1
	for i := 2; i <= MAX; i *= 2 {
		a[i]++
	}
	for i := 1; i <= MAX; i++ {
		if a[i] != 0 {
			for j := i*3; j <= MAX; j *= 3 {
				if a[j] == 0 {
					a[j]++
				}
			}
		}
	}
	for i := 1; i <= MAX; i++ {
		if a[i] != 0 {
			for j := i*5; j <= MAX; j *= 3 {
				if a[j] == 0 {
					a[j]++
				}
			}
		}
	}
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		m, _ := strconv.Atoi(buf[0])
		if m == 0 {
			break
		}
		n, _ := strconv.Atoi(buf[1])
		cnt := 0
		for i := m; i <= n; i++ {
			if a[i] != 0 {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}


Measured memory_bytes: 2892
#include <iostream>

using namespace std;

int main(){
  bool f=true;
  int p=0;
  while(cin >> p && p>0){
    int x[4]={};
    cin >> x[0] >> x[1] >> x[2] >> x[3];

    int r=(x[0]*10+x[1]*50+x[2]*100+x[3]*500)-p;

    int y[4]={};
    y[3]=r/500;    r-=y[3]*500;
    y[2]=r/100;    r-=y[2]*100;
    y[1]=r/50;     r-=y[1]*50;
    y[0]=r/10;
    if(f) f=false;
    else cout << endl;
    if(x[0]>y[0]) cout << "10 "  << (x[0]-y[0]) << endl;
    if(x[1]>y[1]) cout << "50 "  << (x[1]-y[1]) << endl;
    if(x[2]>y[2]) cout << "100 " << (x[2]-y[2]) << endl;
    if(x[3]>y[3]) cout << "500 " << (x[3]-y[3]) << endl;
  }
  return 0;
}

Measured memory_bytes: 3032
# -*- coding: utf-8 -*-

inputs = input()
AA = int(inputs[:2])
BB = int(inputs[2:])

if (AA == 0 or AA > 12) and (BB == 0 or BB > 12):
    print('NA')
elif AA == 0 or AA > 12:
    print('YYMM')
elif BB == 0 or BB > 12:
    print('MMYY')
else:
    print('AMBIGUOUS')

Measured memory_bytes: 3064
N = int(input())
A = [int(a) for a in input().split()]
MA = [0] * (N + 2)
MA[0] = 1
ma = 1
for i, a in enumerate(A):
    if a > ma or (a == ma and i < N - 1):
        print(-1)
        exit()
    ma = (ma - a) * 2
    MA[i+1] = ma

ans = 0
s = 0
for i in range(N + 1)[::-1]:
    a = A[i]
    s = min(s + a, MA[i])
    ans += s
print(ans)

Measured memory_bytes: 700780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<string, int> msi;
typedef map<int,pair<int,int> > miii;
typedef complex<double> point;
typedef pair<int, ii> iii;
typedef vector<iii> viii;
#define X real()
#define Y imag()
#define FileIn(file) freopen(file".txt", "r", stdin)
#define FileOut(file) freopen(file".txt", "w", stdout)
#define Fill(ar, val) memset(ar, val, sizeof(ar))
#define PI 3.1415926535897932385
#define all(ar) ar.begin(), ar.end()
#define pb push_back
#define bit(n) (1<<(n))
#define Last(i) (i & -i)
#define INF 500000000
#define maxN 10000010
#define VISITED 1
#define UNVISITED -1
#define P(p) const point &p
#define L(p0, p1) P(p0), P(p1)

int graph[205][205];
int main()
{
    ios::sync_with_stdio(0);
    //cin.tie(0);
    //FileIn("in");
    //FileOut("out");
    int V,E,R;
    cin>>V>>E>>R;
    for(int i = 0;i<205;i++)
    {
        for(int j = 0;j<205;j++)
        {
            if(i!=j) graph[i][j]=INF;
            else graph[i][j] = 0;
        }
    }
    vector<int> ToTake;
    for(int i = 0;i<R;i++)
    {
        int tmp;
        cin>>tmp;
        ToTake.push_back(tmp-1);
    }
    for(int i = 0;i<E;i++)
    {
        int u,v,w;
        cin>>u>>v>>w;
        u--,v--;
        if(graph[u][v]>w)
            graph[u][v]=graph[v][u]=w;
    }
    for (int k = 0; k < V; k++) // remember that loop order is k->i->j
            for (int i = 0; i < V; i++)
                for (int j = 0; j < V; j++)
                    graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
    sort(ToTake.begin(),ToTake.end());
    int res = INF;
    do{
        int tmp = 0;
		for (int i = 0; i < ToTake.size()-1; ++i)
			tmp += graph[ToTake[i]][ToTake[i + 1]];
		res = min(res, tmp);
	}while(next_permutation(ToTake.begin(), ToTake.end()));
	cout<<res<<"\n";
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <deque> 

using namespace std;


int n, k;

int main()
{
	scanf("%d%d", &n, &k);
	
	int ans = n - k + 1;
	printf("%d\n", ans);
	

	return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	string s;
	cin>>s;
	ll n = s.size(), mx = 0, c = 0;
	forn(i, 0, n){
		if(s[i] == 'R')c++;
		else {
			mx = max(mx, c);
			c= 0;
		}
	}
	mx = max(mx, c);
	cout<<mx<<endl;
}

Measured memory_bytes: 3652
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < s.length(); i+=2) {
      builder.append(s.charAt(i));
    }
    System.out.println(builder.toString());
  }
}

Measured memory_bytes: 23520
import java.util.*;

class Main{
	static public void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int r=sc.nextInt();
		
		if(n<10){
			n=100*(10-n);
		}
		else{
			n=0;
		}
		
		System.out.println(r+n);
	}
}

Measured memory_bytes: 21716
#入力
K, S = map(int, input().split())

#問題文よりX, Y, Zの最大値はKであるため、各値の最大値はKである
X = range(K+1)
Y = range(K+1)

#フラグ設定
flag = 0

#全探索
for x in X:
    for y in Y:
        #条件に合うzの値を算出
        z = S - x - y
        if z<=K and z>=0:  #上で求めたzの値に問題文からFilterを掛ける
            flag += 1

#出力
print(flag)

Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <numeric>
using namespace std;
 
#define LOCAL  1
#define UPLOAD 2
 
#define ll long long
const long long INF = 1LL << 60;
 
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
#define REP(i,M) for(int i=0;i<M;i++)
 
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 gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

  string S = input<string>();
  if(S[0] != S[1] || S[1] != S[2]){
    output("Yes");
  }
  else{
    output("No");
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 0x3f3f3f3f;
const double pi = 3.14;
const ll mod = 1000000007;
ll gcd(ll a, ll b)
{
	if(b==0) return a;

	else return gcd(b, a%b);
}
ll lcm(ll a, ll b)
{
	return (a*b)/gcd(a,b);
}
ll fastpower(ll base, ll exp, ll mod)
{
	ll ans = 1ll;

	while(exp)
	{
		if(exp&1)
		{
			ans = (ans%mod * base%mod)%mod;
		}
		exp/=2;
		base = (base%mod * base%mod)%mod;
	}
	return ans;
}
const int MAX = 1e5+9;
bool visited[MAX];
vector< int > adj[MAX+1];
void dfs(int node)
{
	visited[node] = true;

	for(auto u : adj[node])
	{
		if(!visited[u])
		{
			dfs(u);
		}
	}
}

int main() {
	// your code goes here
	
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	int n; cin >> n;
	unordered_set<string> s;
	for(int i = 0;i<n;i++)
	{
		string m; cin >> m;
		s.insert(m);
	}
	cout << s.size() << '\n';
	return 0;
	} 

Measured memory_bytes: 20064
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi a,b,c;

int main(){
	cin>>n;
	a=b=vi(n);
	for(auto &i:a) cin>>i;
	for(int i=n-1;i>=0;i--){
		int t=0;
		for(int j=i;j<n;j+=i+1) t+=b[j];
		if(t%2!=a[i]){
			b[i]++;
			c.push_back(i+1);
		}
	}
	int S=c.size();
	cout<<S<<endl;
	for(int i=0;i<S;i++) cout<<c[i]<<" \n"[i==S-1];
}

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a;
    vector<int> q;
    for(int i=0;i<n;i++){
        cin >> a;
        q.push_back(a);
    }
    int ans=0,f=0;
    for(int i=0;i<n;i++){
        ans++;
        f=q[f]-1;
        if(f==1){
            cout << ans << endl;
            return 0;
        }
    }
    cout << -1 << endl;


    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int cnt=0;
  vector<int> v(n);
  for (int i=0; i < n ; i++){
    cin >> v.at(i);
  }
  for (int j=1; j < n-1; j++){
    int pre=v.at(j-1);
    int now=v.at(j);
    int next=v.at(j+1);
    if ((pre < now && now < next) ||(next < now && now < pre)) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>

static int64_t
gcd (
  int64_t a,
  int64_t b
  )
{
  do
  {
    const int64_t t = a;
    a = b % a;
    b = t;
  }
  while ( a );

  return ( b );
}

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

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int64_t a1, m1, a2, m2, a3, m3;
    int64_t r1, c1, r2, c2, r3, c3;

    scanf ( "%lld%lld%lld%lld%lld%lld", &a1, &m1, &a2, &m2, &a3, &m3 );
    if ( !( a1 | m1 | a2 | m2 | a3 | m3 ) ) break ;

    c1 = c2 = c3 = 1;
    for ( r1 = a1; r1 != 1; r1 = r1 * a1 % m1 ) ++c1;
    for ( r2 = a2; r2 != 1; r2 = r2 * a2 % m2 ) ++c2;
    for ( r3 = a3; r3 != 1; r3 = r3 * a3 % m3 ) ++c3;

    printf ( "%lld\n", lcm ( lcm ( c1, c2 ), c3 ) );
  }

  return ( 0 );
}

Measured memory_bytes: 0
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int l[] = new int[n];
    for (int i = 0; i < n; i++) {
      l[i] = Integer.parseInt(sc.next());
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        for (int k = j + 1; k < n; k++) {
          int li = l[i];
          int lj = l[j];
          int lk = l[k];
          if (li == lj || lj == lk || lk == li) {
            continue;
          }
          if (li + lj > lk && lj + lk > li && lk + li > lj) {
            ans++;
          }
        }
      }
    }
    pw.println(ans);
  }
}



Measured memory_bytes: 36624
/**
*	created: 11.09.2020 18:56:25
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using ll = long long;
using P = pair<int,int>;
// #define endl '\n'
#define int long long
#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--)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;
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> T pow(T a, ll n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
struct faster_io {faster_io() {cin.tie(0); ios_base::sync_with_stdio(false);}} faster_io_;

signed main() {
    int n, wei; cin >> n >> wei;
    vector<int> w(n), v(n);
    rep(i,n) cin >> w[i] >> v[i];
    deque<int> w1, w2, w3, w4;
    rep(i,n) {
        if (w[i] == w[0]) w1.push_back(v[i]);
        if (w[i] == w[0] + 1) w2.push_back(v[i]);
        if (w[i] == w[0] + 2) w3.push_back(v[i]);
        if (w[i] == w[0] + 3) w4.push_back(v[i]);
    }
    sort(rall(w1)); sort(rall(w2)); sort(rall(w3)); sort(rall(w4));
    w1.push_front(0); w2.push_front(0); w3.push_front(0); w4.push_front(0);
    rep2(i,2,w1.size()) w1[i] += w1[i-1];
    rep2(i,2,w2.size()) w2[i] += w2[i-1];
    rep2(i,2,w3.size()) w3[i] += w3[i-1];
    rep2(i,2,w4.size()) w4[i] += w4[i-1];
    int ans = 0;
    rep(i,w1.size()) rep(j,w2.size()) rep(k,w3.size()) rep(l,w4.size()) {
        int vsum = w1[i] + w2[j] + w3[k] + w4[l];
        int wsum = w[0]*i + (w[0]+1)*j + (w[0]+2)*k + (w[0]+3)*l;
        if (wsum <= wei) chmax(ans,vsum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;

const int N=5005;
const ll inf=1000000000000000000ll;

int n,x,now,p;
ll ans,sum;
int a[N],b[N][N];
ll s[N];

int main(){
	int i,j;
	scanf("%d%d",&n,&x);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	ans=inf;
	for (i=1;i<n;i++) a[i+n]=a[i];
	for (i=1;i<=n+n-1;i++){
		b[i][i]=a[i];
		for (j=i+1;j<=n+n-1;j++) b[i][j]=min(b[i][j-1],a[j]);
	}
	for (i=0;i<n;i++){
		for (j=1;j<=n+n-1;j++) s[j]=s[j-1]+1ll*b[max(1,j-i)][j];
		for (j=n;j<=n+n-1;j++) ans=min(ans,1ll*i*x+s[j]-s[j-n]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 80128
import java.util.*;
class Main{
public static void main(String[] args){
	Scanner in = new Scanner(System.in);
  	int n = in.nextInt();
  	int a[] = new int[n];
  	int sum = 0;	
  	for(int i = 0; i < n; i++){
    	a[i] = in.nextInt();
      	sum+=a[i];
    }
  	int k = in.nextInt();
  	int p[] = new int[k];
  	int x[] = new int[k];
  	for(int i =0;i<k;i++){
    	p[i] = in.nextInt();
      	x[i] = in.nextInt();
      	int temp = sum; 
      	sum=sum-a[p[i]-1]+x[i];
      	System.out.println(sum);
      	sum = temp;
    }
  
}
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

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

  vi A(N + M - 1), B(N + M - 1);
  for (ll i = 0; i < N + M - 1; i++) {
    cin >> A[i] >> B[i];
    A[i] -= 1;
    B[i] -= 1;
  }

  ll r;
  {
    vi v(N);
    for (ll i = 0; i < N + M - 1; i++) {
      v[B[i]] += 1;
    }
    for (ll i = 0; i < N; i++) {
      if (v[i] == 0) {
        r = i;
      }
    }
  }

  vvi G(N);
  for (ll i = 0; i < N + M - 1; i++) {
    G[A[i]].push_back(B[i]);
  }

  vector<unordered_set<ll>> G2(N);
  for (ll i = 0; i < N + M - 1; i++) {
    G2[A[i]].insert(B[i]);
  }

  vi v1;
  {
    list<ll> q;
    unordered_set<ll> visited;
    q.push_back(r);
    while (!q.empty()) {
      ll n = -1;
      vi v;
      for (ll i: G2[q.back()]) {
        v.push_back(i);
        if (visited.find(i) == visited.end()) {
          n = i;
          for (ll j: v) {
            G2[q.back()].erase(j);
          }
          break;
        }
      }
      if (n == -1) {
        v1.push_back(q.back());
        q.pop_back();
      } else {
        visited.insert(n);
        q.push_back(n);
      }
    }
  }

  vi v2(N, -1);
  {
    unordered_set<ll> s;
    for (ll i = 0; i < N; i++) {
      for (ll j: G[v1[i]]) {
        if (s.find(j) != s.end()) {
          v2[j] = v1[i];
          s.erase(j);
        }
      }
      s.insert(v1[i]);
    }
  }

  for (ll i = 0; i < N; i++) {
    cout << v2[i] + 1 << endl;
  }
}

Measured memory_bytes: 23408
import java.math.BigDecimal;
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();
		sc.nextLine();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		sc.close();
		Arrays.sort(array);
		int count1 = 1;
		int count2 = 0;
		int width = array[n - 1];
		int height = 0;
		boolean widthFixed = false;
		boolean heightFixed = false;
		for (int i = n - 2; i >= 0; i--) {
			if (!widthFixed) {
				if (array[i] == width) {
					count1++;
					if (count1 == 4) {
						height = width;
						widthFixed = true;
						heightFixed = true;
						break;
					}
				} else {
					if (count1 < 4 && count1 >= 2) {
						count1 = 2;
						widthFixed = true;
						height = array[i];
						count2 = 1;
					} else {
						count1 = 1;
						width = array[i];
					}
				}
			} else {
				if (array[i] == height) {
					count2++;
					if (count2 == 2) {
						heightFixed = true;
						break;
					}
				} else {
					if (count2 < 2) {
						height = array[i];
						count2 = 1;
					}
				}
			}
		}
		if (heightFixed && widthFixed) {
			BigDecimal mupti = new BigDecimal(width).multiply(new BigDecimal(height));
			System.out.println(mupti);
		} else {
			System.out.println(0);
		}
		
	}
}

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

ll dp[18][2];

int main() {
    string S; cin >> S;
    
    vector<ll> abc(26, 0);
    ll n = S.length();
    REP(i, n) abc[S[i] - 'a']++;
    
    string ans;
    if (n != 26) {
        REP(i, 26) if (abc[i] == 0) {
            ans = S + (char)(i + 'a');
            break;
        }
    } else {
        ll x = 0;
        RFOR(i, n-1, 1) if (S[i-1] < S[i]) {
             x = i;
             break;
        }
        if (x == 0) {
            ans = "-1";
        } else {
            ans += S.substr(0, x-1);
            
            fill(ALL(abc), 0);
            REP(i, x) abc[S[i] - 'a']++;
            
            FOR(i, S[x-1] - 'a', 26) if (abc[i] == 0) {
                ans += i + 'a';
                break;
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define NUM 999
int main(){
   int x ;
   scanf("%d",&x);
   if(x%10==2||x%10==4||x%10==5||x%10==7||x%10==9){
      printf("hon");
   }else if(x%10==0||x%10==1||x%10==6||x%10==8){
      printf("pon");
   }else if(x%10==3){
      printf("bon");
   }
     

   
   return 0;
}


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

#define reb(i,b,n) for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n) reb(i,0,n)
#define rreb(i,b,n) for(int i = b-1; i >= n; i--)
#define rrep(i,n) reb(i,n,0)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v) for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vall(x) (x).begin(), (x).end()
#define rvall(x) (x).rbegin(), (x).rend()
#define vsort(v) sort(vall(v))
#define rvsort(v) sort(rvall(v))
#define len(array) (sizeof (array) / sizeof *(array))
#define aall(x) x, x+len(x)
#define asort(x) sort(aall(x))
#define rasort(a, type) sort(aall(a), greater<type>())
#define afill(a, v) fill(aall(a), v)
#define afill2(a, v, type) fill((type *)a, (type *)(a + len(a)), v)
#define sz(x) (int)(x).size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define pb push_back
#define _USE_MATH_DEFINES
#define priArr(table, n) rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define priAr2(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;

using namespace std;
using std::stringstream;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class F, class T> inline void convert(const F &f, T &t){stringstream ss;ss<<f;ss>>t;}
template<class T> inline T sqr(T x) {return x*x;}

typedef long long ll; typedef unsigned long long ull;
typedef pair <int, int> P; typedef pair <int, P> PP;
typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<string> vs;
typedef vector<ll> vl; typedef vector<P > vP; typedef vector<char> vc;
typedef long double ld;

const static int INF = 0x3f3f3f3f;
const static ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const static double EPS = 1e-9;
const static ll MOD = 1000000007LL;

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

static int N, M, Q;
static vi a, b, c, d;
static ll ans;

void dfs(vi A)
{
    if (A.size() == N+1) {
        // priArr(A, A.size());

        ll tmp_max = 0;
        rep(i, Q) {
            if (A[b[i]] - A[a[i]] == c[i]) {
                tmp_max += d[i];
            }
        }
        ans = max(tmp_max, ans);

        return;
    }

    A.pb(A.back());
    while (A.back() <= M) {
        dfs(A);
        A.back()++;
    }
}

int main(int argc, char *argv[])
{
    cin >> N >> M >> Q;
    a = b = c = d = vi(Q);
    rep(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    dfs(vi(1, 1));

    cout << ans << endl;

    return 0;
}


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

int main() {
    string s, t, u;
    cin >> s >> t >> u;
    cout << char(toupper(s[0])) << char(toupper(t[0])) << char(toupper(u[0])) << endl;
}


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

int main()
{
  int N,K;
  cin >> N >> K;
  int count=0;
  
  vector<int> result(100);
  for(int i=0; i<result.size(); i++){
  	result.at(i) = N % K;
    N /= K;
    count++;
    if(N < 1){
      break;
    }
  
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(){
  int a,b,c,j,k,l;
  scanf("%d %d %d",&a,&b,&c);
  
  k=abs(a-b)+abs(b-c);
  j=abs(b-a)+abs(a-c);
  l=abs(a-c)+abs(c-b);
  
  if(k>=j&&j<=l)
    printf("%d",j);
  
    else if(k>=l&&l<=j)
    printf("%d",l);
  
    else if(k<=j&&k<=l)
    printf("%d",k);
}

Measured memory_bytes: 128
import java.util.*;
import java.util.stream.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt(), b = in.nextInt();
		if(a + b == 15) {
			System.out.println("+");
		}else if(a * b == 15) {
			System.out.println("*");
		}else {
			System.out.println("x");
		}
	}
}


Measured memory_bytes: 23124
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

long long Q, H, S, D, N;

int main() {
	scanf("%lld%lld%lld%lld%lld", &Q, &H, &S, &D, &N);
	long long t = min({N * 4 * Q, N * 2 * H, N * S});
	printf("%lld\n", min(N / 2 * D + N % 2 * t / N, t));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> l(n + 2);
	rep(i,n) cin >> l.at(i + 1);
	l.at(0) = 0;
	l.at(n + 1) = 20000;
	sort(l.begin(),l.end());
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = n; j > i + 1; j--){
			int k = lower_bound(l.begin(),l.end(),l.at(i) + l.at(j)) - l.begin() - 1;
			k = min(k, j - 1);
			int t = upper_bound(l.begin(),l.end(),l.at(j) - l.at(i)) - l.begin();
			if(l.at(t) != l.at(j) - l.at(i)) t--;
			t = max(t, i);
			ans += max(0, k - t);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256